diff options
Diffstat (limited to 'util-linux')
| -rw-r--r-- | util-linux/Config.in | 7 | ||||
| -rw-r--r-- | util-linux/umount.c | 55 |
2 files changed, 35 insertions, 27 deletions
diff --git a/util-linux/Config.in b/util-linux/Config.in index 76e9ff97f..fbcf62476 100644 --- a/util-linux/Config.in +++ b/util-linux/Config.in | |||
| @@ -393,6 +393,13 @@ config CONFIG_UMOUNT | |||
| 393 | the tool to use. If you enabled the 'mount' utility, you almost certainly | 393 | the tool to use. If you enabled the 'mount' utility, you almost certainly |
| 394 | also want to enable 'umount'. | 394 | also want to enable 'umount'. |
| 395 | 395 | ||
| 396 | config CONFIG_FEATURE_UMOUNT_ALL | ||
| 397 | bool " umount -a option" | ||
| 398 | default n | ||
| 399 | depends on CONFIG_UMOUNT | ||
| 400 | help | ||
| 401 | Support -a option to unmount all currently mounted filesystems. | ||
| 402 | |||
| 396 | comment "Common options for mount/umount" | 403 | comment "Common options for mount/umount" |
| 397 | depends on CONFIG_MOUNT || CONFIG_UMOUNT | 404 | depends on CONFIG_MOUNT || CONFIG_UMOUNT |
| 398 | 405 | ||
diff --git a/util-linux/umount.c b/util-linux/umount.c index 14ff41588..8c0558466 100644 --- a/util-linux/umount.c +++ b/util-linux/umount.c | |||
| @@ -21,15 +21,14 @@ | |||
| 21 | #include <getopt.h> | 21 | #include <getopt.h> |
| 22 | #include "busybox.h" | 22 | #include "busybox.h" |
| 23 | 23 | ||
| 24 | #define OPTION_STRING "flaDnrv" | 24 | #define OPTION_STRING "flDnrva" |
| 25 | #define OPT_FORCE 1 | 25 | #define OPT_FORCE 1 |
| 26 | #define OPT_LAZY 2 | 26 | #define OPT_LAZY 2 |
| 27 | #define OPT_ALL 4 | 27 | #define OPT_DONTFREELOOP 4 |
| 28 | #define OPT_DONTFREELOOP 8 | 28 | #define OPT_NO_MTAB 8 |
| 29 | #define OPT_NO_MTAB 16 | 29 | #define OPT_REMOUNT 16 |
| 30 | #define OPT_REMOUNT 32 | 30 | #define OPT_IGNORED 32 // -v is ignored |
| 31 | /* -v is ignored */ | 31 | #define OPT_ALL (ENABLE_FEATURE_UMOUNT_ALL ? 64 : 0) |
| 32 | |||
| 33 | 32 | ||
| 34 | extern int umount_main(int argc, char **argv) | 33 | extern int umount_main(int argc, char **argv) |
| 35 | { | 34 | { |
| @@ -61,24 +60,25 @@ extern int umount_main(int argc, char **argv) | |||
| 61 | * umounts the most recent entries first. */ | 60 | * umounts the most recent entries first. */ |
| 62 | 61 | ||
| 63 | m=mtl=0; | 62 | m=mtl=0; |
| 64 | if(!(fp = setmntent(bb_path_mtab_file, "r"))) | 63 | if(opt & OPT_ALL) { |
| 65 | bb_error_msg_and_die("Cannot open %s", bb_path_mtab_file); | 64 | |
| 66 | while (getmntent_r(fp,&me,path,sizeof(path))) { | 65 | /* If we're umounting all, then m points to the start of the list and |
| 67 | m=xmalloc(sizeof(struct mtab_list)); | 66 | * the argument list should be empty (which will match all). */ |
| 68 | m->next=mtl; | 67 | |
| 69 | m->device=bb_xstrdup(me.mnt_fsname); | 68 | if(!(fp = setmntent(bb_path_mtab_file, "r"))) |
| 70 | m->dir=bb_xstrdup(me.mnt_dir); | 69 | bb_error_msg_and_die("Cannot open %s", bb_path_mtab_file); |
| 71 | mtl=m; | 70 | while (getmntent_r(fp,&me,path,sizeof(path))) { |
| 72 | } | 71 | m=xmalloc(sizeof(struct mtab_list)); |
| 73 | endmntent(fp); | 72 | m->next=mtl; |
| 74 | 73 | m->device=bb_xstrdup(me.mnt_fsname); | |
| 75 | /* If we're umounting all, then m points to the start of the list and | 74 | m->dir=bb_xstrdup(me.mnt_dir); |
| 76 | * the argument list should be empty (which will match all). */ | 75 | mtl=m; |
| 77 | if(!(opt & OPT_ALL)) { | 76 | } |
| 78 | m=0; | 77 | endmntent(fp); |
| 79 | if(argc <= 0) bb_show_usage(); | ||
| 80 | } | ||
| 81 | 78 | ||
| 79 | /* If we're not mounting all, we need at least one argument. */ | ||
| 80 | } else if(argc <= 0) bb_show_usage(); | ||
| 81 | |||
| 82 | // Loop through everything we're supposed to umount, and do so. | 82 | // Loop through everything we're supposed to umount, and do so. |
| 83 | for(;;) { | 83 | for(;;) { |
| 84 | int curstat; | 84 | int curstat; |
| @@ -92,9 +92,10 @@ extern int umount_main(int argc, char **argv) | |||
| 92 | else { | 92 | else { |
| 93 | // Get next command line argument (and look it up in mtab list) | 93 | // Get next command line argument (and look it up in mtab list) |
| 94 | realpath(*argv++, path); | 94 | realpath(*argv++, path); |
| 95 | for(m = mtl; m; m = m->next) | 95 | if (ENABLE_FEATURE_MTAB_SUPPORT) |
| 96 | if(!strcmp(path, m->dir) || !strcmp(path, m->device)) | 96 | for(m = mtl; m; m = m->next) |
| 97 | break; | 97 | if(!strcmp(path, m->dir) || !strcmp(path, m->device)) |
| 98 | break; | ||
| 98 | } | 99 | } |
| 99 | 100 | ||
| 100 | // Let's ask the thing nicely to unmount. | 101 | // Let's ask the thing nicely to unmount. |
