From: Karel Zak Date: Tue, 6 Jan 2009 23:18:41 +0000 (+0100) Subject: umount: cleanup gefs_by_specdir() X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=448d12483cc24cd1ba50fde6b95d4c0f5080f038;p=util-linux umount: cleanup gefs_by_specdir() fix: - don't call canonicalize_spec() for LABELs/UUIDs - simplify the code - rename to getfs_by_devdir(), because we use it only for device names and not for SPECes (see umount.c). Signed-off-by: Karel Zak --- diff --git a/mount/fstab.c b/mount/fstab.c index 8e7019a5..c60c5f4d 100644 --- a/mount/fstab.c +++ b/mount/fstab.c @@ -326,46 +326,39 @@ has_uuid(const char *device, const char *uuid){ return ret; } -/* Find the entry (SPEC,DIR) in fstab -- spec and dir must be canonicalized! */ +/* Find the entry (DEV,DIR) in fstab -- spec and dir must be canonicalized! */ struct mntentchn * -getfs_by_specdir (const char *spec, const char *dir) { +getfs_by_devdir (const char *dev, const char *dir) { struct mntentchn *mc, *mc0; mc0 = fstab_head(); for (mc = mc0->nxt; mc && mc != mc0; mc = mc->nxt) { + int ok = 1; + /* dir */ if (!streq(mc->m.mnt_dir, dir)) { char *dr = canonicalize(mc->m.mnt_dir); - int ok = 0; - - if (streq(dr, dir)) - ok = 1; - free(dr); - if (!ok) - continue; + ok = streq(dr, dir); + my_free(dr); } /* spec */ - if (!streq(mc->m.mnt_fsname, spec)) { - char *fs = canonicalize_spec(mc->m.mnt_fsname); - int ok = 0; - - if (streq(fs, spec)) - ok = 1; - else if (strncmp (fs, "LABEL=", 6) == 0) { - if (has_label(spec, fs + 6)) - ok = 1; - } - else if (strncmp (fs, "UUID=", 5) == 0) { - if (has_uuid(spec, fs + 5)) - ok = 1; + if (ok && !streq(mc->m.mnt_fsname, dev)) { + const char *fs = mc->m.mnt_fsname; + + if (strncmp (fs, "LABEL=", 6) == 0) { + ok = has_label(dev, fs + 6); + } else if (strncmp (fs, "UUID=", 5) == 0) { + ok = has_uuid(dev, fs + 5); + } else { + fs = canonicalize_spec(mc->m.mnt_fsname); + ok = streq(fs, dev); + my_free(fs); } - free(fs); - if (!ok) - continue; } - return mc; + if (ok) + return mc; } return NULL; diff --git a/mount/fstab.h b/mount/fstab.h index 14b24c45..8fc8fd41 100644 --- a/mount/fstab.h +++ b/mount/fstab.h @@ -22,7 +22,7 @@ struct mntentchn *fstab_head (void); struct mntentchn *getfs_by_dir (const char *dir); struct mntentchn *getfs_by_spec (const char *spec); struct mntentchn *getfs_by_devname (const char *devname); -struct mntentchn *getfs_by_specdir (const char *spec, const char *dir); +struct mntentchn *getfs_by_devdir (const char *dev, const char *dir); struct mntentchn *getfs_by_uuid (const char *uuid); struct mntentchn *getfs_by_label (const char *label); diff --git a/mount/umount.c b/mount/umount.c index 81f8bdf1..00745aed 100644 --- a/mount/umount.c +++ b/mount/umount.c @@ -514,8 +514,8 @@ umount_file (char *arg) { /dev/sda4 /mnt/zip auto user,noauto 0 0 then "mount /dev/sda4" followed by "umount /mnt/zip" used to fail. So, we must not look for file, but for - the pair (spec,file) in fstab. */ - fs = getfs_by_specdir(mc->m.mnt_fsname, mc->m.mnt_dir); + the pair (dev,file) in fstab. */ + fs = getfs_by_devdir(mc->m.mnt_fsname, mc->m.mnt_dir); if (!fs) { if (!getfs_by_spec (file) && !getfs_by_dir (file)) die (2,