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') 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