mirror of
https://github.com/systemd/systemd.git
synced 2025-01-27 18:04:05 +03:00
[PATCH] udevinfo: print devpath -> node relationship for all devices
This commit is contained in:
parent
f8a178a35b
commit
9fe1a96d88
35
udev_db.c
35
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;
|
||||
}
|
||||
|
@ -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_ */
|
||||
|
@ -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"
|
||||
|
14
udevinfo.c
14
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");
|
||||
|
Loading…
x
Reference in New Issue
Block a user