Index: util-linux-ng-2.14.2/mount/umount.c =================================================================== --- util-linux-ng-2.14.2.orig/mount/umount.c 2009-02-11 17:00:35.000000000 +0100 +++ util-linux-ng-2.14.2/mount/umount.c 2009-02-12 13:09:44.000000000 +0100 @@ -465,6 +465,42 @@ get_value(const char *list, const char * return 0; } +#define LOOP_DEV_PATH "/dev/loop" +/* check if mc contains a loop device which is associated + * with the file in fs + */ +static int +valid_loop(struct mntentchn *mc, struct mntentchn *fs) +{ + unsigned long long offset=0; + char *p; + + /* 1. check if it begins with /dev/loop */ + if (strncmp(LOOP_DEV_PATH, mc->m.mnt_fsname, sizeof(LOOP_DEV_PATH)-1) != 0) + return 0; + + /* 2. check for loop option in fstab */ + if (!contains(fs->m.mnt_opts, "loop")) + return 0; + + /* 3. check for offset option in fstab */ + if (p=get_value(fs->m.mnt_opts, "offset=")) + offset = strtoull(p, NULL, 10); + + /* 4. check association */ + if (loopfile_used_with(mc->m.mnt_fsname, fs->m.mnt_fsname, offset)) { + if (verbose > 1) + printf(_("device %s is associated with %s\n"), + mc->m.mnt_fsname, fs->m.mnt_fsname); + return 1; + } else { + if (verbose > 1) + printf(_("device %s is not associated with %s\n"), + mc->m.mnt_fsname, fs->m.mnt_fsname); + return 0; + } +} + static int umount_file (char *arg) { struct mntentchn *mc, *fs; @@ -530,14 +566,18 @@ umount_file (char *arg) { the pair (spec,file) in fstab. */ fs = getfs_by_specdir(mc->m.mnt_fsname, mc->m.mnt_dir); if (!fs) { - if (!getfs_by_spec (file) && !getfs_by_dir (file)) + fs = getfs_by_dir(file); + if (!getfs_by_spec (file) && !fs) die (2, _("umount: %s is not in the fstab " "(and you are not root)"), file); - else + + /* spec could be a file which is loop mounted */ + if (fs && !valid_loop(mc, fs)) die (2, _("umount: %s mount disagrees with " "the fstab"), file); + } /*