diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2015-10-01 18:50:06 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2015-10-01 18:50:06 +0200 |
commit | c919d561adaf152d9b8834475539e2366c8aa484 (patch) | |
tree | d01d9fbb3ee8523f47c4b18c409f42ef1537cbf8 | |
parent | c65a7596df190124abd72d33e2c8c3d2bc8bff80 (diff) | |
download | busybox-w32-c919d561adaf152d9b8834475539e2366c8aa484.tar.gz busybox-w32-c919d561adaf152d9b8834475539e2366c8aa484.tar.bz2 busybox-w32-c919d561adaf152d9b8834475539e2366c8aa484.zip |
umount: always use umount2 syscall with specified flags
Make umount -f more compatible with util-linux 2.22.2.
Before:
* 'umount -f': calls umount syscall,
if it fails calls umount2 with 'MNT_FORCE'
* 'mount -f -l': calls umount syscall,
if it fails calls umount2 with 'MNT_LAZY'. 'MNT_FORCE' dropped
After:
* 'umount -f': calls umount2 syscall with 'MNT_FORCE'
* 'mount -f -l': calls umount2 syscall with 'MNT_LAZY' and 'MNT_FORCE'
function old new delta
umount 45 - -45
umount_main 610 555 -55
Signed-off-by: Anton Bondarenko <anton.bondarenko@axis.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | util-linux/umount.c | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/util-linux/umount.c b/util-linux/umount.c index 4c2e8821e..c6c7441b8 100644 --- a/util-linux/umount.c +++ b/util-linux/umount.c | |||
@@ -81,8 +81,13 @@ int umount_main(int argc UNUSED_PARAM, char **argv) | |||
81 | argv += optind; | 81 | argv += optind; |
82 | 82 | ||
83 | // MNT_FORCE and MNT_DETACH (from linux/fs.h) must match | 83 | // MNT_FORCE and MNT_DETACH (from linux/fs.h) must match |
84 | // OPT_FORCE and OPT_LAZY, otherwise this trick won't work: | 84 | // OPT_FORCE and OPT_LAZY. |
85 | doForce = MAX((opt & OPT_FORCE), (opt & OPT_LAZY)); | 85 | { |
86 | typedef char bug[ | ||
87 | (OPT_FORCE != MNT_FORCE || OPT_LAZY != MNT_DETACH) ? -1 : 1 | ||
88 | ]; | ||
89 | } | ||
90 | doForce = opt & (OPT_FORCE|OPT_LAZY); | ||
86 | 91 | ||
87 | /* Get a list of mount points from mtab. We read them all in now mostly | 92 | /* Get a list of mount points from mtab. We read them all in now mostly |
88 | * for umount -a (so we don't have to worry about the list changing while | 93 | * for umount -a (so we don't have to worry about the list changing while |
@@ -147,11 +152,18 @@ int umount_main(int argc UNUSED_PARAM, char **argv) | |||
147 | // umount the directory even if we were given the block device. | 152 | // umount the directory even if we were given the block device. |
148 | if (m) zapit = m->dir; | 153 | if (m) zapit = m->dir; |
149 | 154 | ||
155 | // umount from util-linux 2.22.2 does not do this: | ||
156 | // umount -f uses umount2(MNT_FORCE) immediately, | ||
157 | // not trying umount() first. | ||
158 | // (Strangely, umount -fl ignores -f: it is equivalent to umount -l. | ||
159 | // We do pass both flags in this case) | ||
160 | #if 0 | ||
150 | // Let's ask the thing nicely to unmount. | 161 | // Let's ask the thing nicely to unmount. |
151 | curstat = umount(zapit); | 162 | curstat = umount(zapit); |
152 | 163 | ||
153 | // Force the unmount, if necessary. | 164 | // Unmount with force and/or lazy flags, if necessary. |
154 | if (curstat && doForce) | 165 | if (curstat && doForce) |
166 | #endif | ||
155 | curstat = umount2(zapit, doForce); | 167 | curstat = umount2(zapit, doForce); |
156 | 168 | ||
157 | // If still can't umount, maybe remount read-only? | 169 | // If still can't umount, maybe remount read-only? |
@@ -168,7 +180,7 @@ int umount_main(int argc UNUSED_PARAM, char **argv) | |||
168 | bb_error_msg(msg, m->device); | 180 | bb_error_msg(msg, m->device); |
169 | } else { | 181 | } else { |
170 | status = EXIT_FAILURE; | 182 | status = EXIT_FAILURE; |
171 | bb_perror_msg("can't %sumount %s", (doForce ? "forcibly " : ""), zapit); | 183 | bb_perror_msg("can't unmount %s", zapit); |
172 | } | 184 | } |
173 | } else { | 185 | } else { |
174 | // De-allocate the loop device. This ioctl should be ignored on | 186 | // De-allocate the loop device. This ioctl should be ignored on |