summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--udev_db.c35
-rw-r--r--udev_db.h1
-rw-r--r--udevinfo.84
-rw-r--r--udevinfo.c14
4 files changed, 52 insertions, 2 deletions
diff --git a/udev_db.c b/udev_db.c
index 61d4b130d3..4515998fcd 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 5065eaa6c6..6a0647f200 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 963b69aed2..ac8cc7fda5 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 e7417697cf..045395256d 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");