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