From acfae2a2f2799047a9856f48803ed9d13d7f0e66 Mon Sep 17 00:00:00 2001 From: Mauro Carvalho Chehab Date: Sat, 22 Aug 2009 23:17:30 -0300 Subject: v4l2-sysfs-path: print the subdevs associated with that device From: Mauro Carvalho Chehab The sysfs interface stores links to the other devices associated with a V4L link. Improves this util to display those associated subdevices. This small tool can be used inside other V4L applications to properly associate audio, input, sound and dvb devices with a /dev/video? file. device = /dev/video0 bus info = usb-0000:00:1d.7-8 sysfs path = /sys/devices/pci0000:00/0000:00:1d.7/usb1/1-8 Subdevs: usb_endpoint:usbdev1.8_ep00 i2c-adapter:i2c-4 input:input8 sound:pcmC1D0c sound:dsp1 sound:audio1 sound:controlC1 sound:mixer1 dvb:dvb0.frontend0 dvb:dvb0.demux0 dvb:dvb0.dvr0 dvb:dvb0.net0 Signed-off-by: Mauro Carvalho Chehab --- v4l2-apps/util/v4l2-sysfs-path.c | 51 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) (limited to 'v4l2-apps/util/v4l2-sysfs-path.c') diff --git a/v4l2-apps/util/v4l2-sysfs-path.c b/v4l2-apps/util/v4l2-sysfs-path.c index e3f3e63e8..90157fa11 100644 --- a/v4l2-apps/util/v4l2-sysfs-path.c +++ b/v4l2-apps/util/v4l2-sysfs-path.c @@ -23,6 +23,7 @@ #include #include #include +#include #define USB_ID "usb-" #define PCI_ID "PCI:" @@ -135,6 +136,52 @@ err: return NULL; } +/* + Examples of subdevs: + sound:audio1 + sound:controlC1 + sound:dsp1 + sound:mixer1 + sound:pcmC1D0c + dvb:dvb0.demux0 + dvb:dvb0.dvr0 + dvb:dvb0.frontend0 + dvb:dvb0.net0 + i2c-adapter:i2c-4 + input:input8 +*/ + +void get_subdevs(char *path) +{ + DIR *dir; + struct dirent *entry; + struct stat st; + char *p, name[1024]; + + dir = opendir(path); + if (!dir) + return; + + strcpy(name, path); + strcat(name, "/"); + p = name + strlen(name); + + printf("Subdevs: "); + entry = readdir(dir); + while (entry) { + strcpy(p, entry->d_name); + if ((lstat(name, &st) == 0) && + !S_ISDIR(st.st_mode)) { + char *s = strchr(entry->d_name, ':'); + if (s) + printf("%s ", entry->d_name); + } + entry = readdir(dir); + } + closedir(dir); + printf("\n"); +} + void get_sysfs(char *fname) { struct v4l2_driver drv; @@ -148,9 +195,11 @@ void get_sysfs(char *fname) printf("bus info = %s\n", drv.cap.bus_info); path = obtain_bus_sysfs_path((char *)drv.cap.bus_info); if (path) { - printf("sysfs path = %s\n\n", path); + printf("sysfs path = %s\n", path); + get_subdevs(path); free(path); } + printf("\n"); v4l2_close(&drv); } -- cgit v1.2.3 From 2d5790ba1659b7cea2c72ac05747f29852fa272d Mon Sep 17 00:00:00 2001 From: Mauro Carvalho Chehab Date: Sun, 23 Aug 2009 12:45:08 -0300 Subject: v4l2-sysfs-path: print device minor/major of the associated devices From: Mauro Carvalho Chehab 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 --- v4l2-apps/util/v4l2-sysfs-path.c | 90 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 84 insertions(+), 6 deletions(-) (limited to 'v4l2-apps/util/v4l2-sysfs-path.c') 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) -- cgit v1.2.3 From 5132986080f45c38e0a8f0677c61e5f4e280ea9a Mon Sep 17 00:00:00 2001 From: Hans Verkuil Date: Wed, 26 Aug 2009 22:34:01 +0200 Subject: v4l2-sysfs-path: fix compile warning. From: Hans Verkuil Priority: normal Signed-off-by: Hans Verkuil --- v4l2-apps/util/v4l2-sysfs-path.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'v4l2-apps/util/v4l2-sysfs-path.c') diff --git a/v4l2-apps/util/v4l2-sysfs-path.c b/v4l2-apps/util/v4l2-sysfs-path.c index 2a6ab0cfc..4f0817017 100644 --- a/v4l2-apps/util/v4l2-sysfs-path.c +++ b/v4l2-apps/util/v4l2-sysfs-path.c @@ -245,13 +245,14 @@ void get_subdevs(char *path) char *s = strchr(entry->d_name, ':'); if (s) { printf("\t%s", entry->d_name); - if (!get_dev(entry->d_name, &major, &minor, extra)) + 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"); } } -- cgit v1.2.3