diff options
Diffstat (limited to 'mount.c')
-rw-r--r-- | mount.c | 88 |
1 files changed, 56 insertions, 32 deletions
@@ -34,6 +34,13 @@ | |||
34 | * | 34 | * |
35 | * 2000-01-12 Ben Collins <bcollins@debian.org>, Borrowed utils-linux's | 35 | * 2000-01-12 Ben Collins <bcollins@debian.org>, Borrowed utils-linux's |
36 | * mount to add loop support. | 36 | * mount to add loop support. |
37 | * | ||
38 | * 2000-04-30 Dave Cinege <dcinege@psychosis.com> | ||
39 | * Rewrote fstab while loop and lower mount section. Can now do | ||
40 | * single mounts from fstab. Can override fstab options for single | ||
41 | * mount. Common mount_one call for single mounts and 'all'. Fixed | ||
42 | * mtab updating and stale entries. Removed 'remount' default. | ||
43 | * | ||
37 | */ | 44 | */ |
38 | 45 | ||
39 | #include "internal.h" | 46 | #include "internal.h" |
@@ -147,6 +154,7 @@ do_mount(char *specialfile, char *dir, char *filesystemtype, | |||
147 | 154 | ||
148 | #if defined BB_MTAB | 155 | #if defined BB_MTAB |
149 | if (useMtab == TRUE) { | 156 | if (useMtab == TRUE) { |
157 | erase_mtab(specialfile); // Clean any stale entries | ||
150 | write_mtab(specialfile, dir, filesystemtype, flags, mtab_opts); | 158 | write_mtab(specialfile, dir, filesystemtype, flags, mtab_opts); |
151 | } | 159 | } |
152 | #endif | 160 | #endif |
@@ -318,6 +326,8 @@ extern int mount_main(int argc, char **argv) | |||
318 | int fakeIt = FALSE; | 326 | int fakeIt = FALSE; |
319 | int useMtab = TRUE; | 327 | int useMtab = TRUE; |
320 | int i; | 328 | int i; |
329 | int rc = FALSE; | ||
330 | int fstabmount = FALSE; | ||
321 | 331 | ||
322 | #if defined BB_FEATURE_USE_DEVPS_PATCH | 332 | #if defined BB_FEATURE_USE_DEVPS_PATCH |
323 | if (argc == 1) { | 333 | if (argc == 1) { |
@@ -435,56 +445,70 @@ extern int mount_main(int argc, char **argv) | |||
435 | argv++; | 445 | argv++; |
436 | } | 446 | } |
437 | 447 | ||
438 | if (all == TRUE) { | 448 | if (all == TRUE || directory == NULL) { |
439 | struct mntent *m; | 449 | struct mntent *m; |
440 | FILE *f = setmntent("/etc/fstab", "r"); | 450 | FILE *f = setmntent("/etc/fstab", "r"); |
451 | fstabmount = TRUE; | ||
441 | 452 | ||
442 | if (f == NULL) | 453 | if (f == NULL) |
443 | fatalError( "\nCannot read /etc/fstab: %s\n", strerror (errno)); | 454 | fatalError( "\nCannot read /etc/fstab: %s\n", strerror (errno)); |
444 | 455 | ||
445 | while ((m = getmntent(f)) != NULL) { | 456 | while ((m = getmntent(f)) != NULL) { |
446 | // If the filesystem isn't noauto, | 457 | if (all == FALSE && directory == NULL && ( |
447 | // and isn't swap or nfs, then mount it | 458 | (strcmp(device, m->mnt_fsname) != 0) && |
448 | if ((!strstr(m->mnt_opts, "noauto")) && | 459 | (strcmp(device, m->mnt_dir) != 0) ) ) { |
449 | (!strstr(m->mnt_type, "swap")) && | 460 | continue; |
450 | (!strstr(m->mnt_type, "nfs"))) { | 461 | } |
462 | |||
463 | if (all == TRUE && ( // If we're mounting 'all' | ||
464 | (strstr(m->mnt_opts, "noauto")) || // and the file system isn't noauto, | ||
465 | (strstr(m->mnt_type, "swap")) || // and isn't swap or nfs, then mount it | ||
466 | (strstr(m->mnt_type, "nfs")) ) ) { | ||
467 | continue; | ||
468 | } | ||
469 | |||
470 | if (all == TRUE || flags == 0) { // Allow single mount to override fstab flags | ||
451 | flags = 0; | 471 | flags = 0; |
452 | *string_flags = '\0'; | 472 | *string_flags = '\0'; |
453 | parse_mount_options(m->mnt_opts, &flags, string_flags); | 473 | parse_mount_options(m->mnt_opts, &flags, string_flags); |
454 | if (mount_one(m->mnt_fsname, m->mnt_dir, m->mnt_type, | ||
455 | flags, string_flags, useMtab, fakeIt, | ||
456 | extra_opts, FALSE)==FALSE) | ||
457 | { | ||
458 | /* Try again, but this time try a remount */ | ||
459 | mount_one(m->mnt_fsname, m->mnt_dir, m->mnt_type, | ||
460 | flags|MS_REMOUNT, string_flags, useMtab, fakeIt, | ||
461 | extra_opts, TRUE); | ||
462 | } | ||
463 | } | 474 | } |
464 | } | 475 | |
465 | endmntent(f); | 476 | device = strdup(m->mnt_fsname); |
466 | } else { | 477 | directory = strdup(m->mnt_dir); |
467 | if (device && directory) { | 478 | filesystemType = strdup(m->mnt_type); |
479 | singlemount: | ||
468 | #ifdef BB_NFSMOUNT | 480 | #ifdef BB_NFSMOUNT |
469 | if (strchr(device, ':') != NULL) | 481 | if (strchr(device, ':') != NULL) |
470 | filesystemType = "nfs"; | 482 | filesystemType = "nfs"; |
471 | if (strcmp(filesystemType, "nfs") == 0) { | 483 | if (strcmp(filesystemType, "nfs") == 0) { |
472 | int ret; | 484 | rc = nfsmount (device, directory, &flags, &extra_opts, &string_flags, 1) |
473 | ret = nfsmount (device, directory, &flags, | 485 | if ( rc != 0) { |
474 | &extra_opts, &string_flags, 1); | 486 | fatalError("nfsmount failed: %s\n", strerror(errno)); |
475 | if (ret != 0) | 487 | rc = FALSE; |
476 | fatalError("nfsmount failed: %s\n", strerror(errno)); | 488 | } |
477 | } | 489 | } else |
478 | #endif | 490 | #endif |
479 | exit(mount_one(device, directory, filesystemType, | 491 | rc = mount_one(device, directory, filesystemType, flags, |
480 | flags, string_flags, useMtab, fakeIt, | 492 | string_flags, useMtab, fakeIt, extra_opts, TRUE); |
481 | extra_opts, TRUE)); | 493 | |
482 | } else { | 494 | if (all == FALSE) |
483 | goto goodbye; | 495 | break; |
496 | |||
497 | rc = TRUE; // Always return 0 for 'all' | ||
484 | } | 498 | } |
499 | if (fstabmount == TRUE) | ||
500 | endmntent(f); | ||
501 | |||
502 | if (all == FALSE && fstabmount == TRUE && directory == NULL) | ||
503 | fprintf(stderr, "Can't find %s in /etc/fstab\n", device); | ||
504 | |||
505 | exit(rc); | ||
485 | } | 506 | } |
486 | exit(TRUE); | 507 | |
508 | goto singlemount; | ||
509 | |||
510 | exit(FALSE); | ||
487 | 511 | ||
488 | goodbye: | 512 | goodbye: |
489 | usage(mount_usage); | 513 | usage(mount_usage); |
490 | } | 514 | } |