diff options
author | Mauro Carvalho Chehab <mchehab@redhat.com> | 2009-08-22 23:17:30 -0300 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2009-08-22 23:17:30 -0300 |
commit | acfae2a2f2799047a9856f48803ed9d13d7f0e66 (patch) | |
tree | 9889212154d1ff511af1c613e500619d415a8442 /v4l2-apps/util | |
parent | 0cba7f108664f9efc0e34a388c51cb943c72d68b (diff) | |
download | mediapointer-dvb-s2-acfae2a2f2799047a9856f48803ed9d13d7f0e66.tar.gz mediapointer-dvb-s2-acfae2a2f2799047a9856f48803ed9d13d7f0e66.tar.bz2 |
v4l2-sysfs-path: print the subdevs associated with that device
From: Mauro Carvalho Chehab <mchehab@redhat.com>
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 <mchehab@redhat.com>
Diffstat (limited to 'v4l2-apps/util')
-rw-r--r-- | v4l2-apps/util/v4l2-sysfs-path.c | 51 |
1 files changed, 50 insertions, 1 deletions
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 <stdio.h> #include <string.h> #include <dirent.h> +#include <sys/stat.h> #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); } |