From: kay.sievers@vrfy.org Date: Fri, 25 Feb 2005 06:40:14 +0000 (+0100) Subject: [PATCH] udevinfo: print devpath -> node relationship for all devices X-Git-Tag: 054~4 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=9fe1a96d88b304af5f3315197800f6b3d16675e1;hp=f8a178a35b8dee2ee46a3de298345aa4faa8f41e;p=elogind.git [PATCH] udevinfo: print devpath -> node relationship for all devices --- diff --git a/udev_db.c b/udev_db.c index 61d4b130d..4515998fc 100644 --- a/udev_db.c +++ b/udev_db.c @@ -239,3 +239,38 @@ found: return 0; } + +int udev_db_call_foreach(int (*handler_function)(struct udevice *udev)) +{ + struct dirent *ent; + DIR *dir; + char filename[NAME_SIZE]; + struct udevice db_udev; + + dir = opendir(udev_db_path); + if (dir == NULL) { + dbg("unable to udev db '%s'", udev_db_path); + return -1; + } + + while (1) { + ent = readdir(dir); + if (ent == NULL || ent->d_name[0] == '\0') + break; + + if (ent->d_name[0] == '.') + continue; + + snprintf(filename, NAME_SIZE, "%s/%s", udev_db_path, ent->d_name); + filename[NAME_SIZE-1] = '\0'; + + memset(&db_udev, 0x00, sizeof(struct udevice)); + if (parse_db_file(&db_udev, filename) == 0) { + if (handler_function(&db_udev) != 0) + break; + } + } + + closedir(dir); + return 0; +} diff --git a/udev_db.h b/udev_db.h index 5065eaa6c..6a0647f20 100644 --- a/udev_db.h +++ b/udev_db.h @@ -30,5 +30,6 @@ extern int udev_db_delete_device(struct udevice *dev); extern int udev_db_get_device_by_devpath(struct udevice *dev, const char *devpath); extern int udev_db_get_device_by_name(struct udevice *udev, const char *name); +extern int udev_db_call_foreach(int (*handler_function)(struct udevice *udev)); #endif /* _UDEV_DB_H_ */ diff --git a/udevinfo.8 b/udevinfo.8 index 963b69aed..ac8cc7fda 100644 --- a/udevinfo.8 +++ b/udevinfo.8 @@ -47,6 +47,10 @@ attributes along the device chain. Useful for finding unique attributes to compose a rule. .RB Needs " \-p " specified. .TP +.B \-d +Print the relationship between the devpath and the node name for all devices +currently available in the database. +.TP .B \-h Print help text. .SH "FILES" diff --git a/udevinfo.c b/udevinfo.c index e7417697c..045395256 100644 --- a/udevinfo.c +++ b/udevinfo.c @@ -178,9 +178,14 @@ exit: return retval; } +static int print_dump(struct udevice *udev) { + printf("%s:%s/%s\n", udev->devpath, udev_root, udev->name); + return 0; +} + static int process_options(int argc, char *argv[]) { - static const char short_options[] = "an:p:q:rVh"; + static const char short_options[] = "adn:p:q:rVh"; int option; int retval = 1; struct udevice udev; @@ -245,6 +250,10 @@ static int process_options(int argc, char *argv[]) attributes = 1; break; + case 'd': + udev_db_call_foreach(print_dump); + exit(0); + case 'V': printf("udevinfo, version %s\n", UDEV_VERSION); exit(0); @@ -384,7 +393,8 @@ help: "\n" " -r print udev root\n" " -a print all SYSFS_attributes along the device chain\n" - " -s print all sysfs devices with major/minor, physical device and bus\n" + " -d print the relationship of devpath and the node name for all\n" + " devices available in the database\n" " -V print udev version\n" " -h print this help text\n" "\n");