diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2024-08-26 21:14:12 +0200 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2024-08-27 22:26:26 +0200 |
commit | 3fe0fd20c9f50948929ef623fd6d47b37e30fd11 (patch) | |
tree | 217cc0fe8bd5de89f19f109f1bac076f3fd3e0ea | |
parent | sd-device: make sd_device_new_from_subsystem_sysname() stricter (diff) | |
download | systemd-3fe0fd20c9f50948929ef623fd6d47b37e30fd11.tar.xz systemd-3fe0fd20c9f50948929ef623fd6d47b37e30fd11.zip |
udevadm/info: also show driver subsystem and device ID
This adds two more fields in 'udevadm info':
- J for device ID, e.g. b128:1, c10:1, n1, and so on.
- B for driver subsystem, e.g. pci, i2c, and so on.
These, especially the device ID field may be useful to find udev
database file under /run/udev/data for a device.
-rw-r--r-- | man/udevadm.xml | 8 | ||||
-rw-r--r-- | src/udev/udevadm-info.c | 23 |
2 files changed, 29 insertions, 2 deletions
diff --git a/man/udevadm.xml b/man/udevadm.xml index b515f3c79c..556f845dce 100644 --- a/man/udevadm.xml +++ b/man/udevadm.xml @@ -337,10 +337,18 @@ <entry>Device number in <filename>/sys/</filename> (i.e. the numeric suffix of the last component of <literal>P:</literal>)</entry> </row> <row> + <entry><literal>J:</literal></entry> + <entry>Device ID</entry> + </row> + <row> <entry><literal>U:</literal></entry> <entry>Kernel subsystem</entry> </row> <row> + <entry><literal>B:</literal></entry> + <entry>Driver subsystem</entry> + </row> + <row> <entry><literal>T:</literal></entry> <entry>Kernel device type within subsystem</entry> </row> diff --git a/src/udev/udevadm-info.c b/src/udev/udevadm-info.c index 824b6fc726..0a1da3ed31 100644 --- a/src/udev/udevadm-info.c +++ b/src/udev/udevadm-info.c @@ -323,9 +323,15 @@ static int print_record(sd_device *device, const char *prefix) { if (sd_device_get_sysnum(device, &str) >= 0) printf("%sR: %s%s%s\n", prefix, ansi_highlight_white(), str, ansi_normal()); + if (sd_device_get_device_id(device, &str) >= 0) + printf("%sJ: %s%s%s\n", prefix, ansi_highlight_white(), str, ansi_normal()); + if (sd_device_get_subsystem(device, &subsys) >= 0) printf("%sU: %s%s%s\n", prefix, ansi_highlight_green(), subsys, ansi_normal()); + if (sd_device_get_driver_subsystem(device, &str) >= 0) + printf("%sB: %s%s%s\n", prefix, ansi_highlight_green(), str, ansi_normal()); + if (sd_device_get_devtype(device, &str) >= 0) printf("%sT: %s%s%s\n", prefix, ansi_highlight_green(), str, ansi_normal()); @@ -376,8 +382,9 @@ static int record_to_json(sd_device *device, sd_json_variant **ret) { assert(device); assert(ret); - /* We don't show any shorthand fields here as done in print_record() except for SYSNAME and SYSNUM as - * all the other ones have a matching property which will already be included. */ + /* We don't show any shorthand fields here as done in print_record() except for SYSNAME, SYSNUM, + * DRIVER_SUBSYSTEM, and DEVICE_ID, as all the other ones have a matching property which will already + * be included. */ if (sd_device_get_sysname(device, &str) >= 0) { r = sd_json_variant_set_field_string(&v, "SYSNAME", str); @@ -391,6 +398,18 @@ static int record_to_json(sd_device *device, sd_json_variant **ret) { return r; } + if (sd_device_get_driver_subsystem(device, &str) >= 0) { + r = sd_json_variant_set_field_string(&v, "DRIVER_SUBSYSTEM", str); + if (r < 0) + return r; + } + + if (sd_device_get_device_id(device, &str) >= 0) { + r = sd_json_variant_set_field_string(&v, "DEVICE_ID", str); + if (r < 0) + return r; + } + FOREACH_DEVICE_PROPERTY(device, key, val) { r = sd_json_variant_set_field_string(&v, key, val); if (r < 0) |