* [PATCH] udev - program to query all device attributes to build a rule
@ 2004-01-18 6:30 Kay Sievers
2004-01-18 13:59 ` Kay Sievers
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Kay Sievers @ 2004-01-18 6:30 UTC (permalink / raw)
To: linux-hotplug
[-- Attachment #1: Type: text/plain, Size: 1739 bytes --]
Hi,
here is a small program to query all attributes of a device and
print these in the udev key format. It may help to get the keys to
define a rule.
thanks,
Kay
USB Flash Reader:
kay@pim:~/src/udev.kay/extras/udevinfo$ ./udevinfo /sys/block/sda/sda3
device '/sys/block/sda/sda3' has major:minor 8:3
looking at class device '/sys/block/sda/sda3':
SYSFS_dev="8:3"
SYSFS_start="384"
SYSFS_size="192"
SYSFS_stat=" 0 0 0 0"
follow class device's "device" link '/sys/block/sda':
BUS="scsi"
ID="56:0:0:0"
SYSFS_dev="8:0"
SYSFS_range="16"
SYSFS_size="31360"
SYSFS_stat=" 12 0 96 88 0 0 0 0 0 88 88"
Or the USB Webcam:
kay@pim:~/src/udev.kay/extras/udevinfo$ ./udevinfo /sys/class/video4linux/video0/
device '/sys/class/video4linux/video0' has major:minor 81:0
looking at class device '/sys/class/video4linux/video0':
SYSFS_dev="81:0"
SYSFS_name="OV511 USB Camera"
SYSFS_custom_id="21"
SYSFS_model="Creative Labs WebCam 3"
SYSFS_bridge="OV511+"
SYSFS_sensor="OV7620"
SYSFS_brightness="105"
SYSFS_saturation="192"
SYSFS_contrast="86"
SYSFS_hue="128"
SYSFS_exposure="0"
follow class device's "device" link '/sys/class/video4linux/video0':
BUS="usb"
ID="1-1.2"
SYSFS_dev="81:0"
SYSFS_name="OV511 USB Camera"
SYSFS_custom_id="21"
SYSFS_model="Creative Labs WebCam 3"
SYSFS_bridge="OV511+"
SYSFS_sensor="OV7620"
SYSFS_brightness="105"
SYSFS_saturation="192"
SYSFS_contrast="86"
SYSFS_hue="128"
SYSFS_exposure="0"
[-- Attachment #2: 03-udevinfo.patch --]
[-- Type: text/plain, Size: 4141 bytes --]
diff -Nru a/extras/udevinfo/Makefile b/extras/udevinfo/Makefile
--- /dev/null Wed Dec 31 16:00:00 1969
+++ b/extras/udevinfo/Makefile Sun Jan 18 07:08:43 2004
@@ -0,0 +1,14 @@
+PROG=udevinfo
+LD=$(CC)
+OBJS=udevinfo.o
+
+all: $(PROG)
+
+clean:
+ rm -f $(PROG) $(OBJS)
+
+$(PROG): $(OBJS)
+ $(LD) $(LDFLAGS) -o $(PROG) $(CRT0) $(OBJS) $(SYSFS)
+
+me:
+ cd ../..; make EXTRAS=extras/udevinfo
diff -Nru a/extras/udevinfo/udevinfo.c b/extras/udevinfo/udevinfo.c
--- /dev/null Wed Dec 31 16:00:00 1969
+++ b/extras/udevinfo/udevinfo.c Sun Jan 18 07:08:43 2004
@@ -0,0 +1,133 @@
+/*
+ * udevinfo - fetches attributes for a device
+ *
+ * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+
+#include "libsysfs.h"
+
+
+# define VALUE_SIZE 100
+
+char **main_argv;
+char **main_envp;
+
+static int print_all_attributes(char *path)
+{
+ struct dlist *attributes;
+ struct sysfs_attribute *attr;
+ struct sysfs_directory *sysfs_dir;
+ char value[VALUE_SIZE];
+ int len;
+ int retval = 0;
+
+ sysfs_dir = sysfs_open_directory(path);
+ if (sysfs_dir == NULL)
+ return -1;
+
+ attributes = sysfs_get_dir_attributes(sysfs_dir);
+ if (attributes == NULL) {
+ retval = -1;
+ goto exit;
+ }
+
+ dlist_for_each_data(attributes, attr, struct sysfs_attribute) {
+ if (attr->value != NULL) {
+ strncpy(value, attr->value, VALUE_SIZE);
+ len = strlen(value);
+ if (value[len-1] == '\n')
+ value[len-1] = '\0';
+ printf(" SYSFS_%s=\"%s\"\n", attr->name, value);
+ }
+ }
+ printf("\n");
+
+exit:
+ sysfs_close_directory(sysfs_dir);
+
+ return retval;
+}
+
+int main(int argc, char **argv, char **envp)
+{
+ main_argv = argv;
+ main_envp = envp;
+ struct sysfs_class_device *class_dev;
+ struct sysfs_class_device *class_dev_parent;
+ struct sysfs_attribute *attr;
+ struct sysfs_device *sysfs_device;
+ char *path;
+ int retval = 0;
+
+ if (argc != 2) {
+ printf("Usage: udevinfo <sysfs_device_path>\n");
+ return -1;
+ }
+ path = argv[1];
+
+ /* get the class dev */
+ class_dev = sysfs_open_class_device_path(path);
+ if (class_dev == NULL) {
+ printf("couldn't get the class device\n");
+ return -1;
+ }
+
+ /* read the 'dev' file for major/minor*/
+ attr = sysfs_get_classdev_attr(class_dev, "dev");
+ if (attr == NULL) {
+ printf("couldn't get the \"dev\" file\n");
+ retval = -1;
+ goto exit;
+ }
+ printf("\ndevice '%s' has major:minor %s\n\n", class_dev->path, attr->value);
+ sysfs_close_attribute(attr);
+
+ /* open sysfs class device directory and print all attributes */
+ printf("looking at class device '%s':\n", class_dev->path);
+ if (print_all_attributes(class_dev->path) != 0) {
+ printf("couldn't open class device directory\n");
+ retval = -1;
+ goto exit;
+ }
+
+ /* get the device (if parent exists use it instead) */
+ class_dev_parent = sysfs_get_classdev_parent(class_dev);
+ if (class_dev_parent != NULL) {
+ //sysfs_close_class_device(class_dev);
+ class_dev = class_dev_parent;
+ }
+ sysfs_device = sysfs_get_classdev_device(class_dev);
+ if (sysfs_device != NULL) {
+ printf("follow class device's \"device\" link '%s':\n", class_dev->path);
+ printf(" BUS=\"%s\"\n", sysfs_device->bus);
+ printf(" ID=\"%s\"\n", sysfs_device->bus_id);
+
+ /* open sysfs device directory and print all attributes */
+ print_all_attributes(class_dev->path);
+
+ sysfs_close_device(sysfs_device);
+ }
+
+exit:
+ //sysfs_close_class_device(class_dev);
+ return retval;
+}
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] udev - program to query all device attributes to build a rule
2004-01-18 6:30 [PATCH] udev - program to query all device attributes to build a rule Kay Sievers
@ 2004-01-18 13:59 ` Kay Sievers
2004-01-19 19:47 ` Greg KH
2004-01-20 14:07 ` Olaf Hering
2 siblings, 0 replies; 4+ messages in thread
From: Kay Sievers @ 2004-01-18 13:59 UTC (permalink / raw)
To: linux-hotplug
[-- Attachment #1: Type: text/plain, Size: 928 bytes --]
On Sun, Jan 18, 2004 at 07:30:50AM +0100, Kay Sievers wrote:
> Hi,
> here is a small program to query all attributes of a device and
> print these in the udev key format. It may help to get the keys to
> define a rule.
Fixed a typo - the sysfs_device is right now.
USB FLash Reader:
kay@pim:~/src/udev.kay$ extras/udevinfo/udevinfo /sys/block/sda/sda1
device '/sys/block/sda/sda1' has major:minor 8:1
looking at class device '/sys/block/sda/sda1':
SYSFS_dev="8:1"
SYSFS_start="32"
SYSFS_size="160"
SYSFS_stat=" 0 0 0 0"
follow class device's "device" link '/sys/block/sda':
BUS="scsi"
ID="57:0:0:0"
SYSFS_detach_state="0"
SYSFS_type="0"
SYSFS_device_blocked="0"
SYSFS_queue_depth="1"
SYSFS_scsi_level="3"
SYSFS_vendor="SMSC "
SYSFS_model="USB 2 HS-CF"
SYSFS_rev="1.25"
SYSFS_online="1"
[-- Attachment #2: 03-udevinfo.patch --]
[-- Type: text/plain, Size: 4140 bytes --]
diff -Nru a/extras/udevinfo/Makefile b/extras/udevinfo/Makefile
--- /dev/null Wed Dec 31 16:00:00 1969
+++ b/extras/udevinfo/Makefile Sun Jan 18 14:50:58 2004
@@ -0,0 +1,14 @@
+PROG=udevinfo
+LD=$(CC)
+OBJS=udevinfo.o
+
+all: $(PROG)
+
+clean:
+ rm -f $(PROG) $(OBJS)
+
+$(PROG): $(OBJS)
+ $(LD) $(LDFLAGS) -o $(PROG) $(CRT0) $(OBJS) $(SYSFS)
+
+me:
+ cd ../..; make EXTRAS=extras/udevinfo
diff -Nru a/extras/udevinfo/udevinfo.c b/extras/udevinfo/udevinfo.c
--- /dev/null Wed Dec 31 16:00:00 1969
+++ b/extras/udevinfo/udevinfo.c Sun Jan 18 14:50:58 2004
@@ -0,0 +1,132 @@
+/*
+ * udevinfo - fetches attributes for a device
+ *
+ * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+
+#include "libsysfs.h"
+
+
+# define VALUE_SIZE 200
+
+char **main_argv;
+char **main_envp;
+
+static int print_all_attributes(char *path)
+{
+ struct dlist *attributes;
+ struct sysfs_attribute *attr;
+ struct sysfs_directory *sysfs_dir;
+ char value[VALUE_SIZE];
+ int len;
+ int retval = 0;
+
+ sysfs_dir = sysfs_open_directory(path);
+ if (sysfs_dir == NULL)
+ return -1;
+
+ attributes = sysfs_get_dir_attributes(sysfs_dir);
+ if (attributes == NULL) {
+ retval = -1;
+ goto exit;
+ }
+
+ dlist_for_each_data(attributes, attr, struct sysfs_attribute) {
+ if (attr->value != NULL) {
+ strncpy(value, attr->value, VALUE_SIZE);
+ len = strlen(value);
+ if (value[len-1] == '\n')
+ value[len-1] = '\0';
+ printf(" SYSFS_%s=\"%s\"\n", attr->name, value);
+ }
+ }
+ printf("\n");
+
+exit:
+ sysfs_close_directory(sysfs_dir);
+
+ return retval;
+}
+
+int main(int argc, char **argv, char **envp)
+{
+ main_argv = argv;
+ main_envp = envp;
+ struct sysfs_class_device *class_dev;
+ struct sysfs_class_device *class_dev_parent;
+ struct sysfs_attribute *attr;
+ struct sysfs_device *sysfs_device;
+ char *path;
+ int retval = 0;
+
+ if (argc != 2) {
+ printf("Usage: udevinfo <sysfs_device_path>\n");
+ return -1;
+ }
+ path = argv[1];
+
+ /* get the class dev */
+ class_dev = sysfs_open_class_device_path(path);
+ if (class_dev == NULL) {
+ printf("couldn't get the class device\n");
+ return -1;
+ }
+
+ /* read the 'dev' file for major/minor*/
+ attr = sysfs_get_classdev_attr(class_dev, "dev");
+ if (attr == NULL) {
+ printf("couldn't get the \"dev\" file\n");
+ retval = -1;
+ goto exit;
+ }
+ printf("\ndevice '%s' has major:minor %s\n", class_dev->path, attr->value);
+ sysfs_close_attribute(attr);
+
+ /* open sysfs class device directory and print all attributes */
+ printf("looking at class device '%s':\n", class_dev->path);
+ if (print_all_attributes(class_dev->path) != 0) {
+ printf("couldn't open class device directory\n");
+ retval = -1;
+ goto exit;
+ }
+
+ /* get the device (if parent exists use it instead) */
+ class_dev_parent = sysfs_get_classdev_parent(class_dev);
+ if (class_dev_parent != NULL) {
+ //sysfs_close_class_device(class_dev);
+ class_dev = class_dev_parent;
+ }
+ sysfs_device = sysfs_get_classdev_device(class_dev);
+ if (sysfs_device != NULL) {
+ printf("follow class device's \"device\" link '%s':\n", class_dev->path);
+ printf(" BUS=\"%s\"\n", sysfs_device->bus);
+ printf(" ID=\"%s\"\n", sysfs_device->bus_id);
+
+ /* open sysfs device directory and print all attributes */
+ print_all_attributes(sysfs_device->path);
+ sysfs_close_device(sysfs_device);
+ }
+
+exit:
+ //sysfs_close_class_device(class_dev);
+ return retval;
+}
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] udev - program to query all device attributes to build a rule
2004-01-18 6:30 [PATCH] udev - program to query all device attributes to build a rule Kay Sievers
2004-01-18 13:59 ` Kay Sievers
@ 2004-01-19 19:47 ` Greg KH
2004-01-20 14:07 ` Olaf Hering
2 siblings, 0 replies; 4+ messages in thread
From: Greg KH @ 2004-01-19 19:47 UTC (permalink / raw)
To: linux-hotplug
On Sun, Jan 18, 2004 at 02:59:06PM +0100, Kay Sievers wrote:
> On Sun, Jan 18, 2004 at 07:30:50AM +0100, Kay Sievers wrote:
> > Hi,
> > here is a small program to query all attributes of a device and
> > print these in the udev key format. It may help to get the keys to
> > define a rule.
>
> Fixed a typo - the sysfs_device is right now.
Nice program. Applied, thanks.
greg k-h
-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration
See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] udev - program to query all device attributes to build a rule
2004-01-18 6:30 [PATCH] udev - program to query all device attributes to build a rule Kay Sievers
2004-01-18 13:59 ` Kay Sievers
2004-01-19 19:47 ` Greg KH
@ 2004-01-20 14:07 ` Olaf Hering
2 siblings, 0 replies; 4+ messages in thread
From: Olaf Hering @ 2004-01-20 14:07 UTC (permalink / raw)
To: linux-hotplug
On Sun, Jan 18, Kay Sievers wrote:
> Hi,
> here is a small program to query all attributes of a device and
> print these in the udev key format. It may help to get the keys to
> define a rule.
I get link errors without this patch.
make 'EXTRAS=extras/scsi_id extras/udevinfo' USE_LOGúlse USE_KLIBC=true STRIP=/bin/true
Maybe I should build it against glibc.
--- udev.bk/extras/udevinfo/Makefile 2004-01-18 15:50:58.000000000 +0100
+++ udev-013/extras/udevinfo/Makefile 2004-01-20 15:02:53.000000000 +0100
@@ -1,5 +1,6 @@
PROG=udevinfo
LD=$(CC)
+override SYSFS= -L../../libsysfs -lsysfs
OBJS=udevinfo.o
all: $(PROG)
@@ -8,7 +9,7 @@ clean:
rm -f $(PROG) $(OBJS)
$(PROG): $(OBJS)
- $(LD) $(LDFLAGS) -o $(PROG) $(CRT0) $(OBJS) $(SYSFS)
+ $(LD) $(LDFLAGS) -o $(PROG) $(CRT0) $(OBJS) $(SYSFS) $(LIB_OBJS) $(ARCH_LIB_OBJS)
me:
cd ../..; make EXTRAS=extras/udevinfo
--
USB is for mice, FireWire is for men!
sUse lINUX ag, nÃœRNBERG
-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration
See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2004-01-20 14:07 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-01-18 6:30 [PATCH] udev - program to query all device attributes to build a rule Kay Sievers
2004-01-18 13:59 ` Kay Sievers
2004-01-19 19:47 ` Greg KH
2004-01-20 14:07 ` Olaf Hering
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.