summaryrefslogtreecommitdiff
path: root/libsysfs/sysfs_utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'libsysfs/sysfs_utils.c')
-rw-r--r--libsysfs/sysfs_utils.c73
1 files changed, 71 insertions, 2 deletions
diff --git a/libsysfs/sysfs_utils.c b/libsysfs/sysfs_utils.c
index 627e618dce..c2ce13433d 100644
--- a/libsysfs/sysfs_utils.c
+++ b/libsysfs/sysfs_utils.c
@@ -280,7 +280,7 @@ struct dlist *sysfs_open_subsystem_list(unsigned char *name)
* name requested here is "class", verify if "block" is supported on
* this system and return the same.
*/
- if (strcmp(name, SYSFS_CLASS_DIR) == 0) {
+ if (strcmp(name, SYSFS_CLASS_NAME) == 0) {
c = strstr(sysfs_path, SYSFS_CLASS_NAME);
if (c == NULL)
goto out;
@@ -325,7 +325,8 @@ struct dlist *sysfs_open_bus_devices_list(unsigned char *name)
strcat(sysfs_path, SYSFS_BUS_NAME);
strcat(sysfs_path, "/");
strcat(sysfs_path, name);
- strcat(sysfs_path, SYSFS_DEVICES_DIR);
+ strcat(sysfs_path, "/");
+ strcat(sysfs_path, SYSFS_DEVICES_NAME);
dir = sysfs_open_directory(sysfs_path);
if (dir == NULL) {
dprintf("Error opening sysfs_directory at %s\n", sysfs_path);
@@ -358,3 +359,71 @@ struct dlist *sysfs_open_bus_devices_list(unsigned char *name)
return list;
}
+/**
+ * sysfs_path_is_dir: Check if the path supplied points to a directory
+ * @path: path to validate
+ * Returns 0 if path points to dir, 1 otherwise
+ */
+int sysfs_path_is_dir(const unsigned char *path)
+{
+ struct stat astats;
+
+ if (path == NULL) {
+ errno = EINVAL;
+ return 1;
+ }
+ if ((lstat(path, &astats)) != 0) {
+ dprintf("stat() failed\n");
+ return 1;
+ }
+ if (S_ISDIR(astats.st_mode))
+ return 0;
+
+ return 1;
+}
+
+/**
+ * sysfs_path_is_link: Check if the path supplied points to a link
+ * @path: path to validate
+ * Returns 0 if path points to link, 1 otherwise
+ */
+int sysfs_path_is_link(const unsigned char *path)
+{
+ struct stat astats;
+
+ if (path == NULL) {
+ errno = EINVAL;
+ return 1;
+ }
+ if ((lstat(path, &astats)) != 0) {
+ dprintf("stat() failed\n");
+ return 1;
+ }
+ if (S_ISLNK(astats.st_mode))
+ return 0;
+
+ return 1;
+}
+
+/**
+ * sysfs_path_is_file: Check if the path supplied points to a file
+ * @path: path to validate
+ * Returns 0 if path points to file, 1 otherwise
+ */
+int sysfs_path_is_file(const unsigned char *path)
+{
+ struct stat astats;
+
+ if (path == NULL) {
+ errno = EINVAL;
+ return 1;
+ }
+ if ((lstat(path, &astats)) != 0) {
+ dprintf("stat() failed\n");
+ return 1;
+ }
+ if (S_ISREG(astats.st_mode))
+ return 0;
+
+ return 1;
+}