summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormananth <mananth>2003-12-26 04:27:00 +0000
committermananth <mananth>2003-12-26 04:27:00 +0000
commit3350196531cb367b5c10a869a0d78ef6558d74de (patch)
tree4370b28d27eded6201c1dbaaa5d3eb1e41ec8ecf
parent5d6832c5b67a00f773fa83b71c7096475003a6cb (diff)
downloadsysfsutils-3350196531cb367b5c10a869a0d78ef6558d74de.tar.gz
Removed unneeded functions and added API to retrieve subdirs, links and attribs
-rw-r--r--ChangeLog4
-rw-r--r--include/libsysfs.h21
-rw-r--r--lib/sysfs_device.c8
-rw-r--r--lib/sysfs_dir.c77
-rw-r--r--lib/sysfs_utils.c1
5 files changed, 94 insertions, 17 deletions
diff --git a/ChangeLog b/ChangeLog
index c994197..717332b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,8 @@
+12/26/2003 - Daniel Stekloff <dsteklof@us.ibm.com>
+ * Removed unneeded functions
+ * Added APIs to get directory links, subdirs and attribs
+
12/17/2003 - Ananth Mavinakayanahalli <ananth@in.ibm.com>
* Updated docs/libsysfs.txt for 0.4.0
* Made some miscallaneous changes in library
diff --git a/include/libsysfs.h b/include/libsysfs.h
index 64efd7b..b49bd58 100644
--- a/include/libsysfs.h
+++ b/include/libsysfs.h
@@ -62,18 +62,20 @@ struct sysfs_link {
};
struct sysfs_directory {
+ unsigned char name[SYSFS_NAME_LEN];
+ unsigned char path[SYSFS_PATH_MAX];
+
+ /* Private: for internal use only */
struct dlist *subdirs;
struct dlist *links;
struct dlist *attributes;
- unsigned char name[SYSFS_NAME_LEN];
- unsigned char path[SYSFS_PATH_MAX];
};
struct sysfs_driver {
unsigned char name[SYSFS_NAME_LEN];
unsigned char path[SYSFS_PATH_MAX];
- /* for internal use only */
+ /* Private: for internal use only */
struct dlist *devices;
struct sysfs_directory *directory;
};
@@ -85,7 +87,7 @@ struct sysfs_device {
unsigned char driver_name[SYSFS_NAME_LEN];
unsigned char path[SYSFS_PATH_MAX];
- /* for internal use only */
+ /* Private: for internal use only */
struct sysfs_device *parent;
struct dlist *children;
struct sysfs_directory *directory;
@@ -95,7 +97,7 @@ struct sysfs_root_device {
unsigned char name[SYSFS_NAME_LEN];
unsigned char path[SYSFS_PATH_MAX];
- /* for internal use only */
+ /* Private: for internal use only */
struct dlist *devices;
struct sysfs_directory *directory;
};
@@ -104,7 +106,7 @@ struct sysfs_bus {
unsigned char name[SYSFS_NAME_LEN];
unsigned char path[SYSFS_PATH_MAX];
- /* internal use only */
+ /* Private: for internal use only */
struct dlist *drivers;
struct dlist *devices;
struct sysfs_directory *directory;
@@ -115,7 +117,7 @@ struct sysfs_class_device {
unsigned char classname[SYSFS_NAME_LEN];
unsigned char path[SYSFS_PATH_MAX];
- /* for internal use only */
+ /* Private: for internal use only */
struct sysfs_class_device *parent;
struct sysfs_device *sysdevice; /* NULL if virtual */
struct sysfs_driver *driver; /* NULL if not implemented */
@@ -126,7 +128,7 @@ struct sysfs_class {
unsigned char name[SYSFS_NAME_LEN];
unsigned char path[SYSFS_PATH_MAX];
- /* for internal use only */
+ /* Private: for internal use only */
struct dlist *devices;
struct sysfs_directory *directory;
};
@@ -178,6 +180,9 @@ extern struct sysfs_link *sysfs_get_subdirectory_link
(struct sysfs_directory *dir, unsigned char *linkname);
extern struct sysfs_attribute *sysfs_get_directory_attribute
(struct sysfs_directory *dir, unsigned char *attrname);
+extern struct dlist *sysfs_get_dir_attributes(struct sysfs_directory *dir);
+extern struct dlist *sysfs_get_dir_links(struct sysfs_directory *dir);
+extern struct dlist *sysfs_get_dir_subdirs(struct sysfs_directory *dir);
/* sysfs driver access */
extern void sysfs_close_driver(struct sysfs_driver *driver);
diff --git a/lib/sysfs_device.c b/lib/sysfs_device.c
index 333063a..4834155 100644
--- a/lib/sysfs_device.c
+++ b/lib/sysfs_device.c
@@ -105,14 +105,6 @@ static void sysfs_close_device_tree(struct sysfs_device *devroot)
}
/**
- * sysfs_del_device: routine for dlist integration
- */
-static void sysfs_del_device(void *dev)
-{
- sysfs_close_device((struct sysfs_device *)dev);
-}
-
-/**
* sysfs_close_dev_tree: routine for dlist integration
*/
static void sysfs_close_dev_tree(void *dev)
diff --git a/lib/sysfs_dir.c b/lib/sysfs_dir.c
index 7e8eb25..7f2afb4 100644
--- a/lib/sysfs_dir.c
+++ b/lib/sysfs_dir.c
@@ -464,6 +464,13 @@ struct sysfs_directory *sysfs_open_directory(const unsigned char *path)
errno = EINVAL;
return NULL;
}
+
+ if (sysfs_path_is_dir(path) != 0) {
+ dprintf("Invalid path directory %s\n", path);
+ errno = EINVAL;
+ return NULL;
+ }
+
sdir = alloc_directory();
if (sdir == NULL) {
dprintf("Error allocating directory %s\n", path);
@@ -936,3 +943,73 @@ struct sysfs_link *sysfs_get_subdirectory_link(struct sysfs_directory *dir,
}
return NULL;
}
+
+/**
+ * sysfs_get_dir_attributes: returns dlist of directory attributes
+ * @dir: directory to retrieve attributes from
+ * returns dlist of attributes or NULL
+ */
+struct dlist *sysfs_get_dir_attributes(struct sysfs_directory *dir)
+{
+ if (dir == NULL) {
+ errno = EINVAL;
+ return NULL;
+ }
+
+ if (dir->attributes == NULL) {
+ if (sysfs_read_dir_attributes(dir) != 0)
+ return NULL;
+ } else {
+ if (sysfs_path_is_dir(dir->path) != 0) {
+ dprintf("Directory at %s no longer exists\n",
+ dir->path);
+ return NULL;
+ }
+ if (sysfs_refresh_attributes(dir->attributes) != 0) {
+ dprintf("Error refreshing attributes at %s\n",
+ dir->path);
+ return NULL;
+ }
+ }
+ return (dir->attributes);
+}
+
+/**
+ * sysfs_get_dir_links: returns dlist of directory links
+ * @dir: directory to return links for
+ * returns dlist of links or NULL
+ */
+struct dlist *sysfs_get_dir_links(struct sysfs_directory *dir)
+{
+ if (dir == NULL) {
+ errno = EINVAL;
+ return NULL;
+ }
+
+ if (dir->links == NULL) {
+ if (sysfs_read_dir_links(dir) != 0)
+ return NULL;
+ }
+
+ return (dir->links);
+}
+
+/**
+ * sysfs_get_dir_subdirs: returns dlist of directory subdirectories
+ * @dir: directory to return subdirs for
+ * returns dlist of subdirs or NULL
+ */
+struct dlist *sysfs_get_dir_subdirs(struct sysfs_directory *dir)
+{
+ if (dir == NULL) {
+ errno = EINVAL;
+ return NULL;
+ }
+
+ if (dir->subdirs == NULL) {
+ if (sysfs_read_dir_subdirs(dir) != 0)
+ return NULL;
+ }
+
+ return (dir->subdirs);
+}
diff --git a/lib/sysfs_utils.c b/lib/sysfs_utils.c
index 5f2c9e3..b10dedc 100644
--- a/lib/sysfs_utils.c
+++ b/lib/sysfs_utils.c
@@ -212,7 +212,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;