Changeset 902 in MondoRescue for branches/stable/mindi-busybox/util-linux/umount.c
- Timestamp:
- Oct 25, 2006, 12:41:23 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/stable/mindi-busybox/util-linux/umount.c
r821 r902 15 15 #include <mntent.h> 16 16 #include <errno.h> 17 #include <string.h>18 17 #include <getopt.h> 19 18 20 #define OPTION_STRING "flDnr vad"19 #define OPTION_STRING "flDnravd" 21 20 #define OPT_FORCE 1 22 21 #define OPT_LAZY 2 … … 24 23 #define OPT_NO_MTAB 8 25 24 #define OPT_REMOUNT 16 26 #define OPT_IGNORED 32 // -v is ignored 27 #define OPT_ALL (ENABLE_FEATURE_UMOUNT_ALL ? 64 : 0) 25 #define OPT_ALL (ENABLE_FEATURE_UMOUNT_ALL ? 32 : 0) 28 26 29 27 int umount_main(int argc, char **argv) … … 78 76 if (!argc) bb_show_usage(); 79 77 } 80 81 82 78 83 79 // Loop through everything we're supposed to umount, and do so. 84 80 for (;;) { 85 81 int curstat; 82 char *zapit = *argv; 86 83 87 84 // Do we already know what to umount this time through the loop? … … 92 89 else if (!argc--) break; 93 90 else { 94 realpath(*argv++, path); 91 argv++; 92 realpath(zapit, path); 95 93 for (m = mtl; m; m = m->next) 96 94 if (!strcmp(path, m->dir) || !strcmp(path, m->device)) 97 95 break; 98 96 } 97 // If we couldn't find this sucker in /etc/mtab, punt by passing our 98 // command line argument straight to the umount syscall. Otherwise, 99 // umount the directory even if we were given the block device. 100 if (m) zapit = m->dir; 99 101 100 102 // Let's ask the thing nicely to unmount. 101 curstat = umount( path);103 curstat = umount(zapit); 102 104 103 105 // Force the unmount, if necessary. 104 106 if (curstat && doForce) { 105 curstat = umount2( path, doForce);107 curstat = umount2(zapit, doForce); 106 108 if (curstat) 107 bb_error_msg_and_die("forced umount of %s failed!", path);109 bb_error_msg_and_die("forced umount of %s failed!", zapit); 108 110 } 109 111 110 112 // If still can't umount, maybe remount read-only? 111 113 if (curstat && (opt & OPT_REMOUNT) && errno == EBUSY && m) { 112 curstat = mount(m->device, path, NULL, MS_REMOUNT|MS_RDONLY, NULL);114 curstat = mount(m->device, zapit, NULL, MS_REMOUNT|MS_RDONLY, NULL); 113 115 bb_error_msg(curstat ? "Cannot remount %s read-only" : 114 116 "%s busy - remounted read-only", m->device); 115 117 } 116 118 117 /* De-allocate the loop device. This ioctl should be ignored on any 118 * non-loop block devices. */ 119 if (ENABLE_FEATURE_MOUNT_LOOP && !(opt & OPT_DONTFREELOOP) && m) 120 del_loop(m->device); 119 if (curstat) { 120 status = EXIT_FAILURE; 121 bb_perror_msg("Couldn't umount %s", zapit); 122 } else { 123 /* De-allocate the loop device. This ioctl should be ignored on 124 * any non-loop block devices. */ 125 if (ENABLE_FEATURE_MOUNT_LOOP && !(opt & OPT_DONTFREELOOP) && m) 126 del_loop(m->device); 127 if (ENABLE_FEATURE_MTAB_SUPPORT && !(opt & OPT_NO_MTAB) && m) 128 erase_mtab(m->dir); 129 } 121 130 122 if (curstat) {123 /* Yes, the ENABLE is redundant here, but the optimizer for ARM124 * can't do simple constant propagation in local variables... */125 if(ENABLE_FEATURE_MTAB_SUPPORT && !(opt & OPT_NO_MTAB) && m)126 erase_mtab(m->dir);127 status = EXIT_FAILURE;128 bb_perror_msg("Couldn't umount %s", path);129 }130 131 // Find next matching mtab entry for -a or umount /dev 132 // Note this means that "umount /dev/blah" will unmount all instances 133 // of /dev/blah, not just the most recent. 131 134 while (m && (m = m->next)) 132 135 if ((opt & OPT_ALL) || !strcmp(path,m->device))
Note:
See TracChangeset
for help on using the changeset viewer.