mount.c revision 152668
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 152668 2005-11-21 22:07:54Z rodrigc $"; 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 *, 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 123static int 124use_mountprog(const char *vfstype) 125{ 126 /* XXX: We need to get away from implementing external mount 127 * programs for every filesystem, and move towards having 128 * each filesystem properly implement the nmount() system call. 129 */ 130 unsigned int i; 131 const char *fs[] = { 132 "mfs", "msdosfs", "nfs", "nfs4", "ntfs", 133 "nwfs", "nullfs", "portalfs", "reiserfs", "smbfs", "udf", "umapfs", 134 "unionfs", 135 NULL 136 }; 137 138 for (i=0; fs[i] != NULL; ++i) { 139 if (strcmp(vfstype, fs[i]) == 0) 140 return 1; 141 } 142 143 return 0; 144} 145 146static int 147exec_mountprog(const char *name, const char *execname, 148 char *const argv[]) 149{ 150 pid_t pid; 151 int status; 152 153 switch (pid = fork()) { 154 case -1: /* Error. */ 155 warn("fork"); 156 exit (1); 157 case 0: /* Child. */ 158 /* Go find an executable. */ 159 execvP(execname, _PATH_SYSPATH, argv); 160 if (errno == ENOENT) { 161 warn("exec %s not found in %s", execname, 162 _PATH_SYSPATH); 163 } 164 exit(1); 165 default: /* Parent. */ 166 if (waitpid(pid, &status, 0) < 0) { 167 warn("waitpid"); 168 return (1); 169 } 170 171 if (WIFEXITED(status)) { 172 if (WEXITSTATUS(status) != 0) 173 return (WEXITSTATUS(status)); 174 } else if (WIFSIGNALED(status)) { 175 warnx("%s: %s", name, sys_siglist[WTERMSIG(status)]); 176 return (1); 177 } 178 break; 179 } 180 181 return (0); 182} 183 184int 185main(int argc, char *argv[]) 186{ 187 const char *mntfromname, **vfslist, *vfstype; 188 struct fstab *fs; 189 struct statfs *mntbuf; 190 FILE *mountdfp; 191 pid_t pid; 192 int all, ch, i, init_flags, mntsize, rval, have_fstab; 193 char *cp, *ep, *options; 194 195 all = init_flags = 0; 196 options = NULL; 197 vfslist = NULL; 198 vfstype = "ufs"; 199 while ((ch = getopt(argc, argv, "adF:fo:prwt:uv")) != -1) 200 switch (ch) { 201 case 'a': 202 all = 1; 203 break; 204 case 'd': 205 debug = 1; 206 break; 207 case 'F': 208 setfstab(optarg); 209 break; 210 case 'f': 211 init_flags |= MNT_FORCE; 212 break; 213 case 'o': 214 if (*optarg) 215 options = catopt(options, optarg); 216 break; 217 case 'p': 218 fstab_style = 1; 219 verbose = 1; 220 break; 221 case 'r': 222 options = catopt(options, "ro"); 223 break; 224 case 't': 225 if (vfslist != NULL) 226 errx(1, "only one -t option may be specified"); 227 vfslist = makevfslist(optarg); 228 vfstype = optarg; 229 break; 230 case 'u': 231 init_flags |= MNT_UPDATE; 232 break; 233 case 'v': 234 verbose = 1; 235 break; 236 case 'w': 237 options = catopt(options, "noro"); 238 break; 239 case '?': 240 default: 241 usage(); 242 /* NOTREACHED */ 243 } 244 argc -= optind; 245 argv += optind; 246 247#define BADTYPE(type) \ 248 (strcmp(type, FSTAB_RO) && \ 249 strcmp(type, FSTAB_RW) && strcmp(type, FSTAB_RQ)) 250 251 rval = 0; 252 switch (argc) { 253 case 0: 254 if ((mntsize = getmntinfo(&mntbuf, MNT_NOWAIT)) == 0) 255 err(1, "getmntinfo"); 256 if (all) { 257 while ((fs = getfsent()) != NULL) { 258 if (BADTYPE(fs->fs_type)) 259 continue; 260 if (checkvfsname(fs->fs_vfstype, vfslist)) 261 continue; 262 if (hasopt(fs->fs_mntops, "noauto")) 263 continue; 264 if (!(init_flags & MNT_UPDATE) && 265 ismounted(fs, mntbuf, mntsize)) 266 continue; 267 options = update_options(options, fs->fs_mntops, 268 mntbuf->f_flags); 269 if (mountfs(fs->fs_vfstype, fs->fs_spec, 270 fs->fs_file, init_flags, options, 271 fs->fs_mntops)) 272 rval = 1; 273 } 274 } else if (fstab_style) { 275 for (i = 0; i < mntsize; i++) { 276 if (checkvfsname(mntbuf[i].f_fstypename, vfslist)) 277 continue; 278 putfsent(&mntbuf[i]); 279 } 280 } else { 281 for (i = 0; i < mntsize; i++) { 282 if (checkvfsname(mntbuf[i].f_fstypename, 283 vfslist)) 284 continue; 285 prmount(&mntbuf[i]); 286 } 287 } 288 exit(rval); 289 case 1: 290 if (vfslist != NULL) 291 usage(); 292 293 rmslashes(*argv, *argv); 294 if (init_flags & MNT_UPDATE) { 295 mntfromname = NULL; 296 have_fstab = 0; 297 if ((mntbuf = getmntpt(*argv)) == NULL) 298 errx(1, "not currently mounted %s", *argv); 299 /* 300 * Only get the mntflags from fstab if both mntpoint 301 * and mntspec are identical. Also handle the special 302 * case where just '/' is mounted and 'spec' is not 303 * identical with the one from fstab ('/dev' is missing 304 * in the spec-string at boot-time). 305 */ 306 if ((fs = getfsfile(mntbuf->f_mntonname)) != NULL) { 307 if (strcmp(fs->fs_spec, 308 mntbuf->f_mntfromname) == 0 && 309 strcmp(fs->fs_file, 310 mntbuf->f_mntonname) == 0) { 311 have_fstab = 1; 312 mntfromname = mntbuf->f_mntfromname; 313 } else if (argv[0][0] == '/' && 314 argv[0][1] == '\0') { 315 fs = getfsfile("/"); 316 have_fstab = 1; 317 mntfromname = fs->fs_spec; 318 } 319 } 320 if (have_fstab) { 321 options = update_options(options, fs->fs_mntops, 322 mntbuf->f_flags); 323 } else { 324 mntfromname = mntbuf->f_mntfromname; 325 options = update_options(options, NULL, 326 mntbuf->f_flags); 327 } 328 rval = mountfs(mntbuf->f_fstypename, mntfromname, 329 mntbuf->f_mntonname, init_flags, options, 0); 330 break; 331 } 332 if ((fs = getfsfile(*argv)) == NULL && 333 (fs = getfsspec(*argv)) == NULL) 334 errx(1, "%s: unknown special file or file system", 335 *argv); 336 if (BADTYPE(fs->fs_type)) 337 errx(1, "%s has unknown file system type", 338 *argv); 339 rval = mountfs(fs->fs_vfstype, fs->fs_spec, fs->fs_file, 340 init_flags, options, fs->fs_mntops); 341 break; 342 case 2: 343 /* 344 * If -t flag has not been specified, the path cannot be 345 * found, spec contains either a ':' or a '@', then assume 346 * that an NFS file system is being specified ala Sun. 347 * Check if the hostname contains only allowed characters 348 * to reduce false positives. IPv6 addresses containing 349 * ':' will be correctly parsed only if the separator is '@'. 350 * The definition of a valid hostname is taken from RFC 1034. 351 */ 352 if (vfslist == NULL && ((ep = strchr(argv[0], '@')) != NULL || 353 (ep = strchr(argv[0], ':')) != NULL)) { 354 if (*ep == '@') { 355 cp = ep + 1; 356 ep = cp + strlen(cp); 357 } else 358 cp = argv[0]; 359 while (cp != ep) { 360 if (!isdigit(*cp) && !isalpha(*cp) && 361 *cp != '.' && *cp != '-' && *cp != ':') 362 break; 363 cp++; 364 } 365 if (cp == ep) 366 vfstype = "nfs"; 367 } 368 rval = mountfs(vfstype, 369 argv[0], argv[1], init_flags, options, NULL); 370 break; 371 default: 372 usage(); 373 /* NOTREACHED */ 374 } 375 376 /* 377 * If the mount was successfully, and done by root, tell mountd the 378 * good news. Pid checks are probably unnecessary, but don't hurt. 379 */ 380 if (rval == 0 && getuid() == 0 && 381 (mountdfp = fopen(_PATH_MOUNTDPID, "r")) != NULL) { 382 if (fscanf(mountdfp, "%d", &pid) == 1 && 383 pid > 0 && kill(pid, SIGHUP) == -1 && errno != ESRCH) 384 err(1, "signal mountd"); 385 (void)fclose(mountdfp); 386 } 387 388 exit(rval); 389} 390 391int 392ismounted(struct fstab *fs, struct statfs *mntbuf, int mntsize) 393{ 394 int i; 395 396 if (fs->fs_file[0] == '/' && fs->fs_file[1] == '\0') 397 /* the root file system can always be remounted */ 398 return (0); 399 400 for (i = mntsize - 1; i >= 0; --i) 401 if (strcmp(fs->fs_file, mntbuf[i].f_mntonname) == 0 && 402 (!isremountable(fs->fs_vfstype) || 403 strcmp(fs->fs_spec, mntbuf[i].f_mntfromname) == 0)) 404 return (1); 405 return (0); 406} 407 408int 409isremountable(const char *vfsname) 410{ 411 const char **cp; 412 413 for (cp = remountable_fs_names; *cp; cp++) 414 if (strcmp(*cp, vfsname) == 0) 415 return (1); 416 return (0); 417} 418 419int 420hasopt(const char *mntopts, const char *option) 421{ 422 int negative, found; 423 char *opt, *optbuf; 424 425 if (option[0] == 'n' && option[1] == 'o') { 426 negative = 1; 427 option += 2; 428 } else 429 negative = 0; 430 optbuf = strdup(mntopts); 431 found = 0; 432 for (opt = optbuf; (opt = strtok(opt, ",")) != NULL; opt = NULL) { 433 if (opt[0] == 'n' && opt[1] == 'o') { 434 if (!strcasecmp(opt + 2, option)) 435 found = negative; 436 } else if (!strcasecmp(opt, option)) 437 found = !negative; 438 } 439 free(optbuf); 440 return (found); 441} 442 443int 444mountfs(const char *vfstype, const char *spec, const char *name, int flags, 445 const char *options, const char *mntopts) 446{ 447 char *argv[100]; 448 struct statfs sf; 449 int argc, i, ret; 450 char *optbuf, execname[PATH_MAX], mntpath[PATH_MAX]; 451 452#if __GNUC__ 453 (void)&optbuf; 454 (void)&name; 455#endif 456 457 /* resolve the mountpoint with realpath(3) */ 458 (void)checkpath(name, mntpath); 459 name = mntpath; 460 461 if (mntopts == NULL) 462 mntopts = ""; 463 if (options == NULL) { 464 if (*mntopts == '\0') { 465 options = "rw"; 466 } else { 467 options = mntopts; 468 mntopts = ""; 469 } 470 } 471 optbuf = catopt(strdup(mntopts), options); 472 473 if (strcmp(name, "/") == 0) 474 flags |= MNT_UPDATE; 475 if (flags & MNT_FORCE) 476 optbuf = catopt(optbuf, "force"); 477 if (flags & MNT_RDONLY) 478 optbuf = catopt(optbuf, "ro"); 479 /* 480 * XXX 481 * The mount_mfs (newfs) command uses -o to select the 482 * optimization mode. We don't pass the default "-o rw" 483 * for that reason. 484 */ 485 if (flags & MNT_UPDATE) 486 optbuf = catopt(optbuf, "update"); 487 488 /* Compatibility glue. */ 489 if (strcmp(vfstype, "msdos") == 0) 490 vfstype = "msdosfs"; 491 492 /* Construct the name of the appropriate mount command */ 493 (void)snprintf(execname, sizeof(execname), "mount_%s", vfstype); 494 495 argc = 0; 496 argv[argc++] = execname; 497 mangle(optbuf, &argc, argv); 498 argv[argc++] = strdup(spec); 499 argv[argc++] = strdup(name); 500 argv[argc] = NULL; 501 502 if (debug) { 503 (void)printf("exec: mount_%s", vfstype); 504 for (i = 1; i < argc; i++) 505 (void)printf(" %s", argv[i]); 506 (void)printf("\n"); 507 return (0); 508 } 509 510 if (use_mountprog(vfstype)) { 511 ret = exec_mountprog(name, execname, argv); 512 } else { 513 ret = mount_fs(vfstype, argc, argv); 514 } 515 516 free(optbuf); 517 518 if (verbose) { 519 if (statfs(name, &sf) < 0) { 520 warn("statfs %s", name); 521 return (1); 522 } 523 if (fstab_style) 524 putfsent(&sf); 525 else 526 prmount(&sf); 527 } 528 529 return (0); 530} 531 532void 533prmount(struct statfs *sfp) 534{ 535 int flags; 536 unsigned int i; 537 struct opt *o; 538 struct passwd *pw; 539 540 (void)printf("%s on %s (%s", sfp->f_mntfromname, sfp->f_mntonname, 541 sfp->f_fstypename); 542 543 flags = sfp->f_flags & MNT_VISFLAGMASK; 544 for (o = optnames; flags && o->o_opt; o++) 545 if (flags & o->o_opt) { 546 (void)printf(", %s", o->o_name); 547 flags &= ~o->o_opt; 548 } 549 /* 550 * Inform when file system is mounted by an unprivileged user 551 * or privileged non-root user. 552 */ 553 if ((flags & MNT_USER) != 0 || sfp->f_owner != 0) { 554 (void)printf(", mounted by "); 555 if ((pw = getpwuid(sfp->f_owner)) != NULL) 556 (void)printf("%s", pw->pw_name); 557 else 558 (void)printf("%d", sfp->f_owner); 559 } 560 if (verbose) { 561 if (sfp->f_syncwrites != 0 || sfp->f_asyncwrites != 0) 562 (void)printf(", writes: sync %ju async %ju", 563 (uintmax_t)sfp->f_syncwrites, 564 (uintmax_t)sfp->f_asyncwrites); 565 if (sfp->f_syncreads != 0 || sfp->f_asyncreads != 0) 566 (void)printf(", reads: sync %ju async %ju", 567 (uintmax_t)sfp->f_syncreads, 568 (uintmax_t)sfp->f_asyncreads); 569 if (sfp->f_fsid.val[0] != 0 || sfp->f_fsid.val[1] != 0) { 570 printf(", fsid "); 571 for (i = 0; i < sizeof(sfp->f_fsid); i++) 572 printf("%02x", ((u_char *)&sfp->f_fsid)[i]); 573 } 574 } 575 (void)printf(")\n"); 576} 577 578struct statfs * 579getmntpt(const char *name) 580{ 581 struct statfs *mntbuf; 582 int i, mntsize; 583 584 mntsize = getmntinfo(&mntbuf, MNT_NOWAIT); 585 for (i = mntsize - 1; i >= 0; i--) { 586 if (strcmp(mntbuf[i].f_mntfromname, name) == 0 || 587 strcmp(mntbuf[i].f_mntonname, name) == 0) 588 return (&mntbuf[i]); 589 } 590 return (NULL); 591} 592 593char * 594catopt(char *s0, const char *s1) 595{ 596 size_t i; 597 char *cp; 598 599 if (s1 == NULL || *s1 == '\0') 600 return s0; 601 602 if (s0 && *s0) { 603 i = strlen(s0) + strlen(s1) + 1 + 1; 604 if ((cp = malloc(i)) == NULL) 605 errx(1, "malloc failed"); 606 (void)snprintf(cp, i, "%s,%s", s0, s1); 607 } else 608 cp = strdup(s1); 609 610 if (s0) 611 free(s0); 612 return (cp); 613} 614 615void 616mangle(options, argcp, argv) 617 char *options; 618 int *argcp; 619 char **argv; 620{ 621 char *p, *s; 622 int argc; 623 624 argc = *argcp; 625 for (s = options; (p = strsep(&s, ",")) != NULL;) 626 if (*p != '\0') { 627 if (strcmp(p, "noauto") == 0) { 628 /* 629 * Do not pass noauto option to nmount(). 630 * or external mount program. noauto is 631 * only used to prevent mounting a filesystem 632 * when 'mount -a' is specified, and is 633 * not a real mount option. 634 */ 635 continue; 636 } else if (*p == '-') { 637 argv[argc++] = p; 638 p = strchr(p, '='); 639 if (p != NULL) { 640 *p = '\0'; 641 argv[argc++] = p+1; 642 } 643 } else if (strcmp(p, "rw") != 0) { 644 argv[argc++] = strdup("-o"); 645 argv[argc++] = p; 646 } 647 } 648 649 *argcp = argc; 650} 651 652 653char * 654update_options(opts, fstab, curflags) 655 char *opts; 656 char *fstab; 657 int curflags; 658{ 659 char *o, *p; 660 char *cur; 661 char *expopt, *newopt, *tmpopt; 662 663 if (opts == NULL) 664 return strdup(""); 665 666 /* remove meta options from list */ 667 remopt(fstab, MOUNT_META_OPTION_FSTAB); 668 remopt(fstab, MOUNT_META_OPTION_CURRENT); 669 cur = flags2opts(curflags); 670 671 /* 672 * Expand all meta-options passed to us first. 673 */ 674 expopt = NULL; 675 for (p = opts; (o = strsep(&p, ",")) != NULL;) { 676 if (strcmp(MOUNT_META_OPTION_FSTAB, o) == 0) 677 expopt = catopt(expopt, fstab); 678 else if (strcmp(MOUNT_META_OPTION_CURRENT, o) == 0) 679 expopt = catopt(expopt, cur); 680 else 681 expopt = catopt(expopt, o); 682 } 683 free(cur); 684 free(opts); 685 686 /* 687 * Remove previous contradictory arguments. Given option "foo" we 688 * remove all the "nofoo" options. Given "nofoo" we remove "nonofoo" 689 * and "foo" - so we can deal with possible options like "notice". 690 */ 691 newopt = NULL; 692 for (p = expopt; (o = strsep(&p, ",")) != NULL;) { 693 if ((tmpopt = malloc( strlen(o) + 2 + 1 )) == NULL) 694 errx(1, "malloc failed"); 695 696 strcpy(tmpopt, "no"); 697 strcat(tmpopt, o); 698 remopt(newopt, tmpopt); 699 free(tmpopt); 700 701 if (strncmp("no", o, 2) == 0) 702 remopt(newopt, o+2); 703 704 newopt = catopt(newopt, o); 705 } 706 free(expopt); 707 708 return newopt; 709} 710 711void 712remopt(string, opt) 713 char *string; 714 const char *opt; 715{ 716 char *o, *p, *r; 717 718 if (string == NULL || *string == '\0' || opt == NULL || *opt == '\0') 719 return; 720 721 r = string; 722 723 for (p = string; (o = strsep(&p, ",")) != NULL;) { 724 if (strcmp(opt, o) != 0) { 725 if (*r == ',' && *o != '\0') 726 r++; 727 while ((*r++ = *o++) != '\0') 728 ; 729 *--r = ','; 730 } 731 } 732 *r = '\0'; 733} 734 735void 736usage() 737{ 738 739 (void)fprintf(stderr, "%s\n%s\n%s\n", 740"usage: mount [-adfpruvw] [-F fstab] [-o options] [-t ufs | external_type]", 741" mount [-dfpruvw] special | node", 742" mount [-dfpruvw] [-o options] [-t ufs | external_type] special node"); 743 exit(1); 744} 745 746void 747putfsent(ent) 748 const struct statfs *ent; 749{ 750 struct fstab *fst; 751 char *opts; 752 753 opts = flags2opts(ent->f_flags); 754 printf("%s\t%s\t%s %s", ent->f_mntfromname, ent->f_mntonname, 755 ent->f_fstypename, opts); 756 free(opts); 757 758 if ((fst = getfsspec(ent->f_mntfromname))) 759 printf("\t%u %u\n", fst->fs_freq, fst->fs_passno); 760 else if ((fst = getfsfile(ent->f_mntonname))) 761 printf("\t%u %u\n", fst->fs_freq, fst->fs_passno); 762 else if (strcmp(ent->f_fstypename, "ufs") == 0) { 763 if (strcmp(ent->f_mntonname, "/") == 0) 764 printf("\t1 1\n"); 765 else 766 printf("\t2 2\n"); 767 } else 768 printf("\t0 0\n"); 769} 770 771 772char * 773flags2opts(flags) 774 int flags; 775{ 776 char *res; 777 778 res = NULL; 779 780 res = catopt(res, (flags & MNT_RDONLY) ? "ro" : "rw"); 781 782 if (flags & MNT_SYNCHRONOUS) res = catopt(res, "sync"); 783 if (flags & MNT_NOEXEC) res = catopt(res, "noexec"); 784 if (flags & MNT_NOSUID) res = catopt(res, "nosuid"); 785 if (flags & MNT_UNION) res = catopt(res, "union"); 786 if (flags & MNT_ASYNC) res = catopt(res, "async"); 787 if (flags & MNT_NOATIME) res = catopt(res, "noatime"); 788 if (flags & MNT_NOCLUSTERR) res = catopt(res, "noclusterr"); 789 if (flags & MNT_NOCLUSTERW) res = catopt(res, "noclusterw"); 790 if (flags & MNT_NOSYMFOLLOW) res = catopt(res, "nosymfollow"); 791 if (flags & MNT_SUIDDIR) res = catopt(res, "suiddir"); 792 if (flags & MNT_MULTILABEL) res = catopt(res, "multilabel"); 793 if (flags & MNT_ACLS) res = catopt(res, "acls"); 794 795 return res; 796} 797