summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormananth <mananth>2003-10-15 12:12:22 +0000
committermananth <mananth>2003-10-15 12:12:22 +0000
commit9823fffa72ad2b296ef9e223635985718f7e9939 (patch)
treea78b4f355782faab5e50cb01532320b1383f3912
parent89b2f6ff171dcf09b165541d79012471c6035e18 (diff)
downloadsysfsutils-9823fffa72ad2b296ef9e223635985718f7e9939.tar.gz
Added function to find the "class" of a given "class_device"
-rw-r--r--ChangeLog4
-rw-r--r--include/libsysfs.h2
-rw-r--r--lib/sysfs_class.c49
3 files changed, 54 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index e785fb8..c7898ce 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,8 @@
+09/09/2003 - Ananth Mavinakayanahalli <ananth@in.ibm.com>
+ * Added sysfs_find_device_class to find what class a
+ device is on
+
09/05/2003 - Ananth Mavinakayanahalli <ananth@in.ibm.com>
* Add sysfs_open_bus_devices_list()
* Simplify sysfs_find_device_bus_name()
diff --git a/include/libsysfs.h b/include/libsysfs.h
index 8f0cd87..46d5a11 100644
--- a/include/libsysfs.h
+++ b/include/libsysfs.h
@@ -214,6 +214,8 @@ extern struct sysfs_class_device *sysfs_open_class_device_by_name
(unsigned char *class, unsigned char *name);
extern struct dlist *sysfs_get_classdev_attributes
(struct sysfs_class_device *cdev);
+extern int sysfs_find_device_class_name(unsigned char *bus_id,
+ unsigned char *classname, size_t bsize);
#ifdef __cplusplus
}
diff --git a/lib/sysfs_class.c b/lib/sysfs_class.c
index c93428a..898a5bc 100644
--- a/lib/sysfs_class.c
+++ b/lib/sysfs_class.c
@@ -346,7 +346,6 @@ struct sysfs_class_device *sysfs_open_class_device_by_name
return rcdev;
}
-
/**
* sysfs_get_classdev_attributes: returns a dlist of attributes for
* the requested class_device
@@ -360,3 +359,51 @@ struct dlist *sysfs_get_classdev_attributes(struct sysfs_class_device *cdev)
return (cdev->directory->attributes);
}
+
+/**
+ * sysfs_find_device_class: locates the device the device is on
+ * @bus_id: device to look for
+ * @classname: buffer to copy class name to
+ * @bsize: size of buffer
+ * returns 0 with success and -1 with error
+ */
+int sysfs_find_device_class_name(unsigned char *bus_id,
+ unsigned char *classname, size_t bsize)
+{
+ unsigned char class[SYSFS_NAME_LEN], clspath[SYSFS_NAME_LEN];
+ unsigned char *cls = NULL, *clsdev = NULL;
+ struct dlist *clslist = NULL, *clsdev_list = NULL;
+
+ if (bus_id == NULL || classname == NULL) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ strcpy(class, SYSFS_CLASS_DIR);
+ clslist = sysfs_open_subsystem_list(class);
+ if (clslist != NULL) {
+ dlist_for_each_data(clslist, cls, char) {
+ memset(clspath, 0, SYSFS_NAME_LEN);
+ strcpy(clspath, SYSFS_CLASS_DIR);
+ strcat(clspath, "/");
+ strcat(clspath, cls);
+ clsdev_list = sysfs_open_subsystem_list(clspath);
+ if (clsdev_list != NULL) {
+ dlist_for_each_data(clsdev_list,
+ clsdev, char) {
+ if (strcmp(bus_id, clsdev) == 0) {
+ strncpy(classname,
+ cls, bsize);
+ sysfs_close_list(clsdev_list);
+ sysfs_close_list(clslist);
+ return 0;
+ }
+ }
+ sysfs_close_list(clsdev_list);
+ }
+ }
+ sysfs_close_list(clslist);
+ }
+ return -1;
+}
+