mount_efs.c revision 1.6 1 /* $NetBSD: mount_efs.c,v 1.6 2024/11/03 10:43:27 rillig Exp $ */
2
3 /*
4 * Copyright (c) 2006 Stephen M. Rumble <rumble (at) ephemeral.org>
5 *
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.
9 *
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.
17 */
18
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>
24
25 #include <err.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28
29 #include <string.h>
30 #include <unistd.h>
31
32 #include <mntopts.h>
33
34 #include "mountprog.h"
35 #include "mount_efs.h"
36
37 static const struct mntopt mopts[] = {
38 MOPT_STDOPTS,
39 MOPT_GETARGS,
40 MOPT_FORCE,
41 MOPT_NULL
42 };
43
44 __dead static void usage(void);
45
46 static void
47 usage(void)
48 {
49
50 fprintf(stderr, "usage: %s [-o options] special node\n", getprogname());
51 exit(1);
52 }
53
54 void
55 mount_efs_parseargs(int argc, char **argv,
56 struct efs_args *args, int *mntflags,
57 char *canon_dev, char *canon_dir)
58 {
59 int ch;
60 mntoptparse_t mp;
61
62 memset(args, 0, sizeof(*args));
63 *mntflags = 0;
64
65 while ((ch = getopt(argc, argv, "o:")) != -1) {
66 switch (ch) {
67 case 'o':
68 mp = getmntopts(optarg, mopts, mntflags, NULL);
69 if (mp == NULL)
70 err(1, "getmntopts");
71 freemntopts(mp);
72 break;
73
74 default:
75 usage();
76 }
77 }
78 argc -= optind;
79 argv += optind;
80
81 if (argc != 2)
82 usage();
83
84 pathadj(argv[0], canon_dev);
85 pathadj(argv[1], canon_dir);
86
87 args->fspec = canon_dev;
88 args->version = EFS_MNT_VERSION;
89 }
90
91 int
92 mount_efs(int argc, char **argv)
93 {
94 char special[MAXPATHLEN], node[MAXPATHLEN];
95 struct efs_args args;
96 int mntflags;
97
98 mount_efs_parseargs(argc, argv, &args, &mntflags, special, node);
99
100 if (mount(MOUNT_EFS, node, mntflags, &args, sizeof args) == -1)
101 err(EXIT_FAILURE, "%s on %s", special, node);
102
103 return (0);
104 }
105
106 #ifndef MOUNT_NOMAIN
107 int
108 main(int argc, char **argv)
109 {
110
111 setprogname(argv[0]);
112 return (mount_efs(argc, argv));
113 }
114 #endif
115