Google
  Web www.spinics.net

[PATCH] v4l2-ctl: List device links as such

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


Subject: v4l2-ctl: List device links as such

Improvement to --list-devices: when a device node is actually a link
to another device node, display it as such. For example, my devices
which where previously listed as:

BT878 video (Hauppauge (bt878)) (PCI:0000:00:09.0):
	/dev/video2
	/dev/vbi
	/dev/vbi0

WinFast DTV1000-T (PCI:0000:00:0a.0):
	/dev/video
	/dev/video0
	/dev/vbi1

DC10plus[0] (PCI:0000:00:0b.0):
	/dev/video1

BT848A video (MIRO PCTV pro) (PCI:0000:00:0d.0):
	/dev/video3
	/dev/radio
	/dev/radio0
	/dev/vbi2

are now listed as:

BT878 video (Hauppauge (bt878)) (PCI:0000:00:09.0):
	/dev/video2
	/dev/vbi0 <- /dev/vbi

WinFast DTV1000-T (PCI:0000:00:0a.0):
	/dev/video0 <- /dev/video
	/dev/vbi1

DC10plus[0] (PCI:0000:00:0b.0):
	/dev/video1

BT848A video (MIRO PCTV pro) (PCI:0000:00:0d.0):
	/dev/video3
	/dev/radio0 <- /dev/radio
	/dev/vbi2

I think it gives a better idea of how many features each device has.

Signed-off-by: Jean Delvare <khali@xxxxxxxxxxxx>
---
And thanks to Hans Verkuil for implementing --list-devices in the
first place, that's very useful!

Note: I don't know much about C++, so maybe my implementation can be
improved.

 v4l2-apps/util/v4l2-ctl.cpp |   37 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 36 insertions(+), 1 deletion(-)

--- v4l-dvb-06df1b240240.orig/v4l2-apps/util/v4l2-ctl.cpp	2008-10-25 10:32:19.000000000 +0200
+++ v4l-dvb-06df1b240240/v4l2-apps/util/v4l2-ctl.cpp	2008-10-25 11:36:58.000000000 +0200
@@ -1096,6 +1096,7 @@ static void list_devices()
 	DIR *dp;
 	struct dirent *ep;
 	dev_vec files;
+	dev_map links;
 	dev_map cards;
 	struct v4l2_capability vcap;
 
@@ -1119,6 +1120,37 @@ static void list_devices()
 	}
 #endif
 
+	/* Find device nodes which are links to other device nodes */
+	for (dev_vec::iterator iter = files.begin();
+			iter != files.end(); ) {
+		char link[64+1];
+		int link_len;
+		std::string target;
+
+		link_len = readlink(iter->c_str(), link, 64);
+		if (link_len < 0) {	/* Not a link or error */
+			iter++;
+			continue;
+		}
+		link[link_len] = '\0';
+
+		/* Only remove from files list if target itself is in list */
+		if (link[0] != '/')	/* Relative link */
+			target = std::string("/dev/");
+		target += link;
+		if (find(files.begin(), files.end(), target) == files.end()) {
+			iter++;
+			continue;
+		}
+
+		/* Move the device node from files to links */
+		if (links[target].empty())
+			links[target] = *iter;
+		else
+			links[target] += ", " + *iter;
+		files.erase(iter);
+	}
+
 	std::sort(files.begin(), files.end(), sort_on_device_name);
 
 	for (dev_vec::iterator iter = files.begin();
@@ -1133,7 +1165,10 @@ static void list_devices()
 		bus_info = (const char *)vcap.bus_info;
 		if (cards[bus_info].empty())
 			cards[bus_info] += std::string((char *)vcap.card) + " (" + bus_info + "):\n";
-		cards[bus_info] += "\t" + (*iter) + "\n";
+		cards[bus_info] += "\t" + (*iter);
+		if (!(links[*iter].empty()))
+			cards[bus_info] += " <- " + links[*iter];
+		cards[bus_info] += "\n";
 	}
 	for (dev_map::iterator iter = cards.begin();
 			iter != cards.end(); ++iter) {


-- 
Jean Delvare

_______________________________________________
v4l-dvb-maintainer mailing list
v4l-dvb-maintainer@xxxxxxxxxxx
http://www.linuxtv.org/cgi-bin/mailman/listinfo/v4l-dvb-maintainer

[Linux Media]     [Older V4L]     [Linux DVB]     [Video Disk Recorder]     [Asterisk]     [Photo]     [DCCP]     [Netdev]     [Xorg]     [Util Linux NG]     [Xfree86]     [Free Photo Albums]     [Fedora Users]     [Fedora Women]     [ALSA Users]     [ALSA Devel]     [SSH]     [Linux USB]

-->
Add to Google Powered by Linux

Google PageRank Checking tool