diff options
author | dsteklof@us.ibm.com <dsteklof@us.ibm.com> | 2003-12-19 18:29:10 -0800 |
---|---|---|
committer | Greg KH <gregkh@suse.de> | 2005-04-26 21:13:09 -0700 |
commit | bcbe2d8e7d4ccd975e79d0c7defbe1d64d1b129c (patch) | |
tree | 78cc968183dc45e80f96133e4cb1a1c94ca461bd /libsysfs/sysfs_class.c | |
parent | 7591c18a8f3460d3e7cab85d02915c4b51638b5c (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_class.c')
-rw-r--r-- | libsysfs/sysfs_class.c | 80 |
1 files changed, 46 insertions, 34 deletions
diff --git a/libsysfs/sysfs_class.c b/libsysfs/sysfs_class.c index 169600d5fd..16eaf6e514 100644 --- a/libsysfs/sysfs_class.c +++ b/libsysfs/sysfs_class.c @@ -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; @@ -184,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(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; } @@ -223,7 +226,6 @@ struct sysfs_class *sysfs_open_class(const unsigned char *name) dprintf("Sysfs not supported on this system\n"); return NULL; } - if (sysfs_trailing_slash(classpath) == 0) strcat(classpath, "/"); @@ -307,7 +309,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) @@ -343,7 +345,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; @@ -401,7 +403,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); @@ -482,7 +484,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 @@ -490,7 +492,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]; @@ -509,7 +511,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); @@ -572,32 +574,41 @@ struct sysfs_attribute *sysfs_get_classdev_attr errno = EINVAL; return NULL; } + /* * First, see if it's in the current directory. Then look at * 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 || clsdev->directory->subdirs == NULL) return 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 (clsdev->directory->subdirs != NULL) { + dlist_for_each_data(clsdev->directory->subdirs, sdir, + struct sysfs_directory) { + 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; } /** @@ -643,3 +654,4 @@ struct sysfs_attribute *sysfs_open_classdev_attr(const unsigned char *classname, } return attribute; } + |