From 2afb8cb37af32495e4f4ff9188e21cbe3a44ce6c Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Fri, 16 Mar 2007 16:02:22 +0100 Subject: pick actual valid device in udev_db_lookup_name --- udev_db.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/udev_db.c b/udev_db.c index 5ac016a051..728d74a030 100644 --- a/udev_db.c +++ b/udev_db.c @@ -275,8 +275,7 @@ int udev_db_lookup_name(const char *name, char *devpath, size_t len) while (!found) { struct dirent *ent; char device[PATH_SIZE]; - char filename[PATH_SIZE]; - struct stat statbuf; + struct udevice *udev; ent = readdir(dir); if (ent == NULL || ent->d_name[0] == '\0') @@ -286,15 +285,27 @@ int udev_db_lookup_name(const char *name, char *devpath, size_t len) strlcpy(device, ent->d_name, sizeof(device)); path_decode(device); - - dbg("looking at '%s'", device); - strlcpy(filename, sysfs_path, sizeof(filename)); - strlcat(filename, device, sizeof(filename)); - if (stat(filename, &statbuf) == 0) { - strlcpy(devpath, device, len); - found = 1; + udev = udev_device_init(); + if (udev == NULL) break; + if (udev_db_get_device(udev, device) == 0) { + char filename[PATH_SIZE]; + struct stat statbuf; + + info("found db entry '%s'", device); + strlcpy(filename, udev_root, sizeof(filename)); + strlcat(filename, "/", sizeof(filename)); + strlcat(filename, name, sizeof(filename)); + /* make sure device entry matches dev_t */ + if (stat(filename, &statbuf) == 0) { + if (statbuf.st_rdev == udev->devt) { + info("node '%s' matches dev_t", udev->name); + strlcpy(devpath, device, len); + found = 1; + } + } } + udev_device_cleanup(udev); } closedir(dir); -- cgit v1.2.3-54-g00ecf