mount.c revision 123242
1/*-
2 * Copyright (c) 1980, 1989, 1993, 1994
3 *	The Regents of the University of California.  All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 *    must display the following acknowledgement:
15 *	This product includes software developed by the University of
16 *	California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 *    may be used to endorse or promote products derived from this software
19 *    without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#ifndef lint
35static const char copyright[] =
36"@(#) Copyright (c) 1980, 1989, 1993, 1994\n\
37	The Regents of the University of California.  All rights reserved.\n";
38#endif /* not lint */
39
40#ifndef lint
41#if 0
42static char sccsid[] = "@(#)mount.c	8.25 (Berkeley) 5/8/95";
43#endif
44static const char rcsid[] =
45  "$FreeBSD: head/sbin/mount/mount.c 123242 2003-12-07 17:00:14Z iedowse $";
46#endif /* not lint */
47
48#include <sys/param.h>
49#include <sys/mount.h>
50#include <sys/stat.h>
51#include <sys/wait.h>
52
53#include <ctype.h>
54#include <err.h>
55#include <errno.h>
56#include <fstab.h>
57#include <paths.h>
58#include <pwd.h>
59#include <signal.h>
60#include <stdint.h>
61#include <stdio.h>
62#include <stdlib.h>
63#include <string.h>
64#include <unistd.h>
65
66#include "extern.h"
67#include "mntopts.h"
68#include "pathnames.h"
69
70/* `meta' options */
71#define MOUNT_META_OPTION_FSTAB		"fstab"
72#define MOUNT_META_OPTION_CURRENT	"current"
73
74int debug, fstab_style, verbose;
75
76char   *catopt(char *, const char *);
77struct statfs *getmntpt(const char *);
78int	hasopt(const char *, const char *);
79int	ismounted(struct fstab *, struct statfs *, int);
80int	isremountable(const char *);
81void	mangle(char *, int *, const char **);
82char   *update_options(char *, char *, int);
83int	mountfs(const char *, const char *, const char *,
84			int, const char *, const char *);
85void	remopt(char *, const char *);
86void	prmount(struct statfs *);
87void	putfsent(const struct statfs *);
88void	usage(void);
89char   *flags2opts(int);
90
91/* Map from mount options to printable formats. */
92static struct opt {
93	int o_opt;
94	const char *o_name;
95} optnames[] = {
96	{ MNT_ASYNC,		"asynchronous" },
97	{ MNT_EXPORTED,		"NFS exported" },
98	{ MNT_LOCAL,		"local" },
99	{ MNT_NOATIME,		"noatime" },
100	{ MNT_NODEV,		"nodev" },
101	{ MNT_NOEXEC,		"noexec" },
102	{ MNT_NOSUID,		"nosuid" },
103	{ MNT_NOSYMFOLLOW,	"nosymfollow" },
104	{ MNT_QUOTA,		"with quotas" },
105	{ MNT_RDONLY,		"read-only" },
106	{ MNT_SYNCHRONOUS,	"synchronous" },
107	{ MNT_UNION,		"union" },
108	{ MNT_NOCLUSTERR,	"noclusterr" },
109	{ MNT_NOCLUSTERW,	"noclusterw" },
110	{ MNT_SUIDDIR,		"suiddir" },
111	{ MNT_SOFTDEP,		"soft-updates" },
112	{ MNT_MULTILABEL,	"multilabel" },
113	{ MNT_ACLS,		"acls" },
114	{ 0, NULL }
115};
116
117/*
118 * List of VFS types that can be remounted without becoming mounted on top
119 * of each other.
120 * XXX Is this list correct?
121 */
122static const char *
123remountable_fs_names[] = {
124	"ufs", "ffs", "ext2fs",
125	0
126};
127
128int
129main(argc, argv)
130	int argc;
131	char * const argv[];
132{
133	const char *mntfromname, **vfslist, *vfstype;
134	struct fstab *fs;
135	struct statfs *mntbuf;
136	FILE *mountdfp;
137	pid_t pid;
138	int all, ch, i, init_flags, mntsize, rval, have_fstab;
139	char *cp, *ep, *options;
140
141	all = init_flags = 0;
142	options = NULL;
143	vfslist = NULL;
144	vfstype = "ufs";
145	while ((ch = getopt(argc, argv, "adF:fo:prwt:uv")) != -1)
146		switch (ch) {
147		case 'a':
148			all = 1;
149			break;
150		case 'd':
151			debug = 1;
152			break;
153		case 'F':
154			setfstab(optarg);
155			break;
156		case 'f':
157			init_flags |= MNT_FORCE;
158			break;
159		case 'o':
160			if (*optarg)
161				options = catopt(options, optarg);
162			break;
163		case 'p':
164			fstab_style = 1;
165			verbose = 1;
166			break;
167		case 'r':
168			options = catopt(options, "ro");
169			break;
170		case 't':
171			if (vfslist != NULL)
172				errx(1, "only one -t option may be specified");
173			vfslist = makevfslist(optarg);
174			vfstype = optarg;
175			break;
176		case 'u':
177			init_flags |= MNT_UPDATE;
178			break;
179		case 'v':
180			verbose = 1;
181			break;
182		case 'w':
183			options = catopt(options, "noro");
184			break;
185		case '?':
186		default:
187			usage();
188			/* NOTREACHED */
189		}
190	argc -= optind;
191	argv += optind;
192
193#define	BADTYPE(type)							\
194	(strcmp(type, FSTAB_RO) &&					\
195	    strcmp(type, FSTAB_RW) && strcmp(type, FSTAB_RQ))
196
197	rval = 0;
198	switch (argc) {
199	case 0:
200		if ((mntsize = getmntinfo(&mntbuf, MNT_NOWAIT)) == 0)
201			err(1, "getmntinfo");
202		if (all) {
203			while ((fs = getfsent()) != NULL) {
204				if (BADTYPE(fs->fs_type))
205					continue;
206				if (checkvfsname(fs->fs_vfstype, vfslist))
207					continue;
208				if (hasopt(fs->fs_mntops, "noauto"))
209					continue;
210				if (!(init_flags & MNT_UPDATE) &&
211				    ismounted(fs, mntbuf, mntsize))
212					continue;
213				if (mountfs(fs->fs_vfstype, fs->fs_spec,
214				    fs->fs_file, init_flags, options,
215				    fs->fs_mntops))
216					rval = 1;
217			}
218		} else if (fstab_style) {
219			for (i = 0; i < mntsize; i++) {
220				if (checkvfsname(mntbuf[i].f_fstypename, vfslist))
221					continue;
222				putfsent(&mntbuf[i]);
223			}
224		} else {
225			for (i = 0; i < mntsize; i++) {
226				if (checkvfsname(mntbuf[i].f_fstypename,
227				    vfslist))
228					continue;
229				prmount(&mntbuf[i]);
230			}
231		}
232		exit(rval);
233	case 1:
234		if (vfslist != NULL)
235			usage();
236
237		if (init_flags & MNT_UPDATE) {
238			mntfromname = NULL;
239			have_fstab = 0;
240			if ((mntbuf = getmntpt(*argv)) == NULL)
241				errx(1, "not currently mounted %s", *argv);
242			/*
243			 * Only get the mntflags from fstab if both mntpoint
244			 * and mntspec are identical. Also handle the special
245			 * case where just '/' is mounted and 'spec' is not
246			 * identical with the one from fstab ('/dev' is missing
247			 * in the spec-string at boot-time).
248			 */
249			if ((fs = getfsfile(mntbuf->f_mntonname)) != NULL) {
250				if (strcmp(fs->fs_spec,
251				    mntbuf->f_mntfromname) == 0 &&
252				    strcmp(fs->fs_file,
253				    mntbuf->f_mntonname) == 0) {
254					have_fstab = 1;
255					mntfromname = mntbuf->f_mntfromname;
256				} else if (argv[0][0] == '/' &&
257				    argv[0][1] == '\0') {
258					fs = getfsfile("/");
259					have_fstab = 1;
260					mntfromname = fs->fs_spec;
261				}
262			}
263			if (have_fstab) {
264				options = update_options(options, fs->fs_mntops,
265				    mntbuf->f_flags);
266			} else {
267				mntfromname = mntbuf->f_mntfromname;
268				options = update_options(options, NULL,
269				    mntbuf->f_flags);
270			}
271			rval = mountfs(mntbuf->f_fstypename, mntfromname,
272			    mntbuf->f_mntonname, init_flags, options, 0);
273			break;
274		}
275		rmslashes(*argv, *argv);
276		if ((fs = getfsfile(*argv)) == NULL &&
277		    (fs = getfsspec(*argv)) == NULL)
278			errx(1, "%s: unknown special file or file system",
279			    *argv);
280		if (BADTYPE(fs->fs_type))
281			errx(1, "%s has unknown file system type",
282			    *argv);
283		rval = mountfs(fs->fs_vfstype, fs->fs_spec, fs->fs_file,
284		    init_flags, options, fs->fs_mntops);
285		break;
286	case 2:
287		/*
288		 * If -t flag has not been specified, the path cannot be
289		 * found, spec contains either a ':' or a '@', then assume
290		 * that an NFS file system is being specified ala Sun.
291		 * Check if the hostname contains only allowed characters
292		 * to reduce false positives.  IPv6 addresses containing
293		 * ':' will be correctly parsed only if the separator is '@'.
294		 * The definition of a valid hostname is taken from RFC 1034.
295		 */
296		if (vfslist == NULL && ((ep = strchr(argv[0], '@')) != NULL ||
297		    (ep = strchr(argv[0], ':')) != NULL)) {
298			if (*ep == '@') {
299				cp = ep + 1;
300				ep = cp + strlen(cp);
301			} else
302				cp = argv[0];
303			while (cp != ep) {
304				if (!isdigit(*cp) && !isalpha(*cp) &&
305				    *cp != '.' && *cp != '-' && *cp != ':')
306					break;
307				cp++;
308			}
309			if (cp == ep)
310				vfstype = "nfs";
311		}
312		rval = mountfs(vfstype,
313		    argv[0], argv[1], init_flags, options, NULL);
314		break;
315	default:
316		usage();
317		/* NOTREACHED */
318	}
319
320	/*
321	 * If the mount was successfully, and done by root, tell mountd the
322	 * good news.  Pid checks are probably unnecessary, but don't hurt.
323	 */
324	if (rval == 0 && getuid() == 0 &&
325	    (mountdfp = fopen(_PATH_MOUNTDPID, "r")) != NULL) {
326		if (fscanf(mountdfp, "%d", &pid) == 1 &&
327		     pid > 0 && kill(pid, SIGHUP) == -1 && errno != ESRCH)
328			err(1, "signal mountd");
329		(void)fclose(mountdfp);
330	}
331
332	exit(rval);
333}
334
335int
336ismounted(fs, mntbuf, mntsize)
337	struct fstab *fs;
338	struct statfs *mntbuf;
339	int mntsize;
340{
341	int i;
342
343	if (fs->fs_file[0] == '/' && fs->fs_file[1] == '\0')
344		/* the root file system can always be remounted */
345		return (0);
346
347	for (i = mntsize - 1; i >= 0; --i)
348		if (strcmp(fs->fs_file, mntbuf[i].f_mntonname) == 0 &&
349		    (!isremountable(fs->fs_vfstype) ||
350		     strcmp(fs->fs_spec, mntbuf[i].f_mntfromname) == 0))
351			return (1);
352	return (0);
353}
354
355int
356isremountable(vfsname)
357	const char *vfsname;
358{
359	const char **cp;
360
361	for (cp = remountable_fs_names; *cp; cp++)
362		if (strcmp(*cp, vfsname) == 0)
363			return (1);
364	return (0);
365}
366
367int
368hasopt(mntopts, option)
369	const char *mntopts, *option;
370{
371	int negative, found;
372	char *opt, *optbuf;
373
374	if (option[0] == 'n' && option[1] == 'o') {
375		negative = 1;
376		option += 2;
377	} else
378		negative = 0;
379	optbuf = strdup(mntopts);
380	found = 0;
381	for (opt = optbuf; (opt = strtok(opt, ",")) != NULL; opt = NULL) {
382		if (opt[0] == 'n' && opt[1] == 'o') {
383			if (!strcasecmp(opt + 2, option))
384				found = negative;
385		} else if (!strcasecmp(opt, option))
386			found = !negative;
387	}
388	free(optbuf);
389	return (found);
390}
391
392int
393mountfs(vfstype, spec, name, flags, options, mntopts)
394	const char *vfstype, *spec, *name, *options, *mntopts;
395	int flags;
396{
397	const char *argv[100];
398	struct statfs sf;
399	pid_t pid;
400	int argc, i, status;
401	char *optbuf, execname[PATH_MAX], mntpath[PATH_MAX];
402
403#if __GNUC__
404	(void)&optbuf;
405	(void)&name;
406#endif
407
408	/* resolve the mountpoint with realpath(3) */
409	(void)checkpath(name, mntpath);
410	name = mntpath;
411
412	if (mntopts == NULL)
413		mntopts = "";
414	if (options == NULL) {
415		if (*mntopts == '\0') {
416			options = "rw";
417		} else {
418			options = mntopts;
419			mntopts = "";
420		}
421	}
422	optbuf = catopt(strdup(mntopts), options);
423
424	if (strcmp(name, "/") == 0)
425		flags |= MNT_UPDATE;
426	if (flags & MNT_FORCE)
427		optbuf = catopt(optbuf, "force");
428	if (flags & MNT_RDONLY)
429		optbuf = catopt(optbuf, "ro");
430	/*
431	 * XXX
432	 * The mount_mfs (newfs) command uses -o to select the
433	 * optimization mode.  We don't pass the default "-o rw"
434	 * for that reason.
435	 */
436	if (flags & MNT_UPDATE)
437		optbuf = catopt(optbuf, "update");
438
439	/* Compatibility glue. */
440	if (strcmp(vfstype, "msdos") == 0)
441		vfstype = "msdosfs";
442
443	argc = 0;
444	argv[argc++] = vfstype;
445	mangle(optbuf, &argc, argv);
446	argv[argc++] = spec;
447	argv[argc++] = name;
448	argv[argc] = NULL;
449
450	if (debug) {
451		(void)printf("exec: mount_%s", vfstype);
452		for (i = 1; i < argc; i++)
453			(void)printf(" %s", argv[i]);
454		(void)printf("\n");
455		return (0);
456	}
457
458	switch (pid = fork()) {
459	case -1:				/* Error. */
460		warn("fork");
461		free(optbuf);
462		return (1);
463	case 0:					/* Child. */
464		if (strcmp(vfstype, "ufs") == 0)
465			exit(mount_ufs(argc, (char * const *) argv));
466
467		/* Go find an executable. */
468		(void)snprintf(execname, sizeof(execname), "mount_%s", vfstype);
469		execvP(execname, _PATH_SYSPATH, (char * const *)argv);
470		if (errno == ENOENT) {
471			warn("exec mount_%s not found in %s", vfstype,
472			    _PATH_SYSPATH);
473		}
474		exit(1);
475		/* NOTREACHED */
476	default:				/* Parent. */
477		free(optbuf);
478
479		if (waitpid(pid, &status, 0) < 0) {
480			warn("waitpid");
481			return (1);
482		}
483
484		if (WIFEXITED(status)) {
485			if (WEXITSTATUS(status) != 0)
486				return (WEXITSTATUS(status));
487		} else if (WIFSIGNALED(status)) {
488			warnx("%s: %s", name, sys_siglist[WTERMSIG(status)]);
489			return (1);
490		}
491
492		if (verbose) {
493			if (statfs(name, &sf) < 0) {
494				warn("statfs %s", name);
495				return (1);
496			}
497			if (fstab_style)
498				putfsent(&sf);
499			else
500				prmount(&sf);
501		}
502		break;
503	}
504
505	return (0);
506}
507
508void
509prmount(sfp)
510	struct statfs *sfp;
511{
512	int flags, i;
513	struct opt *o;
514	struct passwd *pw;
515
516	(void)printf("%s on %s (%s", sfp->f_mntfromname, sfp->f_mntonname,
517	    sfp->f_fstypename);
518
519	flags = sfp->f_flags & MNT_VISFLAGMASK;
520	for (o = optnames; flags && o->o_opt; o++)
521		if (flags & o->o_opt) {
522			(void)printf(", %s", o->o_name);
523			flags &= ~o->o_opt;
524		}
525	if (sfp->f_owner) {
526		(void)printf(", mounted by ");
527		if ((pw = getpwuid(sfp->f_owner)) != NULL)
528			(void)printf("%s", pw->pw_name);
529		else
530			(void)printf("%d", sfp->f_owner);
531	}
532	if (verbose) {
533		if (sfp->f_syncwrites != 0 || sfp->f_asyncwrites != 0)
534			(void)printf(", writes: sync %ju async %ju",
535			    (uintmax_t)sfp->f_syncwrites,
536			    (uintmax_t)sfp->f_asyncwrites);
537		if (sfp->f_syncreads != 0 || sfp->f_asyncreads != 0)
538			(void)printf(", reads: sync %ju async %ju",
539			    (uintmax_t)sfp->f_syncreads,
540			    (uintmax_t)sfp->f_asyncreads);
541		if (sfp->f_fsid.val[0] != 0 || sfp->f_fsid.val[1] != 0) {
542			printf(", fsid ");
543			for (i = 0; i < sizeof(sfp->f_fsid); i++)
544				printf("%02x", ((u_char *)&sfp->f_fsid)[i]);
545		}
546	}
547	(void)printf(")\n");
548}
549
550struct statfs *
551getmntpt(name)
552	const char *name;
553{
554	struct statfs *mntbuf;
555	int i, mntsize;
556
557	mntsize = getmntinfo(&mntbuf, MNT_NOWAIT);
558	for (i = mntsize - 1; i >= 0; i--) {
559		if (strcmp(mntbuf[i].f_mntfromname, name) == 0 ||
560		    strcmp(mntbuf[i].f_mntonname, name) == 0)
561			return (&mntbuf[i]);
562	}
563	return (NULL);
564}
565
566char *
567catopt(s0, s1)
568	char *s0;
569	const char *s1;
570{
571	size_t i;
572	char *cp;
573
574	if (s1 == NULL || *s1 == '\0')
575		return s0;
576
577	if (s0 && *s0) {
578		i = strlen(s0) + strlen(s1) + 1 + 1;
579		if ((cp = malloc(i)) == NULL)
580			errx(1, "malloc failed");
581		(void)snprintf(cp, i, "%s,%s", s0, s1);
582	} else
583		cp = strdup(s1);
584
585	if (s0)
586		free(s0);
587	return (cp);
588}
589
590void
591mangle(options, argcp, argv)
592	char *options;
593	int *argcp;
594	const char **argv;
595{
596	char *p, *s;
597	int argc;
598
599	argc = *argcp;
600	for (s = options; (p = strsep(&s, ",")) != NULL;)
601		if (*p != '\0') {
602			if (*p == '-') {
603				argv[argc++] = p;
604				p = strchr(p, '=');
605				if (p) {
606					*p = '\0';
607					argv[argc++] = p+1;
608				}
609			} else if (strcmp(p, "rw") != 0) {
610				argv[argc++] = "-o";
611				argv[argc++] = p;
612			}
613		}
614
615	*argcp = argc;
616}
617
618
619char *
620update_options(opts, fstab, curflags)
621	char *opts;
622	char *fstab;
623	int curflags;
624{
625	char *o, *p;
626	char *cur;
627	char *expopt, *newopt, *tmpopt;
628
629	if (opts == NULL)
630		return strdup("");
631
632	/* remove meta options from list */
633	remopt(fstab, MOUNT_META_OPTION_FSTAB);
634	remopt(fstab, MOUNT_META_OPTION_CURRENT);
635	cur = flags2opts(curflags);
636
637	/*
638	 * Expand all meta-options passed to us first.
639	 */
640	expopt = NULL;
641	for (p = opts; (o = strsep(&p, ",")) != NULL;) {
642		if (strcmp(MOUNT_META_OPTION_FSTAB, o) == 0)
643			expopt = catopt(expopt, fstab);
644		else if (strcmp(MOUNT_META_OPTION_CURRENT, o) == 0)
645			expopt = catopt(expopt, cur);
646		else
647			expopt = catopt(expopt, o);
648	}
649	free(cur);
650	free(opts);
651
652	/*
653	 * Remove previous contradictory arguments. Given option "foo" we
654	 * remove all the "nofoo" options. Given "nofoo" we remove "nonofoo"
655	 * and "foo" - so we can deal with possible options like "notice".
656	 */
657	newopt = NULL;
658	for (p = expopt; (o = strsep(&p, ",")) != NULL;) {
659		if ((tmpopt = malloc( strlen(o) + 2 + 1 )) == NULL)
660			errx(1, "malloc failed");
661
662		strcpy(tmpopt, "no");
663		strcat(tmpopt, o);
664		remopt(newopt, tmpopt);
665		free(tmpopt);
666
667		if (strncmp("no", o, 2) == 0)
668			remopt(newopt, o+2);
669
670		newopt = catopt(newopt, o);
671	}
672	free(expopt);
673
674	return newopt;
675}
676
677void
678remopt(string, opt)
679	char *string;
680 	const char *opt;
681{
682	char *o, *p, *r;
683
684	if (string == NULL || *string == '\0' || opt == NULL || *opt == '\0')
685		return;
686
687	r = string;
688
689	for (p = string; (o = strsep(&p, ",")) != NULL;) {
690		if (strcmp(opt, o) != 0) {
691			if (*r == ',' && *o != '\0')
692				r++;
693			while ((*r++ = *o++) != '\0')
694			    ;
695			*--r = ',';
696		}
697	}
698	*r = '\0';
699}
700
701void
702usage()
703{
704
705	(void)fprintf(stderr, "%s\n%s\n%s\n",
706"usage: mount [-dfpruvw] [-o options] [-t ufs | external_type] special node",
707"       mount [-adfpruvw] [ -F fstab] [-t ufs | external_type]",
708"       mount [-dfpruvw] special | node");
709	exit(1);
710}
711
712void
713putfsent(ent)
714	const struct statfs *ent;
715{
716	struct fstab *fst;
717	char *opts;
718
719	opts = flags2opts(ent->f_flags);
720	printf("%s\t%s\t%s %s", ent->f_mntfromname, ent->f_mntonname,
721	    ent->f_fstypename, opts);
722	free(opts);
723
724	if ((fst = getfsspec(ent->f_mntfromname)))
725		printf("\t%u %u\n", fst->fs_freq, fst->fs_passno);
726	else if ((fst = getfsfile(ent->f_mntonname)))
727		printf("\t%u %u\n", fst->fs_freq, fst->fs_passno);
728	else if (strcmp(ent->f_fstypename, "ufs") == 0) {
729		if (strcmp(ent->f_mntonname, "/") == 0)
730			printf("\t1 1\n");
731		else
732			printf("\t2 2\n");
733	} else
734		printf("\t0 0\n");
735}
736
737
738char *
739flags2opts(flags)
740	int flags;
741{
742	char *res;
743
744	res = NULL;
745
746	res = catopt(res, (flags & MNT_RDONLY) ? "ro" : "rw");
747
748	if (flags & MNT_SYNCHRONOUS)	res = catopt(res, "sync");
749	if (flags & MNT_NOEXEC)		res = catopt(res, "noexec");
750	if (flags & MNT_NOSUID)		res = catopt(res, "nosuid");
751	if (flags & MNT_NODEV)		res = catopt(res, "nodev");
752	if (flags & MNT_UNION)		res = catopt(res, "union");
753	if (flags & MNT_ASYNC)		res = catopt(res, "async");
754	if (flags & MNT_NOATIME)	res = catopt(res, "noatime");
755	if (flags & MNT_NOCLUSTERR)	res = catopt(res, "noclusterr");
756	if (flags & MNT_NOCLUSTERW)	res = catopt(res, "noclusterw");
757	if (flags & MNT_NOSYMFOLLOW)	res = catopt(res, "nosymfollow");
758	if (flags & MNT_SUIDDIR)	res = catopt(res, "suiddir");
759	if (flags & MNT_MULTILABEL)	res = catopt(res, "multilabel");
760	if (flags & MNT_ACLS)		res = catopt(res, "acls");
761
762	return res;
763}
764