mount.c revision 125200
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 125200 2004-01-29 15:14:03Z guido $";
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				options = update_options(options, fs->fs_mntops,
214				    mntbuf->f_flags);
215				if (mountfs(fs->fs_vfstype, fs->fs_spec,
216				    fs->fs_file, init_flags, options,
217				    fs->fs_mntops))
218					rval = 1;
219			}
220		} else if (fstab_style) {
221			for (i = 0; i < mntsize; i++) {
222				if (checkvfsname(mntbuf[i].f_fstypename, vfslist))
223					continue;
224				putfsent(&mntbuf[i]);
225			}
226		} else {
227			for (i = 0; i < mntsize; i++) {
228				if (checkvfsname(mntbuf[i].f_fstypename,
229				    vfslist))
230					continue;
231				prmount(&mntbuf[i]);
232			}
233		}
234		exit(rval);
235	case 1:
236		if (vfslist != NULL)
237			usage();
238
239		rmslashes(*argv, *argv);
240		if (init_flags & MNT_UPDATE) {
241			mntfromname = NULL;
242			have_fstab = 0;
243			if ((mntbuf = getmntpt(*argv)) == NULL)
244				errx(1, "not currently mounted %s", *argv);
245			/*
246			 * Only get the mntflags from fstab if both mntpoint
247			 * and mntspec are identical. Also handle the special
248			 * case where just '/' is mounted and 'spec' is not
249			 * identical with the one from fstab ('/dev' is missing
250			 * in the spec-string at boot-time).
251			 */
252			if ((fs = getfsfile(mntbuf->f_mntonname)) != NULL) {
253				if (strcmp(fs->fs_spec,
254				    mntbuf->f_mntfromname) == 0 &&
255				    strcmp(fs->fs_file,
256				    mntbuf->f_mntonname) == 0) {
257					have_fstab = 1;
258					mntfromname = mntbuf->f_mntfromname;
259				} else if (argv[0][0] == '/' &&
260				    argv[0][1] == '\0') {
261					fs = getfsfile("/");
262					have_fstab = 1;
263					mntfromname = fs->fs_spec;
264				}
265			}
266			if (have_fstab) {
267				options = update_options(options, fs->fs_mntops,
268				    mntbuf->f_flags);
269			} else {
270				mntfromname = mntbuf->f_mntfromname;
271				options = update_options(options, NULL,
272				    mntbuf->f_flags);
273			}
274			rval = mountfs(mntbuf->f_fstypename, mntfromname,
275			    mntbuf->f_mntonname, init_flags, options, 0);
276			break;
277		}
278		if ((fs = getfsfile(*argv)) == NULL &&
279		    (fs = getfsspec(*argv)) == NULL)
280			errx(1, "%s: unknown special file or file system",
281			    *argv);
282		if (BADTYPE(fs->fs_type))
283			errx(1, "%s has unknown file system type",
284			    *argv);
285		rval = mountfs(fs->fs_vfstype, fs->fs_spec, fs->fs_file,
286		    init_flags, options, fs->fs_mntops);
287		break;
288	case 2:
289		/*
290		 * If -t flag has not been specified, the path cannot be
291		 * found, spec contains either a ':' or a '@', then assume
292		 * that an NFS file system is being specified ala Sun.
293		 * Check if the hostname contains only allowed characters
294		 * to reduce false positives.  IPv6 addresses containing
295		 * ':' will be correctly parsed only if the separator is '@'.
296		 * The definition of a valid hostname is taken from RFC 1034.
297		 */
298		if (vfslist == NULL && ((ep = strchr(argv[0], '@')) != NULL ||
299		    (ep = strchr(argv[0], ':')) != NULL)) {
300			if (*ep == '@') {
301				cp = ep + 1;
302				ep = cp + strlen(cp);
303			} else
304				cp = argv[0];
305			while (cp != ep) {
306				if (!isdigit(*cp) && !isalpha(*cp) &&
307				    *cp != '.' && *cp != '-' && *cp != ':')
308					break;
309				cp++;
310			}
311			if (cp == ep)
312				vfstype = "nfs";
313		}
314		rval = mountfs(vfstype,
315		    argv[0], argv[1], init_flags, options, NULL);
316		break;
317	default:
318		usage();
319		/* NOTREACHED */
320	}
321
322	/*
323	 * If the mount was successfully, and done by root, tell mountd the
324	 * good news.  Pid checks are probably unnecessary, but don't hurt.
325	 */
326	if (rval == 0 && getuid() == 0 &&
327	    (mountdfp = fopen(_PATH_MOUNTDPID, "r")) != NULL) {
328		if (fscanf(mountdfp, "%d", &pid) == 1 &&
329		     pid > 0 && kill(pid, SIGHUP) == -1 && errno != ESRCH)
330			err(1, "signal mountd");
331		(void)fclose(mountdfp);
332	}
333
334	exit(rval);
335}
336
337int
338ismounted(fs, mntbuf, mntsize)
339	struct fstab *fs;
340	struct statfs *mntbuf;
341	int mntsize;
342{
343	int i;
344
345	if (fs->fs_file[0] == '/' && fs->fs_file[1] == '\0')
346		/* the root file system can always be remounted */
347		return (0);
348
349	for (i = mntsize - 1; i >= 0; --i)
350		if (strcmp(fs->fs_file, mntbuf[i].f_mntonname) == 0 &&
351		    (!isremountable(fs->fs_vfstype) ||
352		     strcmp(fs->fs_spec, mntbuf[i].f_mntfromname) == 0))
353			return (1);
354	return (0);
355}
356
357int
358isremountable(vfsname)
359	const char *vfsname;
360{
361	const char **cp;
362
363	for (cp = remountable_fs_names; *cp; cp++)
364		if (strcmp(*cp, vfsname) == 0)
365			return (1);
366	return (0);
367}
368
369int
370hasopt(mntopts, option)
371	const char *mntopts, *option;
372{
373	int negative, found;
374	char *opt, *optbuf;
375
376	if (option[0] == 'n' && option[1] == 'o') {
377		negative = 1;
378		option += 2;
379	} else
380		negative = 0;
381	optbuf = strdup(mntopts);
382	found = 0;
383	for (opt = optbuf; (opt = strtok(opt, ",")) != NULL; opt = NULL) {
384		if (opt[0] == 'n' && opt[1] == 'o') {
385			if (!strcasecmp(opt + 2, option))
386				found = negative;
387		} else if (!strcasecmp(opt, option))
388			found = !negative;
389	}
390	free(optbuf);
391	return (found);
392}
393
394int
395mountfs(vfstype, spec, name, flags, options, mntopts)
396	const char *vfstype, *spec, *name, *options, *mntopts;
397	int flags;
398{
399	const char *argv[100];
400	struct statfs sf;
401	pid_t pid;
402	int argc, i, status;
403	char *optbuf, execname[PATH_MAX], mntpath[PATH_MAX];
404
405#if __GNUC__
406	(void)&optbuf;
407	(void)&name;
408#endif
409
410	/* resolve the mountpoint with realpath(3) */
411	(void)checkpath(name, mntpath);
412	name = mntpath;
413
414	if (mntopts == NULL)
415		mntopts = "";
416	if (options == NULL) {
417		if (*mntopts == '\0') {
418			options = "rw";
419		} else {
420			options = mntopts;
421			mntopts = "";
422		}
423	}
424	optbuf = catopt(strdup(mntopts), options);
425
426	if (strcmp(name, "/") == 0)
427		flags |= MNT_UPDATE;
428	if (flags & MNT_FORCE)
429		optbuf = catopt(optbuf, "force");
430	if (flags & MNT_RDONLY)
431		optbuf = catopt(optbuf, "ro");
432	/*
433	 * XXX
434	 * The mount_mfs (newfs) command uses -o to select the
435	 * optimization mode.  We don't pass the default "-o rw"
436	 * for that reason.
437	 */
438	if (flags & MNT_UPDATE)
439		optbuf = catopt(optbuf, "update");
440
441	/* Compatibility glue. */
442	if (strcmp(vfstype, "msdos") == 0)
443		vfstype = "msdosfs";
444
445	argc = 0;
446	argv[argc++] = vfstype;
447	mangle(optbuf, &argc, argv);
448	argv[argc++] = spec;
449	argv[argc++] = name;
450	argv[argc] = NULL;
451
452	if (debug) {
453		(void)printf("exec: mount_%s", vfstype);
454		for (i = 1; i < argc; i++)
455			(void)printf(" %s", argv[i]);
456		(void)printf("\n");
457		return (0);
458	}
459
460	switch (pid = fork()) {
461	case -1:				/* Error. */
462		warn("fork");
463		free(optbuf);
464		return (1);
465	case 0:					/* Child. */
466		if (strcmp(vfstype, "ufs") == 0)
467			exit(mount_ufs(argc, (char * const *) argv));
468
469		/* Go find an executable. */
470		(void)snprintf(execname, sizeof(execname), "mount_%s", vfstype);
471		execvP(execname, _PATH_SYSPATH, (char * const *)argv);
472		if (errno == ENOENT) {
473			warn("exec mount_%s not found in %s", vfstype,
474			    _PATH_SYSPATH);
475		}
476		exit(1);
477		/* NOTREACHED */
478	default:				/* Parent. */
479		free(optbuf);
480
481		if (waitpid(pid, &status, 0) < 0) {
482			warn("waitpid");
483			return (1);
484		}
485
486		if (WIFEXITED(status)) {
487			if (WEXITSTATUS(status) != 0)
488				return (WEXITSTATUS(status));
489		} else if (WIFSIGNALED(status)) {
490			warnx("%s: %s", name, sys_siglist[WTERMSIG(status)]);
491			return (1);
492		}
493
494		if (verbose) {
495			if (statfs(name, &sf) < 0) {
496				warn("statfs %s", name);
497				return (1);
498			}
499			if (fstab_style)
500				putfsent(&sf);
501			else
502				prmount(&sf);
503		}
504		break;
505	}
506
507	return (0);
508}
509
510void
511prmount(sfp)
512	struct statfs *sfp;
513{
514	int flags, i;
515	struct opt *o;
516	struct passwd *pw;
517
518	(void)printf("%s on %s (%s", sfp->f_mntfromname, sfp->f_mntonname,
519	    sfp->f_fstypename);
520
521	flags = sfp->f_flags & MNT_VISFLAGMASK;
522	for (o = optnames; flags && o->o_opt; o++)
523		if (flags & o->o_opt) {
524			(void)printf(", %s", o->o_name);
525			flags &= ~o->o_opt;
526		}
527	if (sfp->f_owner) {
528		(void)printf(", mounted by ");
529		if ((pw = getpwuid(sfp->f_owner)) != NULL)
530			(void)printf("%s", pw->pw_name);
531		else
532			(void)printf("%d", sfp->f_owner);
533	}
534	if (verbose) {
535		if (sfp->f_syncwrites != 0 || sfp->f_asyncwrites != 0)
536			(void)printf(", writes: sync %ju async %ju",
537			    (uintmax_t)sfp->f_syncwrites,
538			    (uintmax_t)sfp->f_asyncwrites);
539		if (sfp->f_syncreads != 0 || sfp->f_asyncreads != 0)
540			(void)printf(", reads: sync %ju async %ju",
541			    (uintmax_t)sfp->f_syncreads,
542			    (uintmax_t)sfp->f_asyncreads);
543		if (sfp->f_fsid.val[0] != 0 || sfp->f_fsid.val[1] != 0) {
544			printf(", fsid ");
545			for (i = 0; i < sizeof(sfp->f_fsid); i++)
546				printf("%02x", ((u_char *)&sfp->f_fsid)[i]);
547		}
548	}
549	(void)printf(")\n");
550}
551
552struct statfs *
553getmntpt(name)
554	const char *name;
555{
556	struct statfs *mntbuf;
557	int i, mntsize;
558
559	mntsize = getmntinfo(&mntbuf, MNT_NOWAIT);
560	for (i = mntsize - 1; i >= 0; i--) {
561		if (strcmp(mntbuf[i].f_mntfromname, name) == 0 ||
562		    strcmp(mntbuf[i].f_mntonname, name) == 0)
563			return (&mntbuf[i]);
564	}
565	return (NULL);
566}
567
568char *
569catopt(s0, s1)
570	char *s0;
571	const char *s1;
572{
573	size_t i;
574	char *cp;
575
576	if (s1 == NULL || *s1 == '\0')
577		return s0;
578
579	if (s0 && *s0) {
580		i = strlen(s0) + strlen(s1) + 1 + 1;
581		if ((cp = malloc(i)) == NULL)
582			errx(1, "malloc failed");
583		(void)snprintf(cp, i, "%s,%s", s0, s1);
584	} else
585		cp = strdup(s1);
586
587	if (s0)
588		free(s0);
589	return (cp);
590}
591
592void
593mangle(options, argcp, argv)
594	char *options;
595	int *argcp;
596	const char **argv;
597{
598	char *p, *s;
599	int argc;
600
601	argc = *argcp;
602	for (s = options; (p = strsep(&s, ",")) != NULL;)
603		if (*p != '\0') {
604			if (*p == '-') {
605				argv[argc++] = p;
606				p = strchr(p, '=');
607				if (p != NULL) {
608					*p = '\0';
609					argv[argc++] = p+1;
610				}
611			} else if (strcmp(p, "rw") != 0) {
612				argv[argc++] = "-o";
613				argv[argc++] = p;
614			}
615		}
616
617	*argcp = argc;
618}
619
620
621char *
622update_options(opts, fstab, curflags)
623	char *opts;
624	char *fstab;
625	int curflags;
626{
627	char *o, *p;
628	char *cur;
629	char *expopt, *newopt, *tmpopt;
630
631	if (opts == NULL)
632		return strdup("");
633
634	/* remove meta options from list */
635	remopt(fstab, MOUNT_META_OPTION_FSTAB);
636	remopt(fstab, MOUNT_META_OPTION_CURRENT);
637	cur = flags2opts(curflags);
638
639	/*
640	 * Expand all meta-options passed to us first.
641	 */
642	expopt = NULL;
643	for (p = opts; (o = strsep(&p, ",")) != NULL;) {
644		if (strcmp(MOUNT_META_OPTION_FSTAB, o) == 0)
645			expopt = catopt(expopt, fstab);
646		else if (strcmp(MOUNT_META_OPTION_CURRENT, o) == 0)
647			expopt = catopt(expopt, cur);
648		else
649			expopt = catopt(expopt, o);
650	}
651	free(cur);
652	free(opts);
653
654	/*
655	 * Remove previous contradictory arguments. Given option "foo" we
656	 * remove all the "nofoo" options. Given "nofoo" we remove "nonofoo"
657	 * and "foo" - so we can deal with possible options like "notice".
658	 */
659	newopt = NULL;
660	for (p = expopt; (o = strsep(&p, ",")) != NULL;) {
661		if ((tmpopt = malloc( strlen(o) + 2 + 1 )) == NULL)
662			errx(1, "malloc failed");
663
664		strcpy(tmpopt, "no");
665		strcat(tmpopt, o);
666		remopt(newopt, tmpopt);
667		free(tmpopt);
668
669		if (strncmp("no", o, 2) == 0)
670			remopt(newopt, o+2);
671
672		newopt = catopt(newopt, o);
673	}
674	free(expopt);
675
676	return newopt;
677}
678
679void
680remopt(string, opt)
681	char *string;
682 	const char *opt;
683{
684	char *o, *p, *r;
685
686	if (string == NULL || *string == '\0' || opt == NULL || *opt == '\0')
687		return;
688
689	r = string;
690
691	for (p = string; (o = strsep(&p, ",")) != NULL;) {
692		if (strcmp(opt, o) != 0) {
693			if (*r == ',' && *o != '\0')
694				r++;
695			while ((*r++ = *o++) != '\0')
696			    ;
697			*--r = ',';
698		}
699	}
700	*r = '\0';
701}
702
703void
704usage()
705{
706
707	(void)fprintf(stderr, "%s\n%s\n%s\n",
708"usage: mount [-dfpruvw] [-o options] [-t ufs | external_type] special node",
709"       mount [-adfpruvw] [ -F fstab] [-o options] [-t ufs | external_type]",
710"       mount [-dfpruvw] special | node");
711	exit(1);
712}
713
714void
715putfsent(ent)
716	const struct statfs *ent;
717{
718	struct fstab *fst;
719	char *opts;
720
721	opts = flags2opts(ent->f_flags);
722	printf("%s\t%s\t%s %s", ent->f_mntfromname, ent->f_mntonname,
723	    ent->f_fstypename, opts);
724	free(opts);
725
726	if ((fst = getfsspec(ent->f_mntfromname)))
727		printf("\t%u %u\n", fst->fs_freq, fst->fs_passno);
728	else if ((fst = getfsfile(ent->f_mntonname)))
729		printf("\t%u %u\n", fst->fs_freq, fst->fs_passno);
730	else if (strcmp(ent->f_fstypename, "ufs") == 0) {
731		if (strcmp(ent->f_mntonname, "/") == 0)
732			printf("\t1 1\n");
733		else
734			printf("\t2 2\n");
735	} else
736		printf("\t0 0\n");
737}
738
739
740char *
741flags2opts(flags)
742	int flags;
743{
744	char *res;
745
746	res = NULL;
747
748	res = catopt(res, (flags & MNT_RDONLY) ? "ro" : "rw");
749
750	if (flags & MNT_SYNCHRONOUS)	res = catopt(res, "sync");
751	if (flags & MNT_NOEXEC)		res = catopt(res, "noexec");
752	if (flags & MNT_NOSUID)		res = catopt(res, "nosuid");
753	if (flags & MNT_NODEV)		res = catopt(res, "nodev");
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