No empty .Rs/.Re
[netbsd-mini2440.git] / sbin / mount_efs / mount_efs.c
blob96cd65f1d557a7607173506ab4ab43c937a06b8b
1 /* $NetBSD: mount_efs.c,v 1.3 2007/07/16 17:06:52 pooka Exp $ */
3 /*
4 * Copyright (c) 2006 Stephen M. Rumble <rumble@ephemeral.org>
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 #include <sys/param.h>
20 #include <sys/mount.h>
21 #include <fs/efs/efs.h>
22 #include <fs/efs/efs_sb.h>
23 #include <fs/efs/efs_mount.h>
25 #include <err.h>
26 #include <stdio.h>
27 #include <stdlib.h>
29 #include <string.h>
30 #include <unistd.h>
32 #include <mntopts.h>
34 #include "mountprog.h"
35 #include "mount_efs.h"
37 static const struct mntopt mopts[] = {
38 MOPT_STDOPTS,
39 MOPT_GETARGS,
40 MOPT_FORCE,
41 MOPT_NULL
44 static void usage(void);
46 static void
47 usage()
50 fprintf(stderr, "usage: %s [-o options] special node\n", getprogname());
51 exit(1);
54 void
55 mount_efs_parseargs(int argc, char **argv,
56 struct efs_args *args, int *mntflags,
57 char *canon_dev, char *canon_dir)
59 int ch;
60 extern int optind;
61 extern char *optarg;
62 mntoptparse_t mp;
64 memset(args, 0, sizeof(*args));
65 *mntflags = 0;
67 while ((ch = getopt(argc, argv, "o:")) != -1) {
68 switch (ch) {
69 case 'o':
70 mp = getmntopts(optarg, mopts, mntflags, NULL);
71 if (mp == NULL)
72 err(1, "getmntopts");
73 freemntopts(mp);
74 break;
76 default:
77 usage();
80 argc -= optind;
81 argv += optind;
83 if (argc != 2)
84 usage();
86 pathadj(argv[0], canon_dev);
87 pathadj(argv[1], canon_dir);
89 args->fspec = canon_dev;
90 args->version = EFS_MNT_VERSION;
93 int
94 mount_efs(int argc, char **argv)
96 char special[MAXPATHLEN], node[MAXPATHLEN];
97 struct efs_args args;
98 int mntflags;
100 mount_efs_parseargs(argc, argv, &args, &mntflags, special, node);
102 if (mount(MOUNT_EFS, node, mntflags, &args, sizeof args) == -1)
103 err(EXIT_FAILURE, "%s on %s", special, node);
105 return (0);
108 #ifndef MOUNT_NOMAIN
110 main(int argc, char **argv)
113 setprogname(argv[0]);
114 return (mount_efs(argc, argv));
116 #endif