mount.c revision 1.13.2.2 1 1.13.2.2 mycroft /*
2 1.13.2.2 mycroft * Copyright (c) 1980, 1989, 1993, 1994
3 1.13.2.2 mycroft * The Regents of the University of California. All rights reserved.
4 1.13.2.2 mycroft *
5 1.13.2.2 mycroft * Redistribution and use in source and binary forms, with or without
6 1.13.2.2 mycroft * modification, are permitted provided that the following conditions
7 1.13.2.2 mycroft * are met:
8 1.13.2.2 mycroft * 1. Redistributions of source code must retain the above copyright
9 1.13.2.2 mycroft * notice, this list of conditions and the following disclaimer.
10 1.13.2.2 mycroft * 2. Redistributions in binary form must reproduce the above copyright
11 1.13.2.2 mycroft * notice, this list of conditions and the following disclaimer in the
12 1.13.2.2 mycroft * documentation and/or other materials provided with the distribution.
13 1.13.2.2 mycroft * 3. All advertising materials mentioning features or use of this software
14 1.13.2.2 mycroft * must display the following acknowledgement:
15 1.13.2.2 mycroft * This product includes software developed by the University of
16 1.13.2.2 mycroft * California, Berkeley and its contributors.
17 1.13.2.2 mycroft * 4. Neither the name of the University nor the names of its contributors
18 1.13.2.2 mycroft * may be used to endorse or promote products derived from this software
19 1.13.2.2 mycroft * without specific prior written permission.
20 1.13.2.2 mycroft *
21 1.13.2.2 mycroft * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 1.13.2.2 mycroft * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 1.13.2.2 mycroft * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 1.13.2.2 mycroft * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 1.13.2.2 mycroft * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 1.13.2.2 mycroft * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 1.13.2.2 mycroft * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 1.13.2.2 mycroft * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 1.13.2.2 mycroft * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 1.13.2.2 mycroft * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 1.13.2.2 mycroft * SUCH DAMAGE.
32 1.13.2.2 mycroft */
33 1.13.2.2 mycroft
34 1.13.2.2 mycroft #ifndef lint
35 1.13.2.2 mycroft static char copyright[] =
36 1.13.2.2 mycroft "@(#) Copyright (c) 1980, 1989, 1993, 1994\n\
37 1.13.2.2 mycroft The Regents of the University of California. All rights reserved.\n";
38 1.13.2.2 mycroft #endif /* not lint */
39 1.13.2.2 mycroft
40 1.13.2.2 mycroft #ifndef lint
41 1.13.2.2 mycroft /*static char sccsid[] = "from: @(#)mount.c 8.19 (Berkeley) 4/19/94";*/
42 1.13.2.2 mycroft static char *rcsid = "$Id: mount.c,v 1.13.2.2 1994/08/29 02:38:01 mycroft Exp $";
43 1.13.2.2 mycroft #endif /* not lint */
44 1.13.2.2 mycroft
45 1.13.2.2 mycroft #include <sys/param.h>
46 1.13.2.2 mycroft #include <sys/mount.h>
47 1.13.2.2 mycroft #include <sys/wait.h>
48 1.13.2.2 mycroft
49 1.13.2.2 mycroft #include <err.h>
50 1.13.2.2 mycroft #include <errno.h>
51 1.13.2.2 mycroft #include <fstab.h>
52 1.13.2.2 mycroft #include <signal.h>
53 1.13.2.2 mycroft #include <stdio.h>
54 1.13.2.2 mycroft #include <stdlib.h>
55 1.13.2.2 mycroft #include <string.h>
56 1.13.2.2 mycroft #include <unistd.h>
57 1.13.2.2 mycroft
58 1.13.2.2 mycroft #include "pathnames.h"
59 1.13.2.2 mycroft
60 1.13.2.2 mycroft int debug, verbose, skipvfs;
61 1.13.2.2 mycroft
62 1.13.2.2 mycroft int badvfsname __P((const char *, const char **));
63 1.13.2.2 mycroft char *catopt __P((char *, const char *));
64 1.13.2.2 mycroft struct statfs
65 1.13.2.2 mycroft *getmntpt __P((const char *));
66 1.13.2.2 mycroft int hasopt __P((const char *, const char *));
67 1.13.2.2 mycroft const char
68 1.13.2.2 mycroft **makevfslist __P((char *));
69 1.13.2.2 mycroft void mangle __P((char *, int *, const char **));
70 1.13.2.2 mycroft int mountfs __P((const char *, const char *, const char *,
71 1.13.2.2 mycroft int, const char *, const char *));
72 1.13.2.2 mycroft void prmount __P((struct statfs *));
73 1.13.2.2 mycroft void usage __P((void));
74 1.13.2.2 mycroft
75 1.13.2.2 mycroft /* From mount_ufs.c. */
76 1.13.2.2 mycroft int mount_ufs __P((int, char * const *));
77 1.13.2.2 mycroft
78 1.13.2.2 mycroft /* Map from mount otions to printable formats. */
79 1.13.2.2 mycroft static struct opt {
80 1.13.2.2 mycroft int o_opt;
81 1.13.2.2 mycroft const char *o_name;
82 1.13.2.2 mycroft } optnames[] = {
83 1.13.2.2 mycroft { MNT_ASYNC, "asynchronous" },
84 1.13.2.2 mycroft { MNT_EXPORTED, "NFS exported" },
85 1.13.2.2 mycroft { MNT_LOCAL, "local" },
86 1.13.2.2 mycroft { MNT_NODEV, "nodev" },
87 1.13.2.2 mycroft { MNT_NOEXEC, "noexec" },
88 1.13.2.2 mycroft { MNT_NOSUID, "nosuid" },
89 1.13.2.2 mycroft { MNT_QUOTA, "with quotas" },
90 1.13.2.2 mycroft { MNT_RDONLY, "read-only" },
91 1.13.2.2 mycroft { MNT_SYNCHRONOUS, "synchronous" },
92 1.13.2.2 mycroft { MNT_UNION, "union" },
93 1.13.2.2 mycroft { MNT_USER, "user mount" },
94 1.13.2.2 mycroft { NULL }
95 1.13.2.2 mycroft };
96 1.13.2.2 mycroft
97 1.13.2.2 mycroft int
98 1.13.2.2 mycroft main(argc, argv)
99 1.13.2.2 mycroft int argc;
100 1.13.2.2 mycroft char * const argv[];
101 1.13.2.2 mycroft {
102 1.13.2.2 mycroft const char *mntonname, **vfslist, *vfstype;
103 1.13.2.2 mycroft struct fstab *fs;
104 1.13.2.2 mycroft struct statfs *mntbuf;
105 1.13.2.2 mycroft FILE *mountdfp;
106 1.13.2.2 mycroft pid_t pid;
107 1.13.2.2 mycroft int all, ch, i, init_flags, mntsize, rval;
108 1.13.2.2 mycroft char *options;
109 1.13.2.2 mycroft
110 1.13.2.2 mycroft all = init_flags = 0;
111 1.13.2.2 mycroft options = NULL;
112 1.13.2.2 mycroft vfslist = NULL;
113 1.13.2.2 mycroft vfstype = "ufs";
114 1.13.2.2 mycroft while ((ch = getopt(argc, argv, "adfo:rwt:uv")) != EOF)
115 1.13.2.2 mycroft switch (ch) {
116 1.13.2.2 mycroft case 'a':
117 1.13.2.2 mycroft all = 1;
118 1.13.2.2 mycroft break;
119 1.13.2.2 mycroft case 'd':
120 1.13.2.2 mycroft debug = 1;
121 1.13.2.2 mycroft break;
122 1.13.2.2 mycroft case 'f':
123 1.13.2.2 mycroft init_flags |= MNT_FORCE;
124 1.13.2.2 mycroft break;
125 1.13.2.2 mycroft case 'o':
126 1.13.2.2 mycroft if (*optarg)
127 1.13.2.2 mycroft options = catopt(options, optarg);
128 1.13.2.2 mycroft break;
129 1.13.2.2 mycroft case 'r':
130 1.13.2.2 mycroft init_flags |= MNT_RDONLY;
131 1.13.2.2 mycroft break;
132 1.13.2.2 mycroft case 't':
133 1.13.2.2 mycroft if (vfslist != NULL)
134 1.13.2.2 mycroft errx(1, "only one -t option may be specified.");
135 1.13.2.2 mycroft vfslist = makevfslist(optarg);
136 1.13.2.2 mycroft vfstype = optarg;
137 1.13.2.2 mycroft break;
138 1.13.2.2 mycroft case 'u':
139 1.13.2.2 mycroft init_flags |= MNT_UPDATE;
140 1.13.2.2 mycroft break;
141 1.13.2.2 mycroft case 'v':
142 1.13.2.2 mycroft verbose = 1;
143 1.13.2.2 mycroft break;
144 1.13.2.2 mycroft case 'w':
145 1.13.2.2 mycroft init_flags &= ~MNT_RDONLY;
146 1.13.2.2 mycroft break;
147 1.13.2.2 mycroft case '?':
148 1.13.2.2 mycroft default:
149 1.13.2.2 mycroft usage();
150 1.13.2.2 mycroft /* NOTREACHED */
151 1.13.2.2 mycroft }
152 1.13.2.2 mycroft argc -= optind;
153 1.13.2.2 mycroft argv += optind;
154 1.13.2.2 mycroft
155 1.13.2.2 mycroft #define BADTYPE(type) \
156 1.13.2.2 mycroft (strcmp(type, FSTAB_RO) && \
157 1.13.2.2 mycroft strcmp(type, FSTAB_RW) && strcmp(type, FSTAB_RQ))
158 1.13.2.2 mycroft
159 1.13.2.2 mycroft rval = 0;
160 1.13.2.2 mycroft switch (argc) {
161 1.13.2.2 mycroft case 0:
162 1.13.2.2 mycroft if (all)
163 1.13.2.2 mycroft while ((fs = getfsent()) != NULL) {
164 1.13.2.2 mycroft if (BADTYPE(fs->fs_type))
165 1.13.2.2 mycroft continue;
166 1.13.2.2 mycroft if (badvfsname(fs->fs_vfstype, vfslist))
167 1.13.2.2 mycroft continue;
168 1.13.2.2 mycroft if (hasopt(fs->fs_mntops, "noauto"))
169 1.13.2.2 mycroft continue;
170 1.13.2.2 mycroft if (mountfs(fs->fs_vfstype, fs->fs_spec,
171 1.13.2.2 mycroft fs->fs_file, init_flags, options,
172 1.13.2.2 mycroft fs->fs_mntops))
173 1.13.2.2 mycroft rval = 1;
174 1.13.2.2 mycroft }
175 1.13.2.2 mycroft else {
176 1.13.2.2 mycroft if ((mntsize = getmntinfo(&mntbuf, MNT_NOWAIT)) == 0)
177 1.13.2.2 mycroft err(1, "getmntinfo");
178 1.13.2.2 mycroft for (i = 0; i < mntsize; i++) {
179 1.13.2.2 mycroft if (badvfsname(mntbuf[i].f_fstypename, vfslist))
180 1.13.2.2 mycroft continue;
181 1.13.2.2 mycroft prmount(&mntbuf[i]);
182 1.13.2.2 mycroft }
183 1.13.2.2 mycroft }
184 1.13.2.2 mycroft exit(rval);
185 1.13.2.2 mycroft case 1:
186 1.13.2.2 mycroft if (vfslist != NULL)
187 1.13.2.2 mycroft usage();
188 1.13.2.2 mycroft
189 1.13.2.2 mycroft if (init_flags & MNT_UPDATE) {
190 1.13.2.2 mycroft if ((mntbuf = getmntpt(*argv)) == NULL)
191 1.13.2.2 mycroft errx(1,
192 1.13.2.2 mycroft "unknown special file or file system %s.",
193 1.13.2.2 mycroft *argv);
194 1.13.2.2 mycroft if ((fs = getfsfile(mntbuf->f_mntonname)) == NULL)
195 1.13.2.2 mycroft errx(1, "can't find fstab entry for %s.",
196 1.13.2.2 mycroft *argv);
197 1.13.2.2 mycroft /* If it's an update, ignore the fstab file options. */
198 1.13.2.2 mycroft fs->fs_mntops = NULL;
199 1.13.2.2 mycroft mntonname = mntbuf->f_mntonname;
200 1.13.2.2 mycroft } else {
201 1.13.2.2 mycroft if ((fs = getfsfile(*argv)) == NULL &&
202 1.13.2.2 mycroft (fs = getfsspec(*argv)) == NULL)
203 1.13.2.2 mycroft errx(1,
204 1.13.2.2 mycroft "%s: unknown special file or file system.",
205 1.13.2.2 mycroft *argv);
206 1.13.2.2 mycroft if (BADTYPE(fs->fs_type))
207 1.13.2.2 mycroft errx(1, "%s has unknown file system type.",
208 1.13.2.2 mycroft *argv);
209 1.13.2.2 mycroft mntonname = fs->fs_file;
210 1.13.2.2 mycroft }
211 1.13.2.2 mycroft rval = mountfs(fs->fs_vfstype, fs->fs_spec,
212 1.13.2.2 mycroft mntonname, init_flags, options, fs->fs_mntops);
213 1.13.2.2 mycroft break;
214 1.13.2.2 mycroft case 2:
215 1.13.2.2 mycroft /*
216 1.13.2.2 mycroft * If -t flag has not been specified, and spec contains either
217 1.13.2.2 mycroft * a ':' or a '@' then assume that an NFS filesystem is being
218 1.13.2.2 mycroft * specified ala Sun.
219 1.13.2.2 mycroft */
220 1.13.2.2 mycroft if (vfslist == NULL && strpbrk(argv[0], ":@") != NULL)
221 1.13.2.2 mycroft vfstype = "nfs";
222 1.13.2.2 mycroft rval = mountfs(vfstype,
223 1.13.2.2 mycroft argv[0], argv[1], init_flags, options, NULL);
224 1.13.2.2 mycroft break;
225 1.13.2.2 mycroft default:
226 1.13.2.2 mycroft usage();
227 1.13.2.2 mycroft /* NOTREACHED */
228 1.13.2.2 mycroft }
229 1.13.2.2 mycroft
230 1.13.2.2 mycroft /*
231 1.13.2.2 mycroft * If the mount was successfully, and done by root, tell mountd the
232 1.13.2.2 mycroft * good news. Pid checks are probably unnecessary, but don't hurt.
233 1.13.2.2 mycroft */
234 1.13.2.2 mycroft if (rval == 0 && getuid() == 0 &&
235 1.13.2.2 mycroft (mountdfp = fopen(_PATH_MOUNTDPID, "r")) != NULL) {
236 1.13.2.2 mycroft if (fscanf(mountdfp, "%ld", &pid) == 1 &&
237 1.13.2.2 mycroft pid > 0 && kill(pid, SIGHUP) == -1 && errno != ESRCH)
238 1.13.2.2 mycroft err(1, "signal mountd");
239 1.13.2.2 mycroft (void)fclose(mountdfp);
240 1.13.2.2 mycroft }
241 1.13.2.2 mycroft
242 1.13.2.2 mycroft exit(rval);
243 1.13.2.2 mycroft }
244 1.13.2.2 mycroft
245 1.13.2.2 mycroft int
246 1.13.2.2 mycroft hasopt(mntopts, option)
247 1.13.2.2 mycroft const char *mntopts, *option;
248 1.13.2.2 mycroft {
249 1.13.2.2 mycroft int negative, found;
250 1.13.2.2 mycroft char *opt, *optbuf;
251 1.13.2.2 mycroft
252 1.13.2.2 mycroft if (option[0] == 'n' && option[1] == 'o') {
253 1.13.2.2 mycroft negative = 1;
254 1.13.2.2 mycroft option += 2;
255 1.13.2.2 mycroft } else
256 1.13.2.2 mycroft negative = 0;
257 1.13.2.2 mycroft optbuf = strdup(mntopts);
258 1.13.2.2 mycroft found = 0;
259 1.13.2.2 mycroft for (opt = optbuf; (opt = strtok(opt, ",")) != NULL; opt = NULL) {
260 1.13.2.2 mycroft if (opt[0] == 'n' && opt[1] == 'o') {
261 1.13.2.2 mycroft if (!strcasecmp(opt + 2, option))
262 1.13.2.2 mycroft found = negative;
263 1.13.2.2 mycroft } else if (!strcasecmp(opt, option))
264 1.13.2.2 mycroft found = !negative;
265 1.13.2.2 mycroft }
266 1.13.2.2 mycroft free(optbuf);
267 1.13.2.2 mycroft return (found);
268 1.13.2.2 mycroft }
269 1.13.2.2 mycroft
270 1.13.2.2 mycroft int
271 1.13.2.2 mycroft mountfs(vfstype, spec, name, flags, options, mntopts)
272 1.13.2.2 mycroft const char *vfstype, *spec, *name, *options, *mntopts;
273 1.13.2.2 mycroft int flags;
274 1.13.2.2 mycroft {
275 1.13.2.2 mycroft /* List of directories containing mount_xxx subcommands. */
276 1.13.2.2 mycroft static const char *edirs[] = {
277 1.13.2.2 mycroft _PATH_SBIN,
278 1.13.2.2 mycroft _PATH_USRSBIN,
279 1.13.2.2 mycroft NULL
280 1.13.2.2 mycroft };
281 1.13.2.2 mycroft const char *argv[100], **edir;
282 1.13.2.2 mycroft struct statfs sf;
283 1.13.2.2 mycroft pid_t pid;
284 1.13.2.2 mycroft int argc, i, status;
285 1.13.2.2 mycroft char *optbuf, execname[MAXPATHLEN + 1], mntpath[MAXPATHLEN];
286 1.13.2.2 mycroft
287 1.13.2.2 mycroft if (realpath(name, mntpath) == NULL) {
288 1.13.2.2 mycroft warn("realpath %s", mntpath);
289 1.13.2.2 mycroft return (1);
290 1.13.2.2 mycroft }
291 1.13.2.2 mycroft
292 1.13.2.2 mycroft name = mntpath;
293 1.13.2.2 mycroft
294 1.13.2.2 mycroft if (mntopts == NULL)
295 1.13.2.2 mycroft mntopts = "";
296 1.13.2.2 mycroft if (options == NULL) {
297 1.13.2.2 mycroft if (*mntopts == '\0')
298 1.13.2.2 mycroft options = "rw";
299 1.13.2.2 mycroft else {
300 1.13.2.2 mycroft options = mntopts;
301 1.13.2.2 mycroft mntopts = "";
302 1.13.2.2 mycroft }
303 1.13.2.2 mycroft }
304 1.13.2.2 mycroft optbuf = catopt(strdup(mntopts), options);
305 1.13.2.2 mycroft
306 1.13.2.2 mycroft if (strcmp(name, "/") == 0)
307 1.13.2.2 mycroft flags |= MNT_UPDATE;
308 1.13.2.2 mycroft if (flags & MNT_FORCE)
309 1.13.2.2 mycroft optbuf = catopt(optbuf, "force");
310 1.13.2.2 mycroft if (flags & MNT_RDONLY)
311 1.13.2.2 mycroft optbuf = catopt(optbuf, "ro");
312 1.13.2.2 mycroft /*
313 1.13.2.2 mycroft * XXX
314 1.13.2.2 mycroft * The mount_mfs (newfs) command uses -o to select the
315 1.13.2.2 mycroft * optimisation mode. We don't pass the default "-o rw"
316 1.13.2.2 mycroft * for that reason.
317 1.13.2.2 mycroft */
318 1.13.2.2 mycroft if (flags & MNT_UPDATE)
319 1.13.2.2 mycroft optbuf = catopt(optbuf, "update");
320 1.13.2.2 mycroft
321 1.13.2.2 mycroft argc = 0;
322 1.13.2.2 mycroft argv[argc++] = vfstype;
323 1.13.2.2 mycroft mangle(optbuf, &argc, argv);
324 1.13.2.2 mycroft argv[argc++] = spec;
325 1.13.2.2 mycroft argv[argc++] = name;
326 1.13.2.2 mycroft argv[argc] = NULL;
327 1.13.2.2 mycroft
328 1.13.2.2 mycroft if (debug) {
329 1.13.2.2 mycroft (void)printf("exec: mount_%s", vfstype);
330 1.13.2.2 mycroft for (i = 1; i < argc; i++)
331 1.13.2.2 mycroft (void)printf(" %s", argv[i]);
332 1.13.2.2 mycroft (void)printf("\n");
333 1.13.2.2 mycroft return (0);
334 1.13.2.2 mycroft }
335 1.13.2.2 mycroft
336 1.13.2.2 mycroft switch (pid = vfork()) {
337 1.13.2.2 mycroft case -1: /* Error. */
338 1.13.2.2 mycroft warn("vfork");
339 1.13.2.2 mycroft free(optbuf);
340 1.13.2.2 mycroft return (1);
341 1.13.2.2 mycroft case 0: /* Child. */
342 1.13.2.2 mycroft if (strcmp(vfstype, "ufs") == 0)
343 1.13.2.2 mycroft exit(mount_ufs(argc, (char * const *) argv));
344 1.13.2.2 mycroft
345 1.13.2.2 mycroft /* Go find an executable. */
346 1.13.2.2 mycroft edir = edirs;
347 1.13.2.2 mycroft do {
348 1.13.2.2 mycroft (void)snprintf(execname,
349 1.13.2.2 mycroft sizeof(execname), "%s/mount_%s", *edir, vfstype);
350 1.13.2.2 mycroft execv(execname, (char * const *)argv);
351 1.13.2.2 mycroft if (errno != ENOENT)
352 1.13.2.2 mycroft warn("exec %s for %s", execname, name);
353 1.13.2.2 mycroft } while (*++edir != NULL);
354 1.13.2.2 mycroft
355 1.13.2.2 mycroft if (errno == ENOENT)
356 1.13.2.2 mycroft warn("exec %s for %s", execname, name);
357 1.13.2.2 mycroft exit(1);
358 1.13.2.2 mycroft /* NOTREACHED */
359 1.13.2.2 mycroft default: /* Parent. */
360 1.13.2.2 mycroft free(optbuf);
361 1.13.2.2 mycroft
362 1.13.2.2 mycroft if (waitpid(pid, &status, 0) < 0) {
363 1.13.2.2 mycroft warn("waitpid");
364 1.13.2.2 mycroft return (1);
365 1.13.2.2 mycroft }
366 1.13.2.2 mycroft
367 1.13.2.2 mycroft if (WIFEXITED(status)) {
368 1.13.2.2 mycroft if (WEXITSTATUS(status) != 0)
369 1.13.2.2 mycroft return (WEXITSTATUS(status));
370 1.13.2.2 mycroft } else if (WIFSIGNALED(status)) {
371 1.13.2.2 mycroft warnx("%s: %s", name, sys_siglist[WTERMSIG(status)]);
372 1.13.2.2 mycroft return (1);
373 1.13.2.2 mycroft }
374 1.13.2.2 mycroft
375 1.13.2.2 mycroft if (verbose) {
376 1.13.2.2 mycroft if (statfs(name, &sf) < 0) {
377 1.13.2.2 mycroft warn("statfs %s", name);
378 1.13.2.2 mycroft return (1);
379 1.13.2.2 mycroft }
380 1.13.2.2 mycroft prmount(&sf);
381 1.13.2.2 mycroft }
382 1.13.2.2 mycroft break;
383 1.13.2.2 mycroft }
384 1.13.2.2 mycroft
385 1.13.2.2 mycroft return (0);
386 1.13.2.2 mycroft }
387 1.13.2.2 mycroft
388 1.13.2.2 mycroft void
389 1.13.2.2 mycroft prmount(sf)
390 1.13.2.2 mycroft struct statfs *sf;
391 1.13.2.2 mycroft {
392 1.13.2.2 mycroft int flags;
393 1.13.2.2 mycroft struct opt *o;
394 1.13.2.2 mycroft int f;
395 1.13.2.2 mycroft
396 1.13.2.2 mycroft (void)printf("%s on %s type %s", sf->f_mntfromname, sf->f_mntonname,
397 1.13.2.2 mycroft sf->f_fstypename);
398 1.13.2.2 mycroft
399 1.13.2.2 mycroft flags = sf->f_flags & MNT_VISFLAGMASK;
400 1.13.2.2 mycroft for (f = 0, o = optnames; flags && o->o_opt; o++)
401 1.13.2.2 mycroft if (flags & o->o_opt) {
402 1.13.2.2 mycroft (void)printf("%s%s", !f++ ? " (" : ", ", o->o_name);
403 1.13.2.2 mycroft flags &= ~o->o_opt;
404 1.13.2.2 mycroft }
405 1.13.2.2 mycroft (void)printf(f ? ")\n" : "\n");
406 1.13.2.2 mycroft }
407 1.13.2.2 mycroft
408 1.13.2.2 mycroft struct statfs *
409 1.13.2.2 mycroft getmntpt(name)
410 1.13.2.2 mycroft const char *name;
411 1.13.2.2 mycroft {
412 1.13.2.2 mycroft struct statfs *mntbuf;
413 1.13.2.2 mycroft int i, mntsize;
414 1.13.2.2 mycroft
415 1.13.2.2 mycroft mntsize = getmntinfo(&mntbuf, MNT_NOWAIT);
416 1.13.2.2 mycroft for (i = 0; i < mntsize; i++)
417 1.13.2.2 mycroft if (strcmp(mntbuf[i].f_mntfromname, name) == 0 ||
418 1.13.2.2 mycroft strcmp(mntbuf[i].f_mntonname, name) == 0)
419 1.13.2.2 mycroft return (&mntbuf[i]);
420 1.13.2.2 mycroft return (NULL);
421 1.13.2.2 mycroft }
422 1.13.2.2 mycroft
423 1.13.2.2 mycroft int
424 1.13.2.2 mycroft badvfsname(vfsname, vfslist)
425 1.13.2.2 mycroft const char *vfsname;
426 1.13.2.2 mycroft const char **vfslist;
427 1.13.2.2 mycroft {
428 1.13.2.2 mycroft
429 1.13.2.2 mycroft if (vfslist == NULL)
430 1.13.2.2 mycroft return (0);
431 1.13.2.2 mycroft while (*vfslist != NULL) {
432 1.13.2.2 mycroft if (strcmp(vfsname, *vfslist) == 0)
433 1.13.2.2 mycroft return (skipvfs);
434 1.13.2.2 mycroft ++vfslist;
435 1.13.2.2 mycroft }
436 1.13.2.2 mycroft return (!skipvfs);
437 1.13.2.2 mycroft }
438 1.13.2.2 mycroft
439 1.13.2.2 mycroft const char **
440 1.13.2.2 mycroft makevfslist(fslist)
441 1.13.2.2 mycroft char *fslist;
442 1.13.2.2 mycroft {
443 1.13.2.2 mycroft const char **av;
444 1.13.2.2 mycroft int i;
445 1.13.2.2 mycroft char *nextcp;
446 1.13.2.2 mycroft
447 1.13.2.2 mycroft if (fslist == NULL)
448 1.13.2.2 mycroft return (NULL);
449 1.13.2.2 mycroft if (fslist[0] == 'n' && fslist[1] == 'o') {
450 1.13.2.2 mycroft fslist += 2;
451 1.13.2.2 mycroft skipvfs = 1;
452 1.13.2.2 mycroft }
453 1.13.2.2 mycroft for (i = 0, nextcp = fslist; *nextcp; nextcp++)
454 1.13.2.2 mycroft if (*nextcp == ',')
455 1.13.2.2 mycroft i++;
456 1.13.2.2 mycroft if ((av = malloc((size_t)(i + 2) * sizeof(char *))) == NULL) {
457 1.13.2.2 mycroft warn(NULL);
458 1.13.2.2 mycroft return (NULL);
459 1.13.2.2 mycroft }
460 1.13.2.2 mycroft nextcp = fslist;
461 1.13.2.2 mycroft i = 0;
462 1.13.2.2 mycroft av[i++] = nextcp;
463 1.13.2.2 mycroft while ((nextcp = strchr(nextcp, ',')) != NULL) {
464 1.13.2.2 mycroft *nextcp++ = '\0';
465 1.13.2.2 mycroft av[i++] = nextcp;
466 1.13.2.2 mycroft }
467 1.13.2.2 mycroft av[i++] = NULL;
468 1.13.2.2 mycroft return (av);
469 1.13.2.2 mycroft }
470 1.13.2.2 mycroft
471 1.13.2.2 mycroft char *
472 1.13.2.2 mycroft catopt(s0, s1)
473 1.13.2.2 mycroft char *s0;
474 1.13.2.2 mycroft const char *s1;
475 1.13.2.2 mycroft {
476 1.13.2.2 mycroft size_t i;
477 1.13.2.2 mycroft char *cp;
478 1.13.2.2 mycroft
479 1.13.2.2 mycroft if (s0 && *s0) {
480 1.13.2.2 mycroft i = strlen(s0) + strlen(s1) + 1 + 1;
481 1.13.2.2 mycroft if ((cp = malloc(i)) == NULL)
482 1.13.2.2 mycroft err(1, NULL);
483 1.13.2.2 mycroft (void)snprintf(cp, i, "%s,%s", s0, s1);
484 1.13.2.2 mycroft } else
485 1.13.2.2 mycroft cp = strdup(s1);
486 1.13.2.2 mycroft
487 1.13.2.2 mycroft if (s0)
488 1.13.2.2 mycroft free(s0);
489 1.13.2.2 mycroft return (cp);
490 1.13.2.2 mycroft }
491 1.13.2.2 mycroft
492 1.13.2.2 mycroft void
493 1.13.2.2 mycroft mangle(options, argcp, argv)
494 1.13.2.2 mycroft char *options;
495 1.13.2.2 mycroft int *argcp;
496 1.13.2.2 mycroft const char **argv;
497 1.13.2.2 mycroft {
498 1.13.2.2 mycroft char *p, *s;
499 1.13.2.2 mycroft int argc;
500 1.13.2.2 mycroft
501 1.13.2.2 mycroft argc = *argcp;
502 1.13.2.2 mycroft for (s = options; (p = strsep(&s, ",")) != NULL;)
503 1.13.2.2 mycroft if (*p != '\0')
504 1.13.2.2 mycroft if (*p == '-') {
505 1.13.2.2 mycroft argv[argc++] = p;
506 1.13.2.2 mycroft p = strchr(p, '=');
507 1.13.2.2 mycroft if (p) {
508 1.13.2.2 mycroft *p = '\0';
509 1.13.2.2 mycroft argv[argc++] = p+1;
510 1.13.2.2 mycroft }
511 1.13.2.2 mycroft } else if (strcmp(p, "rw") != 0) {
512 1.13.2.2 mycroft argv[argc++] = "-o";
513 1.13.2.2 mycroft argv[argc++] = p;
514 1.13.2.2 mycroft }
515 1.13.2.2 mycroft
516 1.13.2.2 mycroft *argcp = argc;
517 1.13.2.2 mycroft }
518 1.13.2.2 mycroft
519 1.13.2.2 mycroft void
520 1.13.2.2 mycroft usage()
521 1.13.2.2 mycroft {
522 1.13.2.2 mycroft
523 1.13.2.2 mycroft (void)fprintf(stderr,
524 1.13.2.2 mycroft "usage: mount %s %s\n mount %s\n mount %s\n",
525 1.13.2.2 mycroft "[-dfruvw] [-o options] [-t ufs | external_type]",
526 1.13.2.2 mycroft "special node",
527 1.13.2.2 mycroft "[-adfruvw] [-t ufs | external_type]",
528 1.13.2.2 mycroft "[-dfruvw] special | node");
529 1.13.2.2 mycroft exit(1);
530 1.13.2.2 mycroft }
531