diff options
author | Mauro Carvalho Chehab <mchehab@redhat.com> | 2009-08-23 12:45:08 -0300 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2009-08-23 12:45:08 -0300 |
commit | 2d5790ba1659b7cea2c72ac05747f29852fa272d (patch) | |
tree | 0f8147ecdbe4a3686fcd84c5c54d67e77b03cc96 /v4l2-apps/util | |
parent | bc086d6c321888e2a8df7c9495d09c46a393cb1a (diff) | |
download | mediapointer-dvb-s2-2d5790ba1659b7cea2c72ac05747f29852fa272d.tar.gz mediapointer-dvb-s2-2d5790ba1659b7cea2c72ac05747f29852fa272d.tar.bz2 |
v4l2-sysfs-path: print device minor/major of the associated devices
From: Mauro Carvalho Chehab <mchehab@redhat.com>
Instead of just printing the associated devices, go further and display
the device major/minors and the associated event interface. The output
will look like:
device = /dev/video0
bus info = usb-0000:00:1d.7-8
sysfs path = /sys/devices/pci0000:00/0000:00:1d.7/usb1/1-8
Associated devices:
usb_endpoint:usbdev1.8_ep00 (dev 252,20)
i2c-adapter:i2c-4
input:input9:event6 (dev 13,70)
sound:pcmC1D0c (dev 116,9)
sound:dsp1 (dev 14,19)
sound:audio1 (dev 14,20)
sound:controlC1 (dev 116,10)
sound:mixer1 (dev 14,16)
dvb:dvb0.frontend0 (dev 212,0)
dvb:dvb0.demux0 (dev 212,1)
dvb:dvb0.dvr0 (dev 212,2)
dvb:dvb0.net0 (dev 212,3)
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'v4l2-apps/util')
-rw-r--r-- | v4l2-apps/util/v4l2-sysfs-path.c | 90 |
1 files changed, 84 insertions, 6 deletions
diff --git a/v4l2-apps/util/v4l2-sysfs-path.c b/v4l2-apps/util/v4l2-sysfs-path.c index 90157fa11..2a6ab0cfc 100644 --- a/v4l2-apps/util/v4l2-sysfs-path.c +++ b/v4l2-apps/util/v4l2-sysfs-path.c @@ -136,6 +136,75 @@ err: return NULL; } +char *seek_name(char *path, char *match) +{ + DIR *dir; + struct dirent *entry; + struct stat st; + char *p; + static char name[1024]; + int major, minor; + + dir = opendir(path); + if (!dir) + return NULL; + + strcpy(name, path); + strcat(name, "/"); + p = name + strlen(name); + + entry = readdir(dir); + while (entry) { + if (!strncmp(entry->d_name, match, strlen(match))) { + + strcpy(name, entry->d_name); + closedir(dir); + return name; + } + entry = readdir(dir); + } + closedir(dir); + return NULL; +} + +int get_dev(char *class, int *major, int *minor, char *extra) +{ + char path[1024]; + char *name; + FILE *fp; + + name = strchr(class,':'); + if (!name) + return -1; + *name = 0; + name++; + + *extra = 0; + + if (!strcmp(class, "input")) { + char *event; + + sprintf(path, "/sys/class/%s/%s/", class, name); + event = seek_name(path, "event"); + if (!event) + return -1; + + strcpy(extra, event); + + sprintf(path, "/sys/class/%s/%s/%s/dev", class, name, event); + + } else + sprintf(path, "/sys/class/%s/%s/dev", class, name); + + fp = fopen(path, "r"); + if (!fp) + return -1; + + fscanf(fp, "%d:%d", major, minor); + + return 0; +} + /* Examples of subdevs: sound:audio1 @@ -156,7 +225,8 @@ void get_subdevs(char *path) DIR *dir; struct dirent *entry; struct stat st; - char *p, name[1024]; + char *p, name[1024], extra[20]; + int major, minor; dir = opendir(path); if (!dir) @@ -166,20 +236,28 @@ void get_subdevs(char *path) strcat(name, "/"); p = name + strlen(name); - printf("Subdevs: "); + printf("Associated devices:\n"); entry = readdir(dir); while (entry) { strcpy(p, entry->d_name); - if ((lstat(name, &st) == 0) && + if ((lstat(name, &st) == 0) && !S_ISDIR(st.st_mode)) { char *s = strchr(entry->d_name, ':'); - if (s) - printf("%s ", entry->d_name); + if (s) { + printf("\t%s", entry->d_name); + if (!get_dev(entry->d_name, &major, &minor, extra)) + if (*extra) + printf(":%s (dev %d,%d)", + extra, major, minor); + else + printf(" (dev %d,%d)", + major, minor); + printf("\n"); + } } entry = readdir(dir); } closedir(dir); - printf("\n"); } void get_sysfs(char *fname) |