summaryrefslogtreecommitdiff
path: root/libsysfs/sysfs_utils.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_utils.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_utils.c')
-rw-r--r--libsysfs/sysfs_utils.c26
1 files changed, 12 insertions, 14 deletions
diff --git a/libsysfs/sysfs_utils.c b/libsysfs/sysfs_utils.c
index c2ce13433d..009ae94efa 100644
--- a/libsysfs/sysfs_utils.c
+++ b/libsysfs/sysfs_utils.c
@@ -1,5 +1,5 @@
/*
- * syfs_utils.c
+ * sysfs_utils.c
*
* System utility functions for libsysfs
*
@@ -135,17 +135,21 @@ int sysfs_get_name_from_path(const unsigned char *path, unsigned char *name,
}
memset(tmp, 0, SYSFS_PATH_MAX);
strcpy(tmp, path);
- n = &tmp[strlen(tmp)-1];
- if (strncmp(n, "/", 1) == 0)
- *n = '\0';
n = strrchr(tmp, '/');
if (n == NULL) {
errno = EINVAL;
return -1;
}
+ if (*(n+1) == '\0') {
+ *n = '\0';
+ n = strrchr(tmp, '/');
+ if (n == NULL) {
+ errno = EINVAL;
+ return -1;
+ }
+ }
n++;
strncpy(name, n, len);
-
return 0;
}
@@ -233,7 +237,6 @@ struct dlist *sysfs_open_subsystem_list(unsigned char *name)
unsigned char *c = NULL;
struct sysfs_directory *dir = NULL, *cur = NULL;
struct dlist *list = NULL;
- struct stat astats;
if (name == NULL)
return NULL;
@@ -242,7 +245,6 @@ struct dlist *sysfs_open_subsystem_list(unsigned char *name)
dprintf("Error getting sysfs mount point\n");
return NULL;
}
-
if (sysfs_trailing_slash(sysfs_path) == 0)
strcat(sysfs_path, "/");
strcat(sysfs_path, name);
@@ -252,7 +254,7 @@ struct dlist *sysfs_open_subsystem_list(unsigned char *name)
return NULL;
}
- if (sysfs_read_directory(dir) != 0) {
+ if ((sysfs_read_dir_subdirs(dir)) != 0) {
dprintf("Error reading sysfs_directory at %s\n", sysfs_path);
sysfs_close_directory(dir);
return NULL;
@@ -285,11 +287,7 @@ struct dlist *sysfs_open_subsystem_list(unsigned char *name)
if (c == NULL)
goto out;
strcpy(c, SYSFS_BLOCK_NAME);
- if ((lstat(sysfs_path, &astats)) != 0) {
- dprintf("stat() failed\n");
- goto out;
- }
- if (S_ISDIR(astats.st_mode)) {
+ if ((sysfs_path_is_dir(sysfs_path)) == 0) {
subsys_name = (char *)calloc(1, SYSFS_NAME_LEN);
strcpy(subsys_name, SYSFS_BLOCK_NAME);
dlist_unshift(list, subsys_name);
@@ -333,7 +331,7 @@ struct dlist *sysfs_open_bus_devices_list(unsigned char *name)
return NULL;
}
- if (sysfs_read_directory(dir) != 0) {
+ if ((sysfs_read_dir_links(dir)) != 0) {
dprintf("Error reading sysfs_directory at %s\n", sysfs_path);
sysfs_close_directory(dir);
return NULL;