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