summaryrefslogtreecommitdiff
path: root/libsysfs/sysfs_dir.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_dir.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_dir.c')
-rw-r--r--libsysfs/sysfs_dir.c71
1 files changed, 31 insertions, 40 deletions
diff --git a/libsysfs/sysfs_dir.c b/libsysfs/sysfs_dir.c
index ac2ecfcbe1..7dbee8aba8 100644
--- a/libsysfs/sysfs_dir.c
+++ b/libsysfs/sysfs_dir.c
@@ -1,5 +1,5 @@
/*
- * syfs_dir.c
+ * sysfs_dir.c
*
* Directory utility functions for libsysfs
*
@@ -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;
@@ -260,7 +260,7 @@ int sysfs_read_attribute(struct sysfs_attribute *sysattr)
{
unsigned char *fbuf = NULL;
unsigned char *vbuf = NULL;
- size_t length = 0;
+ ssize_t length = 0;
long pgsize = 0;
int fd;
@@ -441,13 +441,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_dir_subdirs(cursub)) != 0)
+ dprintf ("Error reading subdirectory %s\n",
+ cursub->name);
+ }
}
return 0;
}
@@ -476,7 +478,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;
}
@@ -527,7 +529,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", attr->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);
@@ -540,12 +543,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;
}
@@ -655,9 +652,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;
@@ -697,9 +694,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;
@@ -742,9 +739,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;
@@ -784,9 +781,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;
@@ -829,26 +826,20 @@ 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, "/");
strcat(new_path, attrname);
if ((sysfs_path_is_file(new_path)) == 0) {
if ((add_attribute(dir, new_path)) == 0) {
- attr = (struct sysfs_attribute *)dlist_find_custom
- (dir->attributes, attrname, dir_attribute_name_equal);
+ attr = (struct sysfs_attribute *)
+ dlist_find_custom(dir->attributes,
+ attrname, dir_attribute_name_equal);
}
- return attr;
}
}
- return NULL;
+ return attr;
}
/**