2 * udevinfo - fetches attributes for a device
4 * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation version 2 of the License.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 675 Mass Ave, Cambridge, MA 02139, USA.
29 # define VALUE_SIZE 200
34 static int print_all_attributes(char *path)
36 struct dlist *attributes;
37 struct sysfs_attribute *attr;
38 struct sysfs_directory *sysfs_dir;
39 char value[VALUE_SIZE];
43 sysfs_dir = sysfs_open_directory(path);
44 if (sysfs_dir == NULL)
47 attributes = sysfs_get_dir_attributes(sysfs_dir);
48 if (attributes == NULL) {
53 dlist_for_each_data(attributes, attr, struct sysfs_attribute) {
54 if (attr->value != NULL) {
55 strncpy(value, attr->value, VALUE_SIZE);
57 if (value[len-1] == '\n')
59 printf(" SYSFS_%s=\"%s\"\n", attr->name, value);
65 sysfs_close_directory(sysfs_dir);
70 int main(int argc, char **argv, char **envp)
74 struct sysfs_class_device *class_dev;
75 struct sysfs_class_device *class_dev_parent;
76 struct sysfs_attribute *attr;
77 struct sysfs_device *sysfs_device;
82 printf("Usage: udevinfo <sysfs_device_path>\n");
87 /* get the class dev */
88 class_dev = sysfs_open_class_device_path(path);
89 if (class_dev == NULL) {
90 printf("couldn't get the class device\n");
94 /* read the 'dev' file for major/minor*/
95 attr = sysfs_get_classdev_attr(class_dev, "dev");
97 printf("couldn't get the \"dev\" file\n");
101 printf("\ndevice '%s' has major:minor %s\n", class_dev->path, attr->value);
102 sysfs_close_attribute(attr);
104 /* open sysfs class device directory and print all attributes */
105 printf("looking at class device '%s':\n", class_dev->path);
106 if (print_all_attributes(class_dev->path) != 0) {
107 printf("couldn't open class device directory\n");
112 /* get the device (if parent exists use it instead) */
113 class_dev_parent = sysfs_get_classdev_parent(class_dev);
114 if (class_dev_parent != NULL) {
115 //sysfs_close_class_device(class_dev);
116 class_dev = class_dev_parent;
118 sysfs_device = sysfs_get_classdev_device(class_dev);
119 if (sysfs_device != NULL) {
120 printf("follow class device's \"device\" link '%s':\n", class_dev->path);
121 printf(" BUS=\"%s\"\n", sysfs_device->bus);
122 printf(" ID=\"%s\"\n", sysfs_device->bus_id);
124 /* open sysfs device directory and print all attributes */
125 print_all_attributes(sysfs_device->path);
126 sysfs_close_device(sysfs_device);
130 //sysfs_close_class_device(class_dev);