mount.c (151043) | mount.c (152344) |
---|---|
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 --- 24 unchanged lines hidden (view full) --- 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[] = | 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 --- 24 unchanged lines hidden (view full) --- 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 151043 2005-10-07 02:22:04Z rodrigc $"; | 41 "$FreeBSD: head/sbin/mount/mount.c 152344 2005-11-12 20:12:56Z 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> --- 19 unchanged lines hidden (view full) --- 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 *); | 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> --- 19 unchanged lines hidden (view full) --- 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 **); | 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); --- 29 unchanged lines hidden (view full) --- 115 * XXX Is this list correct? 116 */ 117static const char * 118remountable_fs_names[] = { 119 "ufs", "ffs", "ext2fs", 120 0 121}; 122 | 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); --- 29 unchanged lines hidden (view full) --- 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 |
|
123int 124main(int argc, char *argv[]) 125{ 126 const char *mntfromname, **vfslist, *vfstype; 127 struct fstab *fs; 128 struct statfs *mntbuf; 129 FILE *mountdfp; 130 pid_t pid; --- 247 unchanged lines hidden (view full) --- 378 free(optbuf); 379 return (found); 380} 381 382int 383mountfs(const char *vfstype, const char *spec, const char *name, int flags, 384 const char *options, const char *mntopts) 385{ | 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; --- 247 unchanged lines hidden (view full) --- 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{ |
386 const char *argv[100]; | 447 char *argv[100]; |
387 struct statfs sf; | 448 struct statfs sf; |
388 pid_t pid; 389 int argc, i, status; | 449 int argc, i, ret; |
390 char *optbuf, execname[PATH_MAX], mntpath[PATH_MAX]; 391 392#if __GNUC__ 393 (void)&optbuf; 394 (void)&name; 395#endif 396 397 /* resolve the mountpoint with realpath(3) */ --- 32 unchanged lines hidden (view full) --- 430 vfstype = "msdosfs"; 431 432 /* Construct the name of the appropriate mount command */ 433 (void)snprintf(execname, sizeof(execname), "mount_%s", vfstype); 434 435 argc = 0; 436 argv[argc++] = execname; 437 mangle(optbuf, &argc, argv); | 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) */ --- 32 unchanged lines hidden (view full) --- 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); |
438 argv[argc++] = spec; 439 argv[argc++] = name; | 498 argv[argc++] = strdup(spec); 499 argv[argc++] = strdup(name); |
440 argv[argc] = NULL; 441 442 if (debug) { 443 (void)printf("exec: mount_%s", vfstype); 444 for (i = 1; i < argc; i++) 445 (void)printf(" %s", argv[i]); 446 (void)printf("\n"); 447 return (0); 448 } 449 | 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 |
450 switch (pid = fork()) { 451 case -1: /* Error. */ 452 warn("fork"); 453 free(optbuf); 454 return (1); 455 case 0: /* Child. */ 456 if (strcmp(vfstype, "ufs") == 0) 457 exit(mount_ufs(argc, (char * const *) argv)); | 510 if (strcmp(vfstype, "ufs")==0) { 511 ret = mount_ufs(argc, argv); 512 } else if (use_mountprog(vfstype)) { 513 ret = exec_mountprog(name, execname, argv); 514 } else { 515 ret = mount_fs(vfstype, argc, argv); 516 } |
458 | 517 |
459 /* Go find an executable. */ 460 execvP(execname, _PATH_SYSPATH, (char * const *)argv); 461 if (errno == ENOENT) { 462 warn("exec mount_%s not found in %s", vfstype, 463 _PATH_SYSPATH); 464 } 465 exit(1); 466 /* NOTREACHED */ 467 default: /* Parent. */ 468 free(optbuf); | 518 free(optbuf); |
469 | 519 |
470 if (waitpid(pid, &status, 0) < 0) { 471 warn("waitpid"); | 520 if (verbose) { 521 if (statfs(name, &sf) < 0) { 522 warn("statfs %s", name); |
472 return (1); 473 } | 523 return (1); 524 } |
474 475 if (WIFEXITED(status)) { 476 if (WEXITSTATUS(status) != 0) 477 return (WEXITSTATUS(status)); 478 } else if (WIFSIGNALED(status)) { 479 warnx("%s: %s", name, sys_siglist[WTERMSIG(status)]); 480 return (1); 481 } 482 483 if (verbose) { 484 if (statfs(name, &sf) < 0) { 485 warn("statfs %s", name); 486 return (1); 487 } 488 if (fstab_style) 489 putfsent(&sf); 490 else 491 prmount(&sf); 492 } 493 break; | 525 if (fstab_style) 526 putfsent(&sf); 527 else 528 prmount(&sf); |
494 } 495 496 return (0); 497} 498 499void 500prmount(struct statfs *sfp) 501{ --- 76 unchanged lines hidden (view full) --- 578 free(s0); 579 return (cp); 580} 581 582void 583mangle(options, argcp, argv) 584 char *options; 585 int *argcp; | 529 } 530 531 return (0); 532} 533 534void 535prmount(struct statfs *sfp) 536{ --- 76 unchanged lines hidden (view full) --- 613 free(s0); 614 return (cp); 615} 616 617void 618mangle(options, argcp, argv) 619 char *options; 620 int *argcp; |
586 const char **argv; | 621 char **argv; |
587{ 588 char *p, *s; 589 int argc; 590 591 argc = *argcp; 592 for (s = options; (p = strsep(&s, ",")) != NULL;) 593 if (*p != '\0') { 594 if (*p == '-') { 595 argv[argc++] = p; 596 p = strchr(p, '='); 597 if (p != NULL) { 598 *p = '\0'; 599 argv[argc++] = p+1; 600 } 601 } else if (strcmp(p, "rw") != 0) { | 622{ 623 char *p, *s; 624 int argc; 625 626 argc = *argcp; 627 for (s = options; (p = strsep(&s, ",")) != NULL;) 628 if (*p != '\0') { 629 if (*p == '-') { 630 argv[argc++] = p; 631 p = strchr(p, '='); 632 if (p != NULL) { 633 *p = '\0'; 634 argv[argc++] = p+1; 635 } 636 } else if (strcmp(p, "rw") != 0) { |
602 argv[argc++] = "-o"; | 637 argv[argc++] = strdup("-o"); |
603 argv[argc++] = p; 604 } 605 } 606 607 *argcp = argc; 608} 609 610 --- 144 unchanged lines hidden --- | 638 argv[argc++] = p; 639 } 640 } 641 642 *argcp = argc; 643} 644 645 --- 144 unchanged lines hidden --- |