diff options
author | mananth <mananth> | 2003-12-12 14:52:40 +0000 |
---|---|---|
committer | mananth <mananth> | 2003-12-12 14:52:40 +0000 |
commit | 48401dcfccc68c651732c9a2d3691b56cdcbec3c (patch) | |
tree | 3b2623bc1562fe8218c2aafad7dcc85db3ff1c96 | |
parent | 26a8563c088a648cdcc1e89c3ec83dd6e6b29bb0 (diff) | |
download | sysfsutils-48401dcfccc68c651732c9a2d3691b56cdcbec3c.tar.gz |
Miscllaneous changes - add new function prototypes, remove unused vars, etc.
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | cmd/lsbus.c | 6 | ||||
-rw-r--r-- | cmd/systool.c | 4 | ||||
-rw-r--r-- | include/libsysfs.h | 3 | ||||
-rw-r--r-- | lib/sysfs_bus.c | 104 | ||||
-rw-r--r-- | lib/sysfs_class.c | 38 | ||||
-rw-r--r-- | lib/sysfs_dir.c | 24 | ||||
-rw-r--r-- | lib/sysfs_driver.c | 1 |
8 files changed, 70 insertions, 114 deletions
@@ -1,4 +1,8 @@ +12/12/2003 - Ananth Mavinakayanahalli <ananth@in.ibm.com> + * Miscllaneous changes - added new function definitions, + general code cleanup + 12/12/2003 - Daniel Stekloff <dsteklof@us.ibm.com> * Changed function prototypes for sysfs_open_* calls that accept absolute path to have _path suffix diff --git a/cmd/lsbus.c b/cmd/lsbus.c index 923ba22..a3d4eef 100644 --- a/cmd/lsbus.c +++ b/cmd/lsbus.c @@ -272,7 +272,7 @@ void print_driver(struct sysfs_driver *driver) if (devlist != NULL) { struct sysfs_device *dev = NULL; fprintf(stdout, "\tDevices:\n"); - dlist_for_each_data(driver->devices, dev, + dlist_for_each_data(devlist, dev, struct sysfs_device) fprintf(stdout, "\t\t%s\n", dev->bus_id); } @@ -311,7 +311,7 @@ int print_sysfs_bus(unsigned char *busname) if (devlist != NULL) { if (bus_device == NULL) fprintf(stdout, "Devices:\n"); - dlist_for_each_data(bus->devices, curdev, + dlist_for_each_data(devlist, curdev, struct sysfs_device) { if (bus_device == NULL || (strcmp(bus_device, curdev->bus_id) == 0)) @@ -323,7 +323,7 @@ int print_sysfs_bus(unsigned char *busname) drvlist = sysfs_get_bus_drivers(bus); if (drvlist != NULL) { fprintf(stdout, "Drivers:\n"); - dlist_for_each_data(bus->drivers, curdrv, + dlist_for_each_data(drvlist, curdrv, struct sysfs_driver) { print_driver(curdrv); } diff --git a/cmd/systool.c b/cmd/systool.c index 873d664..0b7a792 100644 --- a/cmd/systool.c +++ b/cmd/systool.c @@ -406,7 +406,7 @@ int show_sysfs_bus(unsigned char *busname) if (devlist != NULL) { if (device_to_show == NULL) fprintf(stdout, "Devices:\n"); - dlist_for_each_data(bus->devices, curdev, + dlist_for_each_data(devlist, curdev, struct sysfs_device) { if (device_to_show == NULL || (strcmp(device_to_show, @@ -419,7 +419,7 @@ int show_sysfs_bus(unsigned char *busname) drvlist = sysfs_get_bus_drivers(bus); if (drvlist != NULL) { fprintf(stdout, "Drivers:\n"); - dlist_for_each_data(bus->drivers, curdrv, + dlist_for_each_data(drvlist, curdrv, struct sysfs_driver) { show_driver(curdrv, 2); } diff --git a/include/libsysfs.h b/include/libsysfs.h index bec8a0a..877e0f2 100644 --- a/include/libsysfs.h +++ b/include/libsysfs.h @@ -160,9 +160,12 @@ extern int sysfs_write_attribute(struct sysfs_attribute *sysattr, const unsigned char *new_value, size_t len); extern unsigned char *sysfs_get_value_from_attributes(struct dlist *attr, const unsigned char * name); +extern int sysfs_refresh_attributes(struct dlist *attrlist); extern void sysfs_close_directory(struct sysfs_directory *sysdir); extern struct sysfs_directory *sysfs_open_directory(const unsigned char *path); extern int sysfs_read_dir_attributes(struct sysfs_directory *sysdir); +extern int sysfs_read_dir_links(struct sysfs_directory *sysdir); +extern int sysfs_read_dir_subdirs(struct sysfs_directory *sysdir); extern int sysfs_read_directory(struct sysfs_directory *sysdir); extern int sysfs_read_all_subdirs(struct sysfs_directory *sysdir); extern struct sysfs_directory *sysfs_get_subdirectory diff --git a/lib/sysfs_bus.c b/lib/sysfs_bus.c index 3723fe3..e8c2c32 100644 --- a/lib/sysfs_bus.c +++ b/lib/sysfs_bus.c @@ -121,16 +121,20 @@ struct dlist *sysfs_get_bus_devices(struct sysfs_bus *bus) return NULL; } - dlist_for_each_data(devdir->links, curl, struct sysfs_link) { - bdev = sysfs_open_device_path(curl->target); - if (bdev == NULL) { - dprintf("Error opening device at %s\n", curl->target); - continue; + if (devdir->links != 0) { + dlist_for_each_data(devdir->links, curl, struct sysfs_link) { + bdev = sysfs_open_device_path(curl->target); + if (bdev == NULL) { + dprintf("Error opening device at %s\n", + curl->target); + continue; + } + if (bus->devices == NULL) + bus->devices = dlist_new_with_delete + (sizeof(struct sysfs_device), + sysfs_close_dev); + dlist_unshift(bus->devices, bdev); } - if (bus->devices == NULL) - bus->devices = dlist_new_with_delete - (sizeof(struct sysfs_device), sysfs_close_dev); - dlist_unshift(bus->devices, bdev); } sysfs_close_directory(devdir); @@ -165,79 +169,27 @@ struct dlist *sysfs_get_bus_drivers(struct sysfs_bus *bus) sysfs_close_directory(drvdir); return NULL; } - dlist_for_each_data(drvdir->subdirs, cursub, struct sysfs_directory) { - driver = sysfs_open_driver_path(cursub->path); - if (driver == NULL) { - dprintf("Error opening driver at %s\n", cursub->path); - continue; + if (drvdir->subdirs != NULL) { + dlist_for_each_data(drvdir->subdirs, cursub, + struct sysfs_directory) { + driver = sysfs_open_driver_path(cursub->path); + if (driver == NULL) { + dprintf("Error opening driver at %s\n", + cursub->path); + continue; + } + if (bus->drivers == NULL) + bus->drivers = dlist_new_with_delete + (sizeof(struct sysfs_driver), + sysfs_close_drv); + dlist_unshift(bus->drivers, driver); } - if (bus->drivers == NULL) - bus->drivers = dlist_new_with_delete - (sizeof(struct sysfs_driver), sysfs_close_drv); - dlist_unshift(bus->drivers, driver); } sysfs_close_directory(drvdir); return (bus->drivers); } /** - * match_bus_device_to_driver: returns 1 if device is bound to driver - * @driver: driver to match - * @busid: busid of device to match - * returns 1 if found and 0 if not found - */ -static int match_bus_device_to_driver(struct sysfs_driver *driver, - unsigned char *busid) -{ - struct sysfs_link *cur = NULL; - struct dlist *links = NULL; - int found = 0; - - if (driver == NULL || busid == NULL) { - errno = EINVAL; - return found; - } - - links = sysfs_get_driver_links(driver); - if (links != NULL) { - dlist_for_each_data(links, cur, - struct sysfs_link) { - if ((strcmp(cur->name, busid)) == 0) - found++; - } - } - return found; -} - -/** - * link_bus_devices_to_drivers: goes through and links devices to drivers - * @bus: bus to link - */ -static void link_bus_devices_to_drivers(struct sysfs_bus *bus) -{ - struct sysfs_device *dev = NULL; - struct sysfs_driver *drv = NULL; - - if (bus != NULL && bus->devices != NULL && bus->drivers != NULL) { - dlist_for_each_data(bus->devices, dev, struct sysfs_device) { - dlist_for_each_data(bus->drivers, drv, - struct sysfs_driver) { - if ((match_bus_device_to_driver(drv, - dev->bus_id)) != 0) { - strncpy(dev->driver_name, drv->name, - SYSFS_NAME_LEN); - if (drv->devices == NULL) - drv->devices = dlist_new - (sizeof(struct - sysfs_device)); - dlist_unshift(drv->devices, dev); - } - } - } - } -} - -/** * sysfs_open_bus: opens specific bus and all its devices on system * returns sysfs_bus structure with success or NULL with error. */ @@ -285,8 +237,6 @@ struct sysfs_bus *sysfs_open_bus(const unsigned char *name) struct sysfs_device *sysfs_get_bus_device(struct sysfs_bus *bus, unsigned char *id) { - struct dlist *devlist = NULL; - if (bus == NULL || id == NULL) { errno = EINVAL; return NULL; diff --git a/lib/sysfs_class.c b/lib/sysfs_class.c index 98a4d10..c71e412 100644 --- a/lib/sysfs_class.c +++ b/lib/sysfs_class.c @@ -185,22 +185,24 @@ struct dlist *sysfs_get_class_devices(struct sysfs_class *cls) return NULL; } - if ((sysfs_read_dir_subdirs(cls->directory) != 0) - || cls->directory->subdirs == NULL) + if ((sysfs_read_dir_subdirs(cls->directory)) != 0) return NULL; - dlist_for_each_data(cls->directory->subdirs, cur, - struct sysfs_directory) { - dev = sysfs_open_class_device_path(cur->path); - if (dev == NULL) { - dprintf("Error opening device at %s\n", cur->path); - continue; - } - if (cls->devices == NULL) - cls->devices = dlist_new_with_delete + if (cls->directory->subdirs != NULL) { + dlist_for_each_data(cls->directory->subdirs, cur, + struct sysfs_directory) { + dev = sysfs_open_class_device_path(cur->path); + if (dev == NULL) { + dprintf("Error opening device at %s\n", + cur->path); + continue; + } + if (cls->devices == NULL) + cls->devices = dlist_new_with_delete (sizeof(struct sysfs_class_device), sysfs_close_cls_dev); - dlist_unshift(cls->devices, dev); + dlist_unshift(cls->devices, dev); + } } return cls->devices; } @@ -588,12 +590,14 @@ struct sysfs_attribute *sysfs_get_classdev_attr clsdev->directory->subdirs == NULL) return NULL; - dlist_for_each_data(clsdev->directory->subdirs, sdir, - struct sysfs_directory) { - cur = sysfs_get_directory_attribute(sdir, + if (clsdev->directory->subdirs != NULL) { + dlist_for_each_data(clsdev->directory->subdirs, sdir, + struct sysfs_directory) { + cur = sysfs_get_directory_attribute(sdir, (unsigned char *)name); - if (cur != NULL) - return cur; + if (cur != NULL) + return cur; + } } return NULL; diff --git a/lib/sysfs_dir.c b/lib/sysfs_dir.c index 33fe4ec..3de63c7 100644 --- a/lib/sysfs_dir.c +++ b/lib/sysfs_dir.c @@ -437,13 +437,15 @@ int sysfs_read_all_subdirs(struct sysfs_directory *sysdir) return -1; } if (sysdir->subdirs == NULL) - if ((sysfs_read_dir_subdirs(sysdir) != 0) - || sysdir->subdirs == NULL) + if ((sysfs_read_dir_subdirs(sysdir)) != 0) return 0; - dlist_for_each_data(sysdir->subdirs, cursub, struct sysfs_directory) { - if ((sysfs_read_directory(cursub)) != 0) - dprintf ("Error reading subdirectory %s\n", - cursub->name); + if (sysdir->subdirs != NULL) { + dlist_for_each_data(sysdir->subdirs, cursub, + struct sysfs_directory) { + if ((sysfs_read_directory(cursub)) != 0) + dprintf ("Error reading subdirectory %s\n", + cursub->name); + } } return 0; } @@ -523,7 +525,8 @@ int sysfs_refresh_attributes(struct dlist *attrlist) dlist_for_each_data(attrlist, attr, struct sysfs_attribute) { if (attr->method & SYSFS_METHOD_SHOW) { if ((sysfs_read_attribute(attr)) != 0) { - dprintf("Error reading attribute %s\n", path); + dprintf("Error reading attribute %s\n", + attr->path); if ((sysfs_path_is_file(attr->path)) != 0) { dprintf("Attr %s no longer exists\n", attr->name); @@ -536,12 +539,6 @@ int sysfs_refresh_attributes(struct dlist *attrlist) } } } - if (attrlist->count == 0) { - dprintf("No attributes in the list, destroying list now\n"); - dlist_destroy(attrlist); - attrlist = NULL; - return 1; - } return 0; } @@ -762,7 +759,6 @@ int sysfs_read_directory(struct sysfs_directory *sysdir) DIR *dir = NULL; struct dirent *dirent = NULL; struct stat astats; - struct sysfs_link *ln = NULL; unsigned char file_path[SYSFS_PATH_MAX]; int retval = 0; diff --git a/lib/sysfs_driver.c b/lib/sysfs_driver.c index 1ccaf03..3ec8089 100644 --- a/lib/sysfs_driver.c +++ b/lib/sysfs_driver.c @@ -105,7 +105,6 @@ static struct sysfs_driver *alloc_driver(void) struct sysfs_driver *sysfs_open_driver_path(const unsigned char *path) { struct sysfs_driver *driver = NULL; - struct sysfs_directory *sdir = NULL; if (path == NULL) { errno = EINVAL; |