From 3be0e096d4cefe9c2ba941abea2530f9703f6a60 Mon Sep 17 00:00:00 2001 From: mananth Date: Fri, 12 Dec 2003 14:10:26 +0000 Subject: Function name changes for functions that take path as argument --- ChangeLog | 11 +++++++++++ docs/libsysfs.txt | 24 ++++++++++++------------ include/libsysfs.h | 18 +++++++++++------- lib/sysfs_bus.c | 6 +++--- lib/sysfs_class.c | 22 ++++++++++++---------- lib/sysfs_device.c | 12 ++++++------ lib/sysfs_driver.c | 38 ++++++++++++++++++++++++++++++++++---- 7 files changed, 89 insertions(+), 42 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5b2b373..d3fd83d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,15 @@ +12/12/2003 - Daniel Stekloff + * Changed function prototypes for sysfs_open_* calls that + accept absolute path to have _path suffix + * Changed function prototypes that take the device/driver + bus/class and name to be normal sysfs_open_xxx() + * Changed sysfs_close_cls_dev() to be a static function + +12/12/2003 - Ananth Mavinakayanahalli + * Added function to open a driver knowing its name + and the bus it is on + 12/10/2003 - Ananth Mavinakayanahalli * Added more optimization changes * Added code to add and refresh attributes dynamically diff --git a/docs/libsysfs.txt b/docs/libsysfs.txt index b401a25..30c4e8c 100644 --- a/docs/libsysfs.txt +++ b/docs/libsysfs.txt @@ -945,7 +945,7 @@ Prototype: void sysfs_close_class(struct sysfs_class *class); ------------------------------------------------------------------------------- ------------------------------------------------------------------------------- -Name: sysfs_open_class_device +Name: sysfs_open_class_device_path Description: Function opens up one of the class devices represented in sysfs in sysfs/class/"class"/ directory. It returns a @@ -957,7 +957,7 @@ Returns: struct sysfs_class_device * with success NULL with error. Errno will be set with error, returning - EINVAL for invalid arguments -Prototype: struct sysfs_class_device *sysfs_open_class_device +Prototype: struct sysfs_class_device *sysfs_open_class_device_path (const unsigned char *path) ------------------------------------------------------------------------------- @@ -991,7 +991,7 @@ Prototype: struct sysfs_class_device *sysfs_get_class_device ------------------------------------------------------------------------------- ------------------------------------------------------------------------------- -Name: sysfs_open_class_device_by_name +Name: sysfs_open_class_device Description: Given the name of the class on which to look for, this function locates a given class device and returns a sysfs_class_device @@ -1011,7 +1011,7 @@ Returns: struct sysfs_class_device * with success NULL with error. Errno will be set with error, returning - EINVAL for invalid arguments -Prototype: struct sysfs_class_device *sysfs_open_class_device_by_name +Prototype: struct sysfs_class_device *sysfs_open_class_device (const unsigned char *classname, unsigned char *class) ------------------------------------------------------------------------------- @@ -1084,7 +1084,7 @@ root devices. These functions recursively open or close a device and all of its children. ------------------------------------------------------------------------------- -Name: sysfs_open_device +Name: sysfs_open_device_path Description: Opens up a device at a specific path. It opens the device's directory, reads the directory, and returns a sysfs_device @@ -1096,7 +1096,7 @@ Returns: struct sysfs_device * with success NULL with error. Errno will be set with error, returning - EINVAL for invalid arguments -Prototype: struct sysfs_device *sysfs_open_device +Prototype: struct sysfs_device *sysfs_open_device_path (const unsigned char *path) ------------------------------------------------------------------------------- @@ -1173,7 +1173,7 @@ Prototype: struct dlist *sysfs_get_device_attributes ------------------------------------------------------------------------------- ------------------------------------------------------------------------------- -Name: sysfs_open_device_by_id +Name: sysfs_open_device Description: Given the name of the bus on which to look for, this function locates a given device and returns a sysfs_device structure @@ -1193,7 +1193,7 @@ Returns: struct sysfs_device * with success NULL with error. Errno will be set with error, returning - EINVAL for invalid arguments -Prototype: struct sysfs_device *sysfs_open_device_by_id +Prototype: struct sysfs_device *sysfs_open_device (const unsigned char *bus_id, const unsigned char *bus) ------------------------------------------------------------------------------- @@ -1230,7 +1230,7 @@ the bus type, such as "pci", "usb, and so on). Functions are provided to open and close drivers. ------------------------------------------------------------------------------- -Name: sysfs_open_driver +Name: sysfs_open_driver_path Description: Opens driver at specific path. @@ -1240,7 +1240,7 @@ Returns: struct sysfs_driver * with success NULL with error. Errno will be set with error, returning - EINVAL for invalid arguments -Prototype: struct sysfs_driver *sysfs_open_driver +Prototype: struct sysfs_driver *sysfs_open_driver_path (const unsigned char *path) ------------------------------------------------------------------------------- @@ -1289,7 +1289,7 @@ Prototype: struct dlist *sysfs_get_driver_attributes ------------------------------------------------------------------------------- ------------------------------------------------------------------------------- -Name: sysfs_open_driver_by_name +Name: sysfs_open_driver Description: Given the name of the bus on which to look for, this function locates a given driver and returns a sysfs_driver structure @@ -1311,7 +1311,7 @@ Returns: struct sysfs_driver * with success NULL with error. Errno will be set with error, returning - EINVAL for invalid arguments -Prototype: struct sysfs_driver *sysfs_open_driver_by_name +Prototype: struct sysfs_driver *sysfs_open_driver (const unsigned char *drv_name, const unsigned char *bus, size_t bsize) ------------------------------------------------------------------------------- diff --git a/include/libsysfs.h b/include/libsysfs.h index 0939102..bec8a0a 100644 --- a/include/libsysfs.h +++ b/include/libsysfs.h @@ -178,7 +178,11 @@ extern struct sysfs_attribute *sysfs_get_directory_attribute /* sysfs driver access */ extern void sysfs_close_driver(struct sysfs_driver *driver); -extern struct sysfs_driver *sysfs_open_driver(const unsigned char *path); +extern struct sysfs_driver *sysfs_open_driver + (const unsigned char *drv_name, const unsigned char *bus_name); +extern struct sysfs_driver *sysfs_open_driver_path(const unsigned char *path); +extern struct sysfs_driver *sysfs_open_driver_by_name + (const unsigned char *drv_name, const unsigned char *bus_name); extern struct sysfs_attribute *sysfs_get_driver_attr (struct sysfs_driver *drv, const unsigned char *name); extern struct dlist *sysfs_get_driver_attributes(struct sysfs_driver *driver); @@ -195,12 +199,12 @@ extern struct sysfs_root_device *sysfs_open_root_device (const unsigned char *name); extern struct dlist *sysfs_get_root_devices(struct sysfs_root_device *root); extern void sysfs_close_device(struct sysfs_device *dev); -extern struct sysfs_device *sysfs_open_device(const unsigned char *path); +extern struct sysfs_device *sysfs_open_device + (const unsigned char *bus_id, const unsigned char *bus); +extern struct sysfs_device *sysfs_open_device_path(const unsigned char *path); extern struct sysfs_attribute *sysfs_get_device_attr (struct sysfs_device *dev, const unsigned char *name); extern struct dlist *sysfs_get_device_attributes(struct sysfs_device *device); -extern struct sysfs_device *sysfs_open_device_by_id - (const unsigned char *bus_id, const unsigned char *bus); extern struct sysfs_attribute *sysfs_open_device_attr(const unsigned char *bus, const unsigned char *bus_id, const unsigned char *attrib); @@ -223,8 +227,10 @@ extern int sysfs_find_driver_bus(const unsigned char *driver, /* generic sysfs class access */ extern void sysfs_close_class_device(struct sysfs_class_device *dev); -extern struct sysfs_class_device *sysfs_open_class_device +extern struct sysfs_class_device *sysfs_open_class_device_path (const unsigned char *path); +extern struct sysfs_class_device *sysfs_open_class_device + (const unsigned char *class, const unsigned char *name); extern struct sysfs_device *sysfs_get_classdev_device (struct sysfs_class_device *clsdev); extern struct sysfs_driver *sysfs_get_classdev_driver @@ -236,8 +242,6 @@ extern struct sysfs_class *sysfs_open_class(const unsigned char *name); extern struct dlist *sysfs_get_class_devices(struct sysfs_class *cls); extern struct sysfs_class_device *sysfs_get_class_device (struct sysfs_class *class, unsigned char *name); -extern struct sysfs_class_device *sysfs_open_class_device_by_name - (const unsigned char *class, const unsigned char *name); extern struct dlist *sysfs_get_classdev_attributes (struct sysfs_class_device *cdev); extern struct sysfs_attribute *sysfs_get_classdev_attr diff --git a/lib/sysfs_bus.c b/lib/sysfs_bus.c index 0a7b171..3723fe3 100644 --- a/lib/sysfs_bus.c +++ b/lib/sysfs_bus.c @@ -122,7 +122,7 @@ struct dlist *sysfs_get_bus_devices(struct sysfs_bus *bus) } dlist_for_each_data(devdir->links, curl, struct sysfs_link) { - bdev = sysfs_open_device(curl->target); + bdev = sysfs_open_device_path(curl->target); if (bdev == NULL) { dprintf("Error opening device at %s\n", curl->target); continue; @@ -166,7 +166,7 @@ struct dlist *sysfs_get_bus_drivers(struct sysfs_bus *bus) return NULL; } dlist_for_each_data(drvdir->subdirs, cursub, struct sysfs_directory) { - driver = sysfs_open_driver(cursub->path); + driver = sysfs_open_driver_path(cursub->path); if (driver == NULL) { dprintf("Error opening driver at %s\n", cursub->path); continue; @@ -414,7 +414,7 @@ struct sysfs_device *sysfs_open_bus_device(unsigned char *busname, strcat(path, "/"); strcat(path, dev_id); - rdev = sysfs_open_device(path); + rdev = sysfs_open_device_path(path); if (rdev == NULL) { dprintf("Error getting device %s on bus %s\n", dev_id, busname); diff --git a/lib/sysfs_class.c b/lib/sysfs_class.c index 7d85f8f..98a4d10 100644 --- a/lib/sysfs_class.c +++ b/lib/sysfs_class.c @@ -23,7 +23,7 @@ #include "libsysfs.h" #include "sysfs.h" -void sysfs_close_cls_dev(void *dev) +static void sysfs_close_cls_dev(void *dev) { sysfs_close_class_device((struct sysfs_class_device *)dev); } @@ -130,11 +130,12 @@ static void set_classdev_classname(struct sysfs_class_device *cdev) } /** - * sysfs_open_class_device: Opens and populates class device + * sysfs_open_class_device_path: Opens and populates class device * @path: path to class device. * returns struct sysfs_class_device with success and NULL with error. */ -struct sysfs_class_device *sysfs_open_class_device(const unsigned char *path) +struct sysfs_class_device *sysfs_open_class_device_path + (const unsigned char *path) { struct sysfs_class_device *cdev = NULL; @@ -190,7 +191,7 @@ struct dlist *sysfs_get_class_devices(struct sysfs_class *cls) dlist_for_each_data(cls->directory->subdirs, cur, struct sysfs_directory) { - dev = sysfs_open_class_device(cur->path); + dev = sysfs_open_class_device_path(cur->path); if (dev == NULL) { dprintf("Error opening device at %s\n", cur->path); continue; @@ -306,7 +307,7 @@ struct sysfs_device *sysfs_get_classdev_device if (devlink == NULL) return NULL; - clsdev->sysdevice = sysfs_open_device(devlink->target); + clsdev->sysdevice = sysfs_open_device_path(devlink->target); if (clsdev->sysdevice == NULL) return NULL; if (clsdev->driver != NULL) @@ -342,7 +343,7 @@ struct sysfs_driver *sysfs_get_classdev_driver } drvlink = sysfs_get_directory_link(clsdev->directory, "driver"); if (drvlink != NULL) { - clsdev->driver = sysfs_open_driver(drvlink->target); + clsdev->driver = sysfs_open_driver_path(drvlink->target); if (clsdev->driver == NULL) return NULL; @@ -400,7 +401,7 @@ static int get_blockdev_parent(struct sysfs_class_device *clsdev) goto errout; *c = '\0'; - clsdev->parent = sysfs_open_class_device(parent_path); + clsdev->parent = sysfs_open_class_device_path(parent_path); if (clsdev->parent == NULL) { dprintf("Error opening the parent class device at %s\n", parent_path); @@ -479,7 +480,7 @@ static int get_classdev_path(const unsigned char *classname, } /** - * sysfs_open_class_device_by_name: Locates a specific class_device and returns it. + * sysfs_open_class_device: Locates a specific class_device and returns it. * Class_device must be closed using sysfs_close_class_device * @classname: Class to search * @name: name of the class_device @@ -487,7 +488,7 @@ static int get_classdev_path(const unsigned char *classname, * NOTE: * Call sysfs_close_class_device() to close the class device */ -struct sysfs_class_device *sysfs_open_class_device_by_name +struct sysfs_class_device *sysfs_open_class_device (const unsigned char *classname, const unsigned char *name) { unsigned char devpath[SYSFS_PATH_MAX]; @@ -506,7 +507,7 @@ struct sysfs_class_device *sysfs_open_class_device_by_name return NULL; } - cdev = sysfs_open_class_device(devpath); + cdev = sysfs_open_class_device_path(devpath); if (cdev == NULL) { dprintf("Error getting class device %s from class %s\n", name, classname); @@ -641,3 +642,4 @@ struct sysfs_attribute *sysfs_open_classdev_attr(const unsigned char *classname, } return attribute; } + diff --git a/lib/sysfs_device.c b/lib/sysfs_device.c index 46e72ec..1dea8ce 100644 --- a/lib/sysfs_device.c +++ b/lib/sysfs_device.c @@ -174,11 +174,11 @@ static struct sysfs_directory *open_device_dir(const unsigned char *path) } /** - * sysfs_open_device: opens and populates device structure + * sysfs_open_device_path: opens and populates device structure * @path: path to device, this is the /sys/devices/ path * returns sysfs_device structure with success or NULL with error */ -struct sysfs_device *sysfs_open_device(const unsigned char *path) +struct sysfs_device *sysfs_open_device_path(const unsigned char *path) { struct sysfs_device *dev = NULL; @@ -232,7 +232,7 @@ static struct sysfs_device *sysfs_open_device_tree(const unsigned char *path) errno = EINVAL; return NULL; } - rootdev = sysfs_open_device(path); + rootdev = sysfs_open_device_path(path); if (rootdev == NULL) { dprintf("Error opening root device at %s\n", path); return NULL; @@ -463,7 +463,7 @@ static int get_device_absolute_path(const unsigned char *device, } /** - * sysfs_open_device_by_id: open a device by id (use the "bus" subsystem) + * sysfs_open_device: open a device by id (use the "bus" subsystem) * @bus_id: bus_id of the device to open - has to be the "bus_id" in * /sys/bus/xxx/devices * @bus: bus the device belongs to @@ -473,7 +473,7 @@ static int get_device_absolute_path(const unsigned char *device, * 2. Bus the device is on must be supplied * Use sysfs_find_device_bus to get the bus name */ -struct sysfs_device *sysfs_open_device_by_id(const unsigned char *bus_id, +struct sysfs_device *sysfs_open_device(const unsigned char *bus_id, const unsigned char *bus) { char sysfs_path[SYSFS_PATH_MAX]; @@ -490,7 +490,7 @@ struct sysfs_device *sysfs_open_device_by_id(const unsigned char *bus_id, return NULL; } - device = sysfs_open_device(sysfs_path); + device = sysfs_open_device_path(sysfs_path); if (device == NULL) { dprintf("Error opening device %s\n", bus_id); return NULL; diff --git a/lib/sysfs_driver.c b/lib/sysfs_driver.c index f2145e0..1ccaf03 100644 --- a/lib/sysfs_driver.c +++ b/lib/sysfs_driver.c @@ -98,11 +98,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; struct sysfs_directory *sdir = NULL; @@ -243,7 +243,7 @@ struct dlist *sysfs_get_driver_devices(struct sysfs_driver *driver) 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 +345,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 +367,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; +} + -- cgit v1.2.1