summaryrefslogtreecommitdiff
path: root/libsysfs/sysfs_driver.c
diff options
context:
space:
mode:
authordsteklof@us.ibm.com <dsteklof@us.ibm.com>2003-12-19 18:29:10 -0800
committerGreg KH <gregkh@suse.de>2005-04-26 21:13:09 -0700
commitbcbe2d8e7d4ccd975e79d0c7defbe1d64d1b129c (patch)
tree78cc968183dc45e80f96133e4cb1a1c94ca461bd /libsysfs/sysfs_driver.c
parent7591c18a8f3460d3e7cab85d02915c4b51638b5c (diff)
[PATCH] libsysfs 0.4.0 patch
Ananth released sysfsutils 0.4.0 last night, I'm sure you saw the email. Here's a patch with the latest changes from the pre-patch I already gave you. It includes sysfs_get_device_parent(), which you said you needed. I've run your test scripts and I've built scsi_id. Please play around with this and check it out. There are quite a few changes. Please do not access structure pointers, like sysfs_device's parent, directly like dev->parent. Please use the "get" function to retrieve. The functions load things on demand and refresh views under the covers.
Diffstat (limited to 'libsysfs/sysfs_driver.c')
-rw-r--r--libsysfs/sysfs_driver.c72
1 files changed, 38 insertions, 34 deletions
diff --git a/libsysfs/sysfs_driver.c b/libsysfs/sysfs_driver.c
index 4372b19f10..695ca794f1 100644
--- a/libsysfs/sysfs_driver.c
+++ b/libsysfs/sysfs_driver.c
@@ -66,29 +66,6 @@ static int open_driver_dir(struct sysfs_driver *driver)
}
/**
- * read_driver_dir: Read driver directory's subdirs and links
- * @driver: Driver to read
- * Returns 0 on success and 1 on failure
- */
-static int read_driver_dir(struct sysfs_driver *driver)
-{
- if (driver == NULL) {
- errno = EINVAL;
- return 1;
- }
- if (driver->directory == NULL) {
- if ((open_driver_dir(driver)) == 1)
- return 1;
- }
- if ((sysfs_read_directory(driver->directory)) != 0) {
- dprintf("Error reading driver directory at %s\n",
- driver->path);
- return 1;
- }
- return 0;
-}
-
-/**
* alloc_driver: allocates and initializes driver
* returns struct sysfs_driver with success and NULL with error.
*/
@@ -98,11 +75,11 @@ static struct sysfs_driver *alloc_driver(void)
}
/**
- * sysfs_open_driver: opens and initializes driver structure
+ * sysfs_open_driver_path: opens and initializes driver structure
* @path: path to driver directory
* returns struct sysfs_driver with success and NULL with error
*/
-struct sysfs_driver *sysfs_open_driver(const unsigned char *path)
+struct sysfs_driver *sysfs_open_driver_path(const unsigned char *path)
{
struct sysfs_driver *driver = NULL;
@@ -185,13 +162,10 @@ struct sysfs_attribute *sysfs_get_driver_attr(struct sysfs_driver *drv,
}
attrlist = sysfs_get_driver_attributes(drv);
- if (attrlist != NULL) {
+ if (attrlist != NULL)
cur = sysfs_get_directory_attribute(drv->directory,
(unsigned char *)name);
- if (cur != NULL)
- return cur;
- }
- return NULL;
+ return cur;
}
/**
@@ -209,7 +183,7 @@ struct dlist *sysfs_get_driver_links(struct sysfs_driver *driver)
if (driver->directory == NULL) {
if ((open_driver_dir(driver)) == 1)
return NULL;
- if ((read_driver_dir(driver)) != 0)
+ if ((sysfs_read_dir_links(driver->directory)) != 0)
return NULL;
}
return(driver->directory->links);
@@ -236,13 +210,13 @@ struct dlist *sysfs_get_driver_devices(struct sysfs_driver *driver)
if (driver->directory == NULL) {
if ((open_driver_dir(driver)) == 1)
return NULL;
- if ((read_driver_dir(driver)) != 0)
+ if ((sysfs_read_dir_links(driver->directory)) != 0)
return NULL;
}
if (driver->directory->links != NULL) {
dlist_for_each_data(driver->directory->links, curlink,
struct sysfs_link) {
- device = sysfs_open_device(curlink->target);
+ device = sysfs_open_device_path(curlink->target);
if (device == NULL) {
dprintf("Error opening device at %s\n",
curlink->target);
@@ -345,7 +319,7 @@ struct sysfs_attribute *sysfs_open_driver_attr(const unsigned char *bus,
return NULL;
}
- memset(path, 0, SYSFS_NAME_LEN);
+ memset(path, 0, SYSFS_PATH_MAX);
if ((get_driver_path(bus, drv, path, SYSFS_PATH_MAX)) != 0) {
dprintf("Error getting to driver %s\n", drv);
return NULL;
@@ -367,3 +341,33 @@ struct sysfs_attribute *sysfs_open_driver_attr(const unsigned char *bus,
return attribute;
}
+/**
+ * sysfs_open_driver: open driver by name, given its bus
+ * @drv_name: Name of the driver
+ * @bus_name: Name of the bus
+ * Returns the sysfs_driver reference on success and NULL on failure
+ */
+struct sysfs_driver *sysfs_open_driver(const unsigned char *drv_name,
+ const unsigned char *bus_name)
+{
+ unsigned char path[SYSFS_PATH_MAX];
+ struct sysfs_driver *driver = NULL;
+
+ if (drv_name == NULL || bus_name == NULL) {
+ errno = EINVAL;
+ return NULL;
+ }
+
+ memset(path, 0, SYSFS_PATH_MAX);
+ if ((get_driver_path(bus_name, drv_name, path, SYSFS_PATH_MAX)) != 0) {
+ dprintf("Error getting to driver %s\n", drv_name);
+ return NULL;
+ }
+ driver = sysfs_open_driver_path(path);
+ if (driver == NULL) {
+ dprintf("Error opening driver at %s\n", path);
+ return NULL;
+ }
+ return driver;
+}
+