From: Theodore Ts'o Date: Sun, 29 Jun 2008 02:09:43 +0000 (-0400) Subject: blkid: Eliminate stale entries that duplicate a verified device X-Git-Tag: v1.41-WIP-0707~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bf58e3d1c68be63d673d232154bde5854e031afc;p=thirdparty%2Fe2fsprogs.git blkid: Eliminate stale entries that duplicate a verified device Addresses-Debian-Bug: #487758, #487783 Signed-off-by: "Theodore Ts'o" --- diff --git a/lib/blkid/devname.c b/lib/blkid/devname.c index 29cde8e72..df9685990 100644 --- a/lib/blkid/devname.c +++ b/lib/blkid/devname.c @@ -51,7 +51,7 @@ blkid_dev blkid_get_dev(blkid_cache cache, const char *devname, int flags) { blkid_dev dev = NULL, tmp; - struct list_head *p; + struct list_head *p, *pnext; if (!cache || !devname) return NULL; @@ -78,8 +78,42 @@ blkid_dev blkid_get_dev(blkid_cache cache, const char *devname, int flags) cache->bic_flags |= BLKID_BIC_FL_CHANGED; } - if (flags & BLKID_DEV_VERIFY) + if (flags & BLKID_DEV_VERIFY) { dev = blkid_verify(cache, dev); + if (!dev || !(dev->bid_flags & BLKID_BID_FL_VERIFIED)) + return dev; + /* + * If the device is verified, then search the blkid + * cache for any entries that match on the type, uuid, + * and label, and verify them; if a cache entry can + * not be verified, then it's stale and so we remove + * it. + */ + list_for_each_safe(p, pnext, &cache->bic_devs) { + blkid_dev dev2; + if (!p) + break; + dev2 = list_entry(p, struct blkid_struct_dev, bid_devs); + if (dev2->bid_flags & BLKID_BID_FL_VERIFIED) + continue; + if (strcmp(dev->bid_type, dev2->bid_type)) + continue; + if (dev->bid_label && dev2->bid_label && + strcmp(dev->bid_label, dev2->bid_label)) + continue; + if (dev->bid_uuid && dev2->bid_uuid && + strcmp(dev->bid_uuid, dev2->bid_uuid)) + continue; + if ((dev->bid_label && !dev2->bid_label) || + (!dev->bid_label && dev2->bid_label) || + (dev->bid_uuid && !dev2->bid_uuid) || + (!dev->bid_uuid && dev2->bid_uuid)) + continue; + dev2 = blkid_verify(cache, dev2); + if (dev2 && !(dev2->bid_flags & BLKID_BID_FL_VERIFIED)) + blkid_free_dev(dev2); + } + } return dev; }