xref: /netbsd-src/sbin/mount_efs/mount_efs.c (revision 8b0f9554ff8762542c4defc4f70e1eb76fb508fa)
1 /*	$NetBSD: mount_efs.c,v 1.3 2007/07/16 17:06:52 pooka Exp $	*/
2 
3 /*
4  * Copyright (c) 2006 Stephen M. Rumble <rumble@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 static const struct mntopt mopts[] = {
35 	MOPT_STDOPTS,
36 	MOPT_GETARGS,
37 	MOPT_FORCE,
38 	MOPT_NULL
39 };
40 
41 static void	usage(void);
42 int		mount_efs(int, char **);
43 
44 static void
45 usage()
46 {
47 
48 	fprintf(stderr, "usage: %s [-o options] special node\n", getprogname());
49 	exit(1);
50 }
51 
52 int
53 mount_efs(int argc, char **argv)
54 {
55 	int ch, mntflags;
56 	extern int optind;
57 	extern char *optarg;
58 	struct efs_args args;
59 	char special[MAXPATHLEN], node[MAXPATHLEN];
60 	mntoptparse_t mp;
61 
62 	setprogname(argv[0]);
63 	memset(&args, 0, sizeof(args));
64 	mntflags = 0;
65 
66 	while ((ch = getopt(argc, argv, "o:")) != -1) {
67 		switch (ch) {
68 		case 'o':
69 			mp = getmntopts(optarg, mopts, &mntflags, NULL);
70 			if (mp == NULL)
71 				err(1, "getmntopts");
72 			freemntopts(mp);
73 			break;
74 
75 		default:
76 			usage();
77 		}
78 	}
79 	argc -= optind;
80 	argv += optind;
81 
82 	if (argc != 2)
83 		usage();
84 
85 	if (realpath(argv[0], special) == NULL)
86 		err(EXIT_FAILURE, "realpath %s", argv[0]);
87 
88 	if (realpath(argv[1], node) == NULL)
89 		err(EXIT_FAILURE, "realpath %s", argv[1]);
90 
91 	args.fspec = special;
92 	args.version = EFS_MNT_VERSION;
93 	if (mount(MOUNT_EFS, node, mntflags, &args, sizeof args) == -1)
94 		err(EXIT_FAILURE, "%s on %s", special, node);
95 
96 	return (0);
97 }
98 
99 #ifndef MOUNT_NOMAIN
100 int
101 main(int argc, char **argv)
102 {
103 
104 	return (mount_efs(argc, argv));
105 }
106 #endif
107