diff options
author | mananth <mananth> | 2003-12-17 11:41:12 +0000 |
---|---|---|
committer | mananth <mananth> | 2003-12-17 11:41:12 +0000 |
commit | 0a5c05219dfe9f38188b2fc975e93bb9a69d8ba9 (patch) | |
tree | 810955bf8c6a806021a4e31140a25511fc9b08a3 | |
parent | ac7317daab22e6a959b0f7f0f38853738cb3cef6 (diff) | |
download | sysfsutils-0a5c05219dfe9f38188b2fc975e93bb9a69d8ba9.tar.gz |
doc updates, miscllaneous changes
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | docs/libsysfs.txt | 353 | ||||
-rw-r--r-- | include/libsysfs.h | 2 | ||||
-rw-r--r-- | lib/sysfs_class.c | 28 | ||||
-rw-r--r-- | lib/sysfs_device.c | 4 | ||||
-rw-r--r-- | lib/sysfs_dir.c | 39 | ||||
-rw-r--r-- | lib/sysfs_driver.c | 7 |
7 files changed, 345 insertions, 92 deletions
@@ -1,4 +1,8 @@ +12/17/2003 - Ananth Mavinakayanahalli <ananth@in.ibm.com> + * Updated docs/libsysfs.txt for 0.4.0 + * Made some miscallaneous changes in library + 12/16/2003 - Daniel Stekloff <dsteklof@us.ibm.com> * Added sysfs_get_device_parent() function diff --git a/docs/libsysfs.txt b/docs/libsysfs.txt index 30c4e8c..66156e5 100644 --- a/docs/libsysfs.txt +++ b/docs/libsysfs.txt @@ -2,8 +2,8 @@ System Utilities sysfs Library - libsysfs ========================================= -Version: 0.3.0 -November 04, 2003 +Version: 0.4.0 +December 16, 2003 Contents -------- @@ -148,6 +148,13 @@ path length: #define SYSFS_BUS_ID_SIZE 20 +NOTE: + As of release 0.4.0 of libsysfs, a number of changes have been made + so that the dlists and "directory" references in all libsysfs's + structures are not populated until such time that it is absolutely + necessary. Hence, these elements may not contain valid data at all + times (as was the case before). + 5.1 Directory and Attribute Data Structures ------------------------------------------- @@ -171,9 +178,9 @@ struct sysfs_attribute { }; Path represents the file/attribute's full path. Value is used when reading -from or writing to an attribute. Len is the length of data in "value". Method -is a bitmask for defining if the attribute supports show(read) and/or -store(write). +from or writing to an attribute. "len" is the length of data in "value". +Method is a bitmask for defining if the attribute supports show(read) +and/or store(write). 5.1.2 Link Structure @@ -188,8 +195,8 @@ struct sysfs_link { unsigned char target[SYSFS_PATH_MAX]; }; -Link's name is stored in name and it's target stored in target. Absolute path -to the link is stored in path. +Link's name is stored in "name' and it's target stored in "target". Absolute +path to the link is stored in "path". 5.1.3 Directory Structure @@ -219,22 +226,22 @@ All buses look similar in sysfs including lists of devices and drivers, therefore we use the following structure to represent all sysfs buses: struct sysfs_bus { - struct dlist *drivers; - struct dlist *devices; unsigned char name[SYSFS_NAME_LEN]; unsigned char path[SYSFS_PATH_MAX]; /* internal use only */ + struct dlist *drivers; + struct dlist *devices; struct sysfs_directory *directory; }; -The sysfs_bus structure contains lists of those devices on the bus and their -drivers. The bus name, like "pci" or "usb", is stored in the name field, while -the "path" to bus directory is also stored. The bus' directory is represented +The sysfs_bus structure contains the bus "name", while the "path" to bus +directory is also stored. It also contains lists of devices on the bus +and drivers that are registered on it. The bus' directory is represented by the sysfs_directory structure and it contains references to all the -subdirectories, links, and attributes. The sysfs_directory structure is for -internal use only. The following functions may be used by applications to -retrieve data from the sysfs_directory structure: +subdirectories, links, and attributes. The sysfs_directory structure +is for internal use only. The following functions may be used by +applications to retrieve data from the sysfs_directory structure: struct dlist *sysfs_get_bus_attributes(struct sysfs_bus *bus) struct sysfs_attribute *sysfs_get_bus_attribute(struct sysfs_bus *bus, @@ -249,26 +256,27 @@ classes contains a class directory like "net" or "scsi_host" and then class devices like "eth0", "lo", or "eth1" for the "net" class. struct sysfs_class { - struct dlist *devices; unsigned char name[SYSFS_NAME_LEN]; unsigned char path[SYSFS_PATH_MAX]; /* for internal use only */ + struct dlist *devices; struct sysfs_directory *directory; }; -The sysfs_class represents device classes in sysfs like "net". It contains a -list of class devices, the class name, "path" to the class and the directory -representation (for internal use only). +The sysfs_class represents device classes in sysfs like "net". It contains +the class "name", "path" to the class, a list of class devices and the +directory representation (for internal use only). struct sysfs_class_device { - struct sysfs_device *sysdevice; /* NULL if virtual */ - struct sysfs_driver *driver; /* NULL if not implemented */ unsigned char name[SYSFS_NAME_LEN]; unsigned char classname[SYSFS_NAME_LEN]; unsigned char path[SYSFS_PATH_MAX]; /* for internal use only */ + struct sysfs_class_device *parent; + struct sysfs_device *sysdevice; /* NULL if virtual */ + struct sysfs_driver *driver; /* NULL if not implemented */ struct sysfs_directory *directory; }; @@ -276,9 +284,10 @@ A class device isn't the same as a sysfs_device, it's specific to the class in which it belongs. The class device structure contains the name of the class the class device belongs to, its sysfs_device reference and that device's driver reference (if any). It also contains the name of the class device -- like "eth0", its sysfs directory information including links and -attributes (for internal use only). The following function may be -used by applications to retrieve data from the sysfs_directory structure: +- like "eth0", its parent point (if present) and its sysfs directory +information including links and attributes (for internal use only). +The following function may be used by applications to retrieve data +from the sysfs_directory structure: struct dlist *sysfs_get_classdev_attributes(struct sysfs_class_device *cdev); @@ -291,11 +300,11 @@ structure. Sysfs devices typically spawn off from base devices which are represented by a sysfs_root_device. struct sysfs_root_device { - struct dlist *devices; unsigned char name[SYSFS_NAME_LEN]; unsigned char path[SYSFS_PATH_MAX]; /* for internal use only */ + struct dlist *devices; struct sysfs_directory *directory; }; @@ -312,8 +321,6 @@ The sysfs_device structure represents a system device that's exposed in sysfs under the /sys/devices directory structure. struct sysfs_device { - struct sysfs_device *parent; - struct dlist *children; unsigned char name[SYSFS_NAME_LEN]; unsigned char bus_id[SYSFS_NAME_LEN]; unsigned char bus[SYSFS_NAME_LEN]; @@ -321,6 +328,8 @@ struct sysfs_device { unsigned char path[SYSFS_PATH_MAX]; /* for internal use only */ + struct sysfs_device *parent; + struct dlist *children; struct sysfs_directory *directory; }; @@ -343,11 +352,11 @@ struct dlist *sysfs_get_device_attributes(struct sysfs_device *device) The sysfs_driver structure represents a device driver. struct sysfs_driver { - struct dlist *devices; unsigned char name[SYSFS_NAME_LEN]; unsigned char path[SYSFS_PATH_MAX]; /* for internal use only */ + struct dlist *devices; struct sysfs_directory *directory; }; @@ -470,6 +479,44 @@ Arguments: struct dlist *list List to be closed Prototype: void sysfs_close_list(struct dlist *list) ------------------------------------------------------------------------------- +------------------------------------------------------------------------------- +Name: sysfs_path_is_dir + +Description: Utility function to verify if a given path is to a directory. + +Arguments: unsigned char *path Path to verify + +Returns: 0 on success, 1 on error + - EINVAL for invalid arguments + +Prototype: int sysfs_path_is_dir(unsigned char *path) +------------------------------------------------------------------------------- + +------------------------------------------------------------------------------- +Name: sysfs_path_is_file + +Description: Utility function to verify if a given path is to a file. + +Arguments: unsigned char *path Path to verify + +Returns: 0 on success, 1 on error + - EINVAL for invalid arguments + +Prototype: int sysfs_path_is_file(unsigned char *path) +------------------------------------------------------------------------------- + +------------------------------------------------------------------------------- +Name: sysfs_path_is_link + +Description: Utility function to verify if a given path is to a link. + +Arguments: unsigned char *path Path to verify + +Returns: 0 on success, 1 on error + - EINVAL for invalid arguments + +Prototype: int sysfs_path_is_link(unsigned char *path) +------------------------------------------------------------------------------- 6.2 Filesystem Functions ------------------------ @@ -496,7 +543,7 @@ Returns: struct sysfs_attribute * with success. NULL with error. Errno will be set with error, returning - EINVAL for invalid arguments -Prototype: struct sysfs_attribute *sysfs_open_attribute +Prototype: struct sysfs_attribute *sysfs_open_attribute (const unsigned char *path) ------------------------------------------------------------------------------- @@ -511,6 +558,37 @@ Prototype: void sysfs_close_attribute(struct sysfs_attribute *sysattr) ------------------------------------------------------------------------------- ------------------------------------------------------------------------------- +Name: sysfs_read_dir_attributes + +Description: Reads the given sysfs_directory to create a list of attributes. + +Arguments: struct sysfs_directory *sysdir sysfs_directory whose + attributes to read + +Returns: struct dlist * of attributes on success + NULL with error. Errno will be set on error, returning EINVAL + for invalid arguments + +Prototype: struct dlist *sysfs_read_dir_attributes + (struct sysfs_directory *sysdir) +------------------------------------------------------------------------------- + +------------------------------------------------------------------------------- +Name: sysfs_refresh_attributes + +Description: Given a list of attributes, this function refreshes the values + of attributes in the list. + +Arguments: struct dlist *attrlist list of attributes to refresh + +Returns: 0 with success. + 1 with error. Errno will be set on error, returning EINVAL + for invalid arguments + +Prototype: int sysfs_refresh_attributes(struct dlist *attrlist) +------------------------------------------------------------------------------- + +------------------------------------------------------------------------------- Name: sysfs_read_attribute Description: Reads the supplied attribute. Since the maximum transfer @@ -639,6 +717,22 @@ Prototype: void sysfs_close_link(struct sysfs_link *ln) ------------------------------------------------------------------------------- ------------------------------------------------------------------------------- +Name: sysfs_read_dir_links + +Description: Reads the given sysfs_directory to create a list of links. + +Arguments: struct sysfs_directory *sysdir sysfs_directory whose + links to read + +Returns: struct dlist * of links with success + NULL with error. Errno will be set on error, returning EINVAL + for invalid arguments + +Prototype: struct dlist *sysfs_read_dir_links + (struct sysfs_directory *sysdir) +------------------------------------------------------------------------------- + +------------------------------------------------------------------------------- Name: sysfs_get_directory_link Description: Function walks the list of links for the given sysfs directory @@ -712,6 +806,22 @@ Prototype: void sysfs_close_directory(struct sysfs_directory *sysdir) ------------------------------------------------------------------------------- ------------------------------------------------------------------------------- +Name: sysfs_read_dir_subdirs + +Description: Reads the given sysfs_directory to create a list of subdirs. + +Arguments: struct sysfs_directory *sysdir sysfs_directory whose + subdirs have to be read + +Returns: struct dlist * of links with success + NULL with error. Errno will be set on error, returning EINVAL + for invalid arguments + +Prototype: struct dlist *sysfs_read_dir_subdirs + (struct sysfs_directory *sysdir) +------------------------------------------------------------------------------- + +------------------------------------------------------------------------------- Name: sysfs_read_directory Description: Read the supplied directory. Reading fills in the directory's @@ -790,7 +900,37 @@ Description: Function closes up the sysfs_bus structure including its Arguments: sysfs_bus *bus Bus structure to close -Prototype: void sysfs_close_bus(struct sysfs_bus *bus); +Prototype: void sysfs_close_bus(struct sysfs_bus *bus) +------------------------------------------------------------------------------- + +------------------------------------------------------------------------------- +Name: sysfs_get_bus_devices + +Description: Function returns a list of devices that are registered with + this bus. + +Arguments: struct sysfs_bus *bus Bus whose devices list to return + +Returns: struct dlist * of sysfs_devices on success + NULL with error. Errno will be sent with error, returning + - EINVAL for invalid arguments + +Prototype: struct dlist *sysfs_get_bus_devices(struct sysfs_bus *bus) +------------------------------------------------------------------------------- + +------------------------------------------------------------------------------- +Name: sysfs_get_bus_drivers + +Description: Function returns a list of drivers that are registered with + this bus. + +Arguments: struct sysfs_bus *bus Bus whose drivers list to return + +Returns: struct dlist * of sysfs_drivers on success + NULL with error. Errno will be sent with error, returning + - EINVAL for invalid arguments + +Prototype: struct dlist *sysfs_get_bus_drivers(struct sysfs_bus *bus) ------------------------------------------------------------------------------- ------------------------------------------------------------------------------- @@ -991,6 +1131,21 @@ Prototype: struct sysfs_class_device *sysfs_get_class_device ------------------------------------------------------------------------------- ------------------------------------------------------------------------------- +Name: sysfs_get_class_devices + +Description: Function returns a list of class devices for the given class. + +Arguments: struct sysfs_class *cls Class whose class device list + is required + +Returns: struct dlist * of sysfs_class_devices on success + NULL with error. Errno will be set with error, returning + - EINVAL for invalid arguments + +Prototype: struct dlist *sysfs_get_class_devices(struct sysfs_class *cls) +------------------------------------------------------------------------------- + +------------------------------------------------------------------------------- Name: sysfs_open_class_device Description: Given the name of the class on which to look for, this function @@ -1016,6 +1171,60 @@ Prototype: struct sysfs_class_device *sysfs_open_class_device ------------------------------------------------------------------------------- ------------------------------------------------------------------------------- +Name: sysfs_get_classdev_device + +Description: Function returns the sysfs_device reference (if present) for the + given class device. + +Arguments: struct sysfs_class_device *clsdev Class device whose + sysfs_device reference + is required + +Returns: struct sysfs_device * on success + NULL with error. Errno will be set with error, returning + - EINVAL for invalid arguments + +Prototype: struct sysfs_device *sysfs_get_classdev_device + (struct sysfs_class_device *clsdev) +------------------------------------------------------------------------------- + +------------------------------------------------------------------------------- +Name: sysfs_get_classdev_driver + +Description: Function returns the sysfs_driver reference (if present) for the + given class device. + +Arguments: struct sysfs_class_device *clsdev Class device whose + sysfs_driver reference + is required + +Returns: struct sysfs_driver * on success + NULL with error. Errno will be set with error, returning + - EINVAL for invalid arguments + +Prototype: struct sysfs_driver *sysfs_get_classdev_driver + (struct sysfs_class_device *clsdev) +------------------------------------------------------------------------------- + +------------------------------------------------------------------------------- +Name: sysfs_get_classdev_parent + +Description: Function returns the sysfs_class_device reference for the parent + (if present) of the given class device. + +Arguments: struct sysfs_class_device *clsdev Class device whose + parent reference + is required + +Returns: struct sysfs_class_device * on success + NULL with error. Errno will be set with error, returning + - EINVAL for invalid arguments + +Prototype: struct sysfs_class_device *sysfs_get_classdev_parent + (struct sysfs_class_device *clsdev) +------------------------------------------------------------------------------- + +------------------------------------------------------------------------------- Name: sysfs_get_classdev_attributes Description: Function takes a sysfs_class_device structure and returns a list @@ -1139,6 +1348,39 @@ Prototype: void sysfs_close_root_device(struct sysfs_root_device *root) ------------------------------------------------------------------------------- ------------------------------------------------------------------------------- +Name: sysfs_get_device_parent + +Description: Function returns the sysfs_device reference for the parent + (if present) of the given sysfs_device. + +Arguments: struct sysfs_device *dev sysfs_device whose parent + reference is required + +Returns: struct sysfs_device * on success + NULL with error. Errno will be set with error, returning + - EINVAL for invalid arguments + +Prototype: struct sysfs_device *sysfs_get_device_parent + (struct sysfs_device *dev) +------------------------------------------------------------------------------- + +------------------------------------------------------------------------------- +Name: sysfs_get_root_devices + +Description: Function returns a list of devices under the given root device. + +Arguments: struct sysfs_root_device *root sysfs_root_device whose devices + list is required + +Returns: struct dlist * of sysfs_devices on success + NULL with error. Errno will be set with error, returning + - EINVAL for invalid arguments + +Prototype: struct dlist *sysfs_get_root_devices + (struct sysfs_root_device *root) +------------------------------------------------------------------------------- + +------------------------------------------------------------------------------- Name: sysfs_get_device_attr Description: Searches supplied device's attributes by name and returns @@ -1179,13 +1421,6 @@ Description: Given the name of the bus on which to look for, this function locates a given device and returns a sysfs_device structure corresponding to the requested device. - NOTE: - 1. The sysfs_device structure obtained upon successful return - from this function has to be closed by calling - sysfs_close_device(). - 2. Bus on which to look for this device should be known prior - to calling this function. - Arguments: const unsigned char *bus_id Device to look for const unsigned char *bus Bus on which to search @@ -1255,6 +1490,39 @@ Prototype: void sysfs_close_driver(struct sysfs_driver *driver) ------------------------------------------------------------------------------- ------------------------------------------------------------------------------- +Name: sysfs_get_driver_devices + +Description: Function returns a list of devices that use this driver. + +Arguments: struct sysfs_driver *driver Driver whose devices list is + required + +Returns: struct dlist * of sysfs_devices on success + NULL with error. Errno will be set with error, returning + - EINVAL for invalid arguments + +Prototype: struct dlist *sysfs_get_driver_devices + (struct sysfs_driver *driver) +------------------------------------------------------------------------------- + +------------------------------------------------------------------------------- +Name: sysfs_get_driver_device + +Description: Function returns a sysfs_device reference for the device with + "name" that uses this driver + +Arguments: struct sysfs_driver *driver Driver on which to search + const unsigned char *name Name of the device to look for + +Returns: struct sysfs_device * corresponding to "name" on success + NULL with error. Errno will be set with error, returning + - EINVAL for invalid arguments + +Prototype: struct dlist *sysfs_get_driver_device + (struct sysfs_driver *driver, const unsigned char *name) +------------------------------------------------------------------------------- + +------------------------------------------------------------------------------- Name: sysfs_get_driver_attr Description: Searches supplied driver's attributes by name and returns @@ -1317,17 +1585,6 @@ Prototype: struct sysfs_driver *sysfs_open_driver ------------------------------------------------------------------------------- ------------------------------------------------------------------------------- -Name: sysfs_close_driver_by_name - -Description: Function closes a sysfs_driver structure got upon a successful - call to sysfs_open_driver_by_name(). - -Arguments: struct sysfs_drive *driver Driver to close - -Prototype: void sysfs_close_driver_by_name(struct sysfs_driver *driver) -------------------------------------------------------------------------------- - -------------------------------------------------------------------------------- Name: sysfs_get_driver_links Description: Function returns a list of links for a given driver diff --git a/include/libsysfs.h b/include/libsysfs.h index 7e7eea5..64efd7b 100644 --- a/include/libsysfs.h +++ b/include/libsysfs.h @@ -184,8 +184,6 @@ extern void sysfs_close_driver(struct sysfs_driver *driver); 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); diff --git a/lib/sysfs_class.c b/lib/sysfs_class.c index c71e412..12f505f 100644 --- a/lib/sysfs_class.c +++ b/lib/sysfs_class.c @@ -578,12 +578,12 @@ struct sysfs_attribute *sysfs_get_classdev_attr * subdirs since class devices can have subdirs of attributes. */ attrlist = sysfs_get_classdev_attributes(clsdev); - if (attrlist == NULL) - return NULL; - cur = sysfs_get_directory_attribute(clsdev->directory, + if (attrlist != NULL) { + cur = sysfs_get_directory_attribute(clsdev->directory, (unsigned char *)name); - if (cur != NULL) - return cur; + if (cur != NULL) + return cur; + } if (clsdev->directory->subdirs == NULL) if ((sysfs_read_dir_subdirs(clsdev->directory)) != 0 || @@ -593,14 +593,20 @@ struct sysfs_attribute *sysfs_get_classdev_attr 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 ((sysfs_path_is_dir(sdir->path)) != 0) + continue; + if (sdir->attributes == NULL) { + cur = sysfs_get_directory_attribute(sdir, + (unsigned char *)name); + } else { + if ((sysfs_refresh_attributes + (sdir->attributes)) == 0) + cur = sysfs_get_directory_attribute(sdir, + (unsigned char *)name); + } } } - - return NULL; + return cur; } /** diff --git a/lib/sysfs_device.c b/lib/sysfs_device.c index 9a7a75f..333063a 100644 --- a/lib/sysfs_device.c +++ b/lib/sysfs_device.c @@ -417,10 +417,8 @@ struct sysfs_attribute *sysfs_get_device_attr(struct sysfs_device *dev, cur = sysfs_get_directory_attribute(dev->directory, (unsigned char *)name); - if (cur != NULL) - return cur; - return NULL; + return cur; } /** diff --git a/lib/sysfs_dir.c b/lib/sysfs_dir.c index 83b318d..7e8eb25 100644 --- a/lib/sysfs_dir.c +++ b/lib/sysfs_dir.c @@ -147,7 +147,7 @@ struct sysfs_attribute *sysfs_open_attribute(const unsigned char *path) sysfs_close_attribute(sysattr); return NULL; } - strncpy(sysattr->path, path, sizeof(sysattr->path)); + strncpy(sysattr->path, path, SYSFS_PATH_MAX); if ((stat(sysattr->path, &fileinfo)) != 0) { dprintf("Stat failed: No such attribute?\n"); sysattr->method = 0; @@ -474,7 +474,7 @@ struct sysfs_directory *sysfs_open_directory(const unsigned char *path) sysfs_close_directory(sdir); return NULL; } - strncpy(sdir->path, path, sizeof(sdir->path)); + strncpy(sdir->path, path, SYSFS_PATH_MAX); return sdir; } @@ -648,9 +648,9 @@ int sysfs_read_dir_attributes(struct sysfs_directory *sysdir) if (0 == strcmp(dirent->d_name, "..")) continue; memset(file_path, 0, SYSFS_PATH_MAX); - strncpy(file_path, sysdir->path, sizeof(file_path)); - strncat(file_path, "/", sizeof(file_path)); - strncat(file_path, dirent->d_name, sizeof(file_path)); + strncpy(file_path, sysdir->path, SYSFS_PATH_MAX); + strcat(file_path, "/"); + strcat(file_path, dirent->d_name); if ((lstat(file_path, &astats)) != 0) { dprintf("stat failed\n"); continue; @@ -690,9 +690,9 @@ int sysfs_read_dir_links(struct sysfs_directory *sysdir) if (0 == strcmp(dirent->d_name, "..")) continue; memset(file_path, 0, SYSFS_PATH_MAX); - strncpy(file_path, sysdir->path, sizeof(file_path)); - strncat(file_path, "/", sizeof(file_path)); - strncat(file_path, dirent->d_name, sizeof(file_path)); + strncpy(file_path, sysdir->path, SYSFS_PATH_MAX); + strcat(file_path, "/"); + strcat(file_path, dirent->d_name); if ((lstat(file_path, &astats)) != 0) { dprintf("stat failed\n"); continue; @@ -735,9 +735,9 @@ int sysfs_read_dir_subdirs(struct sysfs_directory *sysdir) if (0 == strcmp(dirent->d_name, "..")) continue; memset(file_path, 0, SYSFS_PATH_MAX); - strncpy(file_path, sysdir->path, sizeof(file_path)); - strncat(file_path, "/", sizeof(file_path)); - strncat(file_path, dirent->d_name, sizeof(file_path)); + strncpy(file_path, sysdir->path, SYSFS_PATH_MAX); + strcat(file_path, "/"); + strcat(file_path, dirent->d_name); if ((lstat(file_path, &astats)) != 0) { dprintf("stat failed\n"); continue; @@ -777,9 +777,9 @@ int sysfs_read_directory(struct sysfs_directory *sysdir) if (0 == strcmp(dirent->d_name, "..")) continue; memset(file_path, 0, SYSFS_PATH_MAX); - strncpy(file_path, sysdir->path, sizeof(file_path)); - strncat(file_path, "/", sizeof(file_path)); - strncat(file_path, dirent->d_name, sizeof(file_path)); + strncpy(file_path, sysdir->path, SYSFS_PATH_MAX); + strcat(file_path, "/"); + strcat(file_path, dirent->d_name); if ((lstat(file_path, &astats)) != 0) { dprintf("stat failed\n"); continue; @@ -822,13 +822,7 @@ struct sysfs_attribute *sysfs_get_directory_attribute attr = (struct sysfs_attribute *)dlist_find_custom (dir->attributes, attrname, dir_attribute_name_equal); - if (attr != NULL) { - /* - * don't read here since we would have read the attribute in - * in the routine that called this routine - */ - return attr; - } else { + if (attr == NULL) { memset(new_path, 0, SYSFS_PATH_MAX); strcpy(new_path, dir->path); strcat(new_path, "/"); @@ -839,10 +833,9 @@ struct sysfs_attribute *sysfs_get_directory_attribute dlist_find_custom(dir->attributes, attrname, dir_attribute_name_equal); } - return attr; } } - return NULL; + return attr; } /** diff --git a/lib/sysfs_driver.c b/lib/sysfs_driver.c index 1fd560e..8b85aa7 100644 --- a/lib/sysfs_driver.c +++ b/lib/sysfs_driver.c @@ -162,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; } /** |