]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
[PATCH] udevinfo: print devpath -> node relationship for all devices
authorkay.sievers@vrfy.org <kay.sievers@vrfy.org>
Fri, 25 Feb 2005 06:40:14 +0000 (07:40 +0100)
committerGreg KH <gregkh@suse.de>
Wed, 27 Apr 2005 06:39:48 +0000 (23:39 -0700)
udev_db.c
udev_db.h
udevinfo.8
udevinfo.c

index 61d4b130d35f0e64aeb82b3189deaf108a5d346a..4515998fcd8c311fa950f63142269567c5d939cf 100644 (file)
--- 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;
+}
index 5065eaa6c694edd5153307774ef51cdff3d2c170..6a0647f2007b50767de88e7d5e256b0d75a48ed8 100644 (file)
--- 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_ */
index 963b69aed2f41e4e35ce69f9f449fa9430b9a275..ac8cc7fda5ed9c54d4324775a73ab2cd1540176d 100644 (file)
@@ -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"
index e7417697cf7174c028d6cad69fd6ee4f75f3914f..045395256d2b75d2b254ef562299872fbaf9faa2 100644 (file)
@@ -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");