summaryrefslogtreecommitdiff
path: root/util-linux/umount.c
diff options
context:
space:
mode:
authorDenys Vlasenko2015-10-01 18:50:06 +0200
committerDenys Vlasenko2015-10-01 18:50:06 +0200
commitc919d561adaf152d9b8834475539e2366c8aa484 (patch)
treed01d9fbb3ee8523f47c4b18c409f42ef1537cbf8 /util-linux/umount.c
parentc65a7596df190124abd72d33e2c8c3d2bc8bff80 (diff)
downloadbusybox-c919d561adaf152d9b8834475539e2366c8aa484.zip
busybox-c919d561adaf152d9b8834475539e2366c8aa484.tar.gz
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>
Diffstat (limited to 'util-linux/umount.c')
-rw-r--r--util-linux/umount.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/util-linux/umount.c b/util-linux/umount.c
index 4c2e882..c6c7441 100644
--- a/util-linux/umount.c
+++ b/util-linux/umount.c
@@ -81,8 +81,13 @@ int umount_main(int argc UNUSED_PARAM, char **argv)
argv += optind;
// MNT_FORCE and MNT_DETACH (from linux/fs.h) must match
- // OPT_FORCE and OPT_LAZY, otherwise this trick won't work:
- doForce = MAX((opt & OPT_FORCE), (opt & OPT_LAZY));
+ // OPT_FORCE and OPT_LAZY.
+ {
+ typedef char bug[
+ (OPT_FORCE != MNT_FORCE || OPT_LAZY != MNT_DETACH) ? -1 : 1
+ ];
+ }
+ doForce = opt & (OPT_FORCE|OPT_LAZY);
/* Get a list of mount points from mtab. We read them all in now mostly
* 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)
// umount the directory even if we were given the block device.
if (m) zapit = m->dir;
+// umount from util-linux 2.22.2 does not do this:
+// umount -f uses umount2(MNT_FORCE) immediately,
+// not trying umount() first.
+// (Strangely, umount -fl ignores -f: it is equivalent to umount -l.
+// We do pass both flags in this case)
+#if 0
// Let's ask the thing nicely to unmount.
curstat = umount(zapit);
- // Force the unmount, if necessary.
+ // Unmount with force and/or lazy flags, if necessary.
if (curstat && doForce)
+#endif
curstat = umount2(zapit, doForce);
// If still can't umount, maybe remount read-only?
@@ -168,7 +180,7 @@ int umount_main(int argc UNUSED_PARAM, char **argv)
bb_error_msg(msg, m->device);
} else {
status = EXIT_FAILURE;
- bb_perror_msg("can't %sumount %s", (doForce ? "forcibly " : ""), zapit);
+ bb_perror_msg("can't unmount %s", zapit);
}
} else {
// De-allocate the loop device. This ioctl should be ignored on