1 /* $NetBSD: mount_filecore.c,v 1.4 2000/10/30 20:56:59 jdolecek Exp $ */
2 
3 /*
4  * Copyright (c) 1998 Andrew McMurry
5  * Copyright (c) 1992, 1993, 1994 The Regents of the University of California.
6  * All rights reserved.
7  *
8  * This code is contains code contributed to the NetBSD project by
9  * Christopher G. Demetriou
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  * 3. All advertising materials mentioning features or use of this software
20  *    must display the following acknowledgement:
21  *	This product includes software developed by the University of
22  *	California, Berkeley and its contributors.
23  * 4. Neither the name of the University nor the names of its contributors
24  *    may be used to endorse or promote products derived from this software
25  *    without specific prior written permission.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37  * SUCH DAMAGE.
38  *
39  *      mount_filecore.c	1.1	1998/6/26
40  */
41 
42 #include <sys/cdefs.h>
43 #ifndef lint
44 __COPYRIGHT("@(#) Copyright (c) 1992, 1993, 1994\
45         The Regents of the University of California.\n\
46 	Copyright (c) 1998 Andrew McMurry\n\
47 	All rights reserved.\n");
48 #endif /* not lint */
49 
50 #include <sys/param.h>
51 #include <sys/mount.h>
52 
53 #include <ctype.h>
54 #include <err.h>
55 #include <grp.h>
56 #include <pwd.h>
57 #include <stdlib.h>
58 #include <stdio.h>
59 #include <string.h>
60 #include <unistd.h>
61 
62 #include <filecorefs/filecore_mount.h>
63 
64 #include "mntopts.h"
65 #include <fattr.h>
66 
67 static const struct mntopt mopts[] = {
68 	MOPT_STDOPTS,
69 	MOPT_UPDATE,
70 	{ NULL }
71 };
72 
73 int	main __P((int, char *[]));
74 int	mount_filecore __P((int argc, char **argv));
75 static void	usage __P((void));
76 
77 #ifndef MOUNT_NOMAIN
78 int
79 main(argc, argv)
80 	int argc;
81 	char **argv;
82 {
83 	return mount_filecore(argc, argv);
84 }
85 #endif
86 
87 int
88 mount_filecore(argc, argv)
89 	int argc;
90 	char **argv;
91 {
92 	struct filecore_args args;
93 	int ch, mntflags, opts, useuid;
94 	char *dev, *dir;
95 
96 	mntflags = opts = 0;
97 	useuid = 1;
98 	args.uid = 0;
99 	args.gid = 0;
100 
101 	while ((ch = getopt(argc, argv, "anRfu:g:o:")) != -1)
102 		switch (ch) {
103 		case 'a':
104 			args.flags |= FILECOREMNT_ALLACCESS;
105 			break;
106 		case 'n':
107 			args.flags |= FILECOREMNT_OWNACCESS;
108 			break;
109 		case 'R':
110 			args.flags |= FILECOREMNT_OWNREAD;
111 			break;
112 		case 'f':
113 			args.flags |= FILECOREMNT_FILETYPE;
114 			break;
115                 case 'u':
116                         args.uid = a_uid(optarg);
117 			useuid = 0;
118                         break;
119                 case 'g':
120                         args.gid = a_gid(optarg);
121 			useuid = 0;
122                         break;
123 		case 'o':
124 			getmntopts(optarg, mopts, &mntflags, 0);
125 			break;
126 		case '?':
127 		default:
128 			usage();
129 		}
130 	argc -= optind;
131 	argv += optind;
132 
133 	if (argc != 2)
134 		usage();
135 
136 	dev = argv[0];
137 	dir = argv[1];
138 
139 #define DEFAULT_ROOTUID	-2
140 	/*
141 	 * FILECORE filesystems are not writeable.
142 	 */
143 	mntflags |= MNT_RDONLY;
144 	if (useuid) args.flags |= FILECOREMNT_USEUID;
145 	args.export.ex_flags = MNT_EXRDONLY;
146 	args.fspec = dev;
147 	args.export.ex_root = DEFAULT_ROOTUID;
148 	args.flags = opts;
149 
150 	if (mount(MOUNT_FILECORE, dir, mntflags, &args) < 0)
151 		err(1, "%s on %s", dev, dir);
152 	exit(0);
153 }
154 
155 static void
156 usage()
157 {
158 	(void)fprintf(stderr,
159 		"usage: mount_filecore [-o options] special node\n");
160 	exit(1);
161 }
162