4 * Directory utility functions for libsysfs
6 * Copyright (C) IBM Corp. 2003
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "sysfs/libsysfs.h"
27 * sysfs_del_attribute: routine for dlist integration
29 static void sysfs_del_attribute(void *attr)
31 sysfs_close_attribute((struct sysfs_attribute *)attr);
35 * sysfs_del_link: routine for dlist integration
37 static void sysfs_del_link(void *ln)
39 sysfs_close_link((struct sysfs_link *)ln);
43 * sysfs_del_dir: routine for dlist integration
45 static void sysfs_del_directory(void *dir)
47 sysfs_close_directory((struct sysfs_directory *)dir);
51 * dir_attribute_name_equal: compares dir attributes by name
52 * @a: attribute name for comparison
53 * @b: sysfs_attribute to be compared.
54 * returns 1 if a==b->name or 0 if not equal
56 static int dir_attribute_name_equal(void *a, void *b)
58 if (a == NULL || b == NULL)
61 if (strcmp(((char *)a), ((struct sysfs_attribute *)b)->name) == 0)
68 * dir_link_name_equal: compares dir links by name
69 * @a: link name for comparison
70 * @b: sysfs_link to be compared.
71 * returns 1 if a==b->name or 0 if not equal
73 static int dir_link_name_equal(void *a, void *b)
75 if (a == NULL || b == NULL)
78 if (strcmp(((char *)a), ((struct sysfs_link *)b)->name) == 0)
85 * dir_subdir_name_equal: compares subdirs by name
86 * @a: name of subdirectory to compare
87 * @b: sysfs_directory subdirectory to be compared
88 * returns 1 if a==b->name or 0 if not equal
90 static int dir_subdir_name_equal(void *a, void *b)
92 if (a == NULL || b == NULL)
95 if (strcmp(((char *)a), ((struct sysfs_directory *)b)->name) == 0)
102 * sysfs_close_attribute: closes and cleans up attribute
103 * @sysattr: attribute to close.
105 void sysfs_close_attribute(struct sysfs_attribute *sysattr)
107 if (sysattr != NULL) {
108 if (sysattr->value != NULL)
109 free(sysattr->value);
115 * alloc_attribute: allocates and initializes attribute structure
116 * returns struct sysfs_attribute with success and NULL with error.
118 static struct sysfs_attribute *alloc_attribute(void)
120 return (struct sysfs_attribute *)
121 calloc(1, sizeof(struct sysfs_attribute));
125 * sysfs_open_attribute: creates sysfs_attribute structure
126 * @path: path to attribute.
127 * returns sysfs_attribute struct with success and NULL with error.
129 struct sysfs_attribute *sysfs_open_attribute(const char *path)
131 struct sysfs_attribute *sysattr = NULL;
132 struct stat fileinfo;
138 sysattr = alloc_attribute();
139 if (sysattr == NULL) {
140 dprintf("Error allocating attribute at %s\n", path);
143 if (sysfs_get_name_from_path(path, sysattr->name,
144 SYSFS_NAME_LEN) != 0) {
145 dprintf("Error retrieving attrib name from path: %s\n", path);
146 sysfs_close_attribute(sysattr);
149 safestrcpy(sysattr->path, path);
150 if ((stat(sysattr->path, &fileinfo)) != 0) {
151 dprintf("Stat failed: No such attribute?\n");
156 if (fileinfo.st_mode & S_IRUSR)
157 sysattr->method |= SYSFS_METHOD_SHOW;
158 if (fileinfo.st_mode & S_IWUSR)
159 sysattr->method |= SYSFS_METHOD_STORE;
166 * sysfs_write_attribute: write value to the attribute
167 * @sysattr: attribute to write
168 * @new_value: value to write
169 * @len: length of "new_value"
170 * returns 0 with success and -1 with error.
172 int sysfs_write_attribute(struct sysfs_attribute *sysattr,
173 const char *new_value, size_t len)
178 if (sysattr == NULL || new_value == NULL || len == 0) {
183 if (!(sysattr->method & SYSFS_METHOD_STORE)) {
184 dprintf ("Store method not supported for attribute %s\n",
189 if (sysattr->method & SYSFS_METHOD_SHOW) {
191 * read attribute again to see if we can get an updated value
193 if ((sysfs_read_attribute(sysattr)) != 0) {
194 dprintf("Error reading attribute\n");
197 if ((strncmp(sysattr->value, new_value, sysattr->len)) == 0) {
198 dprintf("Attr %s already has the requested value %s\n",
199 sysattr->name, new_value);
204 * open O_WRONLY since some attributes have no "read" but only
207 if ((fd = open(sysattr->path, O_WRONLY)) < 0) {
208 dprintf("Error reading attribute %s\n", sysattr->path);
212 length = write(fd, new_value, len);
214 dprintf("Error writing to the attribute %s - invalid value?\n",
218 } else if ((unsigned int)length != len) {
219 dprintf("Could not write %d bytes to attribute %s\n",
222 * since we could not write user supplied number of bytes,
223 * restore the old value if one available
225 if (sysattr->method & SYSFS_METHOD_SHOW) {
226 length = write(fd, sysattr->value, sysattr->len);
233 * Validate length that has been copied. Alloc appropriate area
234 * in sysfs_attribute. Verify first if the attribute supports reading
235 * (show method). If it does not, do not bother
237 if (sysattr->method & SYSFS_METHOD_SHOW) {
238 if (length != sysattr->len) {
239 sysattr->value = (char *)realloc
240 (sysattr->value, length);
241 sysattr->len = length;
242 safestrcpymax(sysattr->value, new_value, length);
244 /*"length" of the new value is same as old one */
245 safestrcpymax(sysattr->value, new_value, length);
254 * sysfs_read_attribute: reads value from attribute
255 * @sysattr: attribute to read
256 * returns 0 with success and -1 with error.
258 int sysfs_read_attribute(struct sysfs_attribute *sysattr)
266 if (sysattr == NULL) {
270 if (!(sysattr->method & SYSFS_METHOD_SHOW)) {
271 dprintf("Show method not supported for attribute %s\n",
276 pgsize = getpagesize();
277 fbuf = (char *)calloc(1, pgsize+1);
279 dprintf("calloc failed\n");
282 if ((fd = open(sysattr->path, O_RDONLY)) < 0) {
283 dprintf("Error reading attribute %s\n", sysattr->path);
287 length = read(fd, fbuf, pgsize);
289 dprintf("Error reading from attribute %s\n", sysattr->path);
294 if (sysattr->len > 0) {
295 if ((sysattr->len == length) &&
296 (!(strncmp(sysattr->value, fbuf, length)))) {
301 free(sysattr->value);
303 sysattr->len = length;
305 vbuf = (char *)realloc(fbuf, length+1);
307 dprintf("realloc failed\n");
311 sysattr->value = vbuf;
317 * sysfs_read_attribute_value: given path to attribute, return its value.
318 * values can be up to a pagesize, if buffer is smaller the value will
320 * @attrpath: sysfs path to attribute
321 * @value: buffer to put value
322 * @vsize: size of value buffer
323 * returns 0 with success and -1 with error.
325 int sysfs_read_attribute_value(const char *attrpath,
326 char *value, size_t vsize)
328 struct sysfs_attribute *attr = NULL;
331 if (attrpath == NULL || value == NULL || vsize == 0) {
336 attr = sysfs_open_attribute(attrpath);
338 dprintf("Invalid attribute path %s\n", attrpath);
342 if((sysfs_read_attribute(attr)) != 0 || attr->value == NULL) {
343 dprintf("Error reading from attribute %s\n", attrpath);
344 sysfs_close_attribute(attr);
347 length = strlen(attr->value);
349 dprintf("Value length %d is larger than supplied buffer %d\n",
351 safestrcpymax(value, attr->value, vsize);
352 sysfs_close_attribute(attr);
358 * sysfs_get_value_from_attrbutes: given a linked list of attributes and an
359 * attribute name, return its value
360 * @attr: attribute to search
361 * @name: name to look for
362 * returns char * value - could be NULL
364 char *sysfs_get_value_from_attributes(struct dlist *attr, const char *name)
366 struct sysfs_attribute *cur = NULL;
368 if (attr == NULL || name == NULL) {
372 dlist_for_each_data(attr, cur, struct sysfs_attribute) {
373 if (strcmp(cur->name, name) == 0)
380 * sysfs_close_link: closes and cleans up link.
381 * @ln: link to close.
383 void sysfs_close_link(struct sysfs_link *ln)
390 * sysfs_close_directory: closes directory, cleans up attributes and links
391 * @sysdir: sysfs_directory to close
393 void sysfs_close_directory(struct sysfs_directory *sysdir)
395 if (sysdir != NULL) {
396 if (sysdir->subdirs != NULL)
397 dlist_destroy(sysdir->subdirs);
398 if (sysdir->links != NULL)
399 dlist_destroy(sysdir->links);
400 if (sysdir->attributes != NULL)
401 dlist_destroy(sysdir->attributes);
408 * alloc_directory: allocates and initializes directory structure
409 * returns struct sysfs_directory with success or NULL with error.
411 static struct sysfs_directory *alloc_directory(void)
413 return (struct sysfs_directory *)
414 calloc(1, sizeof(struct sysfs_directory));
418 * alloc_link: allocates and initializes link structure
419 * returns struct sysfs_link with success or NULL with error.
421 static struct sysfs_link *alloc_link(void)
423 return (struct sysfs_link *)calloc(1, sizeof(struct sysfs_link));
427 * sysfs_read_all_subdirs: calls sysfs_read_directory for all subdirs
428 * @sysdir: directory whose subdirs need reading.
429 * returns 0 with success and -1 with error.
431 int sysfs_read_all_subdirs(struct sysfs_directory *sysdir)
433 struct sysfs_directory *cursub = NULL;
436 if (sysdir == NULL) {
440 if (sysdir->subdirs == NULL)
441 if ((sysfs_read_dir_subdirs(sysdir)) != 0)
443 if (sysdir->subdirs != NULL) {
444 dlist_for_each_data(sysdir->subdirs, cursub,
445 struct sysfs_directory) {
446 if ((sysfs_read_dir_subdirs(cursub)) != 0) {
447 dprintf ("Error reading subdirectory %s\n",
459 * sysfs_open_directory: opens a sysfs directory, creates dir struct, and
461 * @path: path of directory to open.
462 * returns: struct sysfs_directory * with success and NULL on error.
464 struct sysfs_directory *sysfs_open_directory(const char *path)
466 struct sysfs_directory *sdir = NULL;
473 if (sysfs_path_is_dir(path) != 0) {
474 dprintf("Invalid path to directory %s\n", path);
479 sdir = alloc_directory();
481 dprintf("Error allocating directory %s\n", path);
484 if (sysfs_get_name_from_path(path, sdir->name, SYSFS_NAME_LEN) != 0) {
485 dprintf("Error getting directory name from path: %s\n", path);
486 sysfs_close_directory(sdir);
489 safestrcpy(sdir->path, path);
495 * sysfs_open_link: opens a sysfs link, creates struct, and returns
496 * @path: path of link to open.
497 * returns: struct sysfs_link * with success and NULL on error.
499 struct sysfs_link *sysfs_open_link(const char *linkpath)
501 struct sysfs_link *ln = NULL;
503 if (linkpath == NULL || strlen(linkpath) > SYSFS_PATH_MAX) {
510 dprintf("Error allocating link %s\n", linkpath);
513 safestrcpy(ln->path, linkpath);
514 if ((sysfs_get_name_from_path(linkpath, ln->name, SYSFS_NAME_LEN)) != 0
515 || (sysfs_get_link(linkpath, ln->target, SYSFS_PATH_MAX)) != 0) {
517 dprintf("Invalid link path %s\n", linkpath);
525 * add_attribute: open and add attribute at path to given directory
526 * @sysdir: directory to add attribute to
527 * @path: path to attribute
528 * returns 0 with success and -1 with error.
530 static int add_attribute(struct sysfs_directory *sysdir, const char *path)
532 struct sysfs_attribute *attr = NULL;
534 attr = sysfs_open_attribute(path);
536 dprintf("Error opening attribute %s\n", path);
539 if (attr->method & SYSFS_METHOD_SHOW) {
540 if ((sysfs_read_attribute(attr)) != 0) {
541 dprintf("Error reading attribute %s\n", path);
542 sysfs_close_attribute(attr);
547 if (sysdir->attributes == NULL) {
548 sysdir->attributes = dlist_new_with_delete
549 (sizeof(struct sysfs_attribute), sysfs_del_attribute);
551 dlist_unshift_sorted(sysdir->attributes, attr, sort_list);
557 * add_subdirectory: open and add subdirectory at path to given directory
558 * @sysdir: directory to add subdir to
559 * @path: path to subdirectory
560 * returns 0 with success and -1 with error.
562 static int add_subdirectory(struct sysfs_directory *sysdir, const char *path)
564 struct sysfs_directory *subdir = NULL;
566 subdir = sysfs_open_directory(path);
567 if (subdir == NULL) {
568 dprintf("Error opening directory %s\n", path);
571 if (sysdir->subdirs == NULL)
572 sysdir->subdirs = dlist_new_with_delete
573 (sizeof(struct sysfs_directory), sysfs_del_directory);
574 dlist_unshift_sorted(sysdir->subdirs, subdir, sort_list);
579 * add_link: open and add link at path to given directory
580 * @sysdir: directory to add link to
581 * @path: path to link
582 * returns 0 with success and -1 with error.
584 static int add_link(struct sysfs_directory *sysdir, const char *path)
586 struct sysfs_link *ln = NULL;
588 ln = sysfs_open_link(path);
590 dprintf("Error opening link %s\n", path);
593 if (sysdir->links == NULL)
594 sysdir->links = dlist_new_with_delete
595 (sizeof(struct sysfs_link), sysfs_del_link);
596 dlist_unshift_sorted(sysdir->links, ln, sort_list);
601 * sysfs_read_dir_attributes: grabs attributes for the given directory
602 * @sysdir: sysfs directory to open
603 * returns 0 with success and -1 with error.
605 int sysfs_read_dir_attributes(struct sysfs_directory *sysdir)
608 struct dirent *dirent = NULL;
609 char file_path[SYSFS_PATH_MAX];
612 if (sysdir == NULL) {
616 dir = opendir(sysdir->path);
618 dprintf("Error opening directory %s\n", sysdir->path);
621 while(((dirent = readdir(dir)) != NULL) && retval == 0) {
622 if (0 == strcmp(dirent->d_name, "."))
624 if (0 == strcmp(dirent->d_name, ".."))
626 memset(file_path, 0, SYSFS_PATH_MAX);
627 safestrcpy(file_path, sysdir->path);
628 safestrcat(file_path, "/");
629 safestrcat(file_path, dirent->d_name);
630 if ((sysfs_path_is_file(file_path)) == 0)
631 retval = add_attribute(sysdir, file_path);
640 * sysfs_read_dir_links: grabs links in a specific directory
641 * @sysdir: sysfs directory to read links
642 * returns 0 with success and -1 with error.
644 int sysfs_read_dir_links(struct sysfs_directory *sysdir)
647 struct dirent *dirent = NULL;
648 char file_path[SYSFS_PATH_MAX];
651 if (sysdir == NULL) {
655 dir = opendir(sysdir->path);
657 dprintf("Error opening directory %s\n", sysdir->path);
660 while(((dirent = readdir(dir)) != NULL) && retval == 0) {
661 if (0 == strcmp(dirent->d_name, "."))
663 if (0 == strcmp(dirent->d_name, ".."))
665 memset(file_path, 0, SYSFS_PATH_MAX);
666 safestrcpy(file_path, sysdir->path);
667 safestrcat(file_path, "/");
668 safestrcat(file_path, dirent->d_name);
669 if ((sysfs_path_is_link(file_path)) == 0) {
670 retval = add_link(sysdir, file_path);
682 * sysfs_read_dir_subdirs: grabs subdirs in a specific directory
683 * @sysdir: sysfs directory to read links
684 * returns 0 with success and -1 with error.
686 int sysfs_read_dir_subdirs(struct sysfs_directory *sysdir)
689 struct dirent *dirent = NULL;
690 char file_path[SYSFS_PATH_MAX];
693 if (sysdir == NULL) {
697 dir = opendir(sysdir->path);
699 dprintf("Error opening directory %s\n", sysdir->path);
702 while(((dirent = readdir(dir)) != NULL) && retval == 0) {
703 if (0 == strcmp(dirent->d_name, "."))
705 if (0 == strcmp(dirent->d_name, ".."))
707 memset(file_path, 0, SYSFS_PATH_MAX);
708 safestrcpy(file_path, sysdir->path);
709 safestrcat(file_path, "/");
710 safestrcat(file_path, dirent->d_name);
711 if ((sysfs_path_is_dir(file_path)) == 0)
712 retval = add_subdirectory(sysdir, file_path);
721 * sysfs_read_directory: grabs attributes, links, and subdirectories
722 * @sysdir: sysfs directory to open
723 * returns 0 with success and -1 with error.
725 int sysfs_read_directory(struct sysfs_directory *sysdir)
728 struct dirent *dirent = NULL;
730 char file_path[SYSFS_PATH_MAX];
733 if (sysdir == NULL) {
737 dir = opendir(sysdir->path);
739 dprintf("Error opening directory %s\n", sysdir->path);
742 while(((dirent = readdir(dir)) != NULL) && retval == 0) {
743 if (0 == strcmp(dirent->d_name, "."))
745 if (0 == strcmp(dirent->d_name, ".."))
747 memset(file_path, 0, SYSFS_PATH_MAX);
748 safestrcpy(file_path, sysdir->path);
749 safestrcat(file_path, "/");
750 safestrcat(file_path, dirent->d_name);
751 if ((lstat(file_path, &astats)) != 0) {
752 dprintf("stat failed\n");
755 if (S_ISDIR(astats.st_mode))
756 retval = add_subdirectory(sysdir, file_path);
758 else if (S_ISLNK(astats.st_mode))
759 retval = add_link(sysdir, file_path);
761 else if (S_ISREG(astats.st_mode))
762 retval = add_attribute(sysdir, file_path);
771 * sysfs_refresh_dir_attributes: Refresh attributes list
772 * @sysdir: directory whose list of attributes to refresh
773 * Returns 0 on success, 1 on failure
775 int sysfs_refresh_dir_attributes(struct sysfs_directory *sysdir)
777 if (sysdir == NULL) {
781 if ((sysfs_path_is_dir(sysdir->path)) != 0) {
782 dprintf("Invalid path to directory %s\n", sysdir->path);
786 if (sysdir->attributes != NULL) {
787 dlist_destroy(sysdir->attributes);
788 sysdir->attributes = NULL;
790 if ((sysfs_read_dir_attributes(sysdir)) != 0) {
791 dprintf("Error refreshing attributes for directory %s\n",
800 * sysfs_refresh_dir_links: Refresh links list
801 * @sysdir: directory whose list of links to refresh
802 * Returns 0 on success, 1 on failure
804 int sysfs_refresh_dir_links(struct sysfs_directory *sysdir)
806 if (sysdir == NULL) {
810 if ((sysfs_path_is_dir(sysdir->path)) != 0) {
811 dprintf("Invalid path to directory %s\n", sysdir->path);
815 if (sysdir->links != NULL) {
816 dlist_destroy(sysdir->links);
817 sysdir->links = NULL;
819 if ((sysfs_read_dir_links(sysdir)) != 0) {
820 dprintf("Error refreshing links for directory %s\n",
829 * sysfs_refresh_dir_subdirs: Refresh subdirs list
830 * @sysdir: directory whose list of subdirs to refresh
831 * Returns 0 on success, 1 on failure
833 int sysfs_refresh_dir_subdirs(struct sysfs_directory *sysdir)
835 if (sysdir == NULL) {
839 if ((sysfs_path_is_dir(sysdir->path)) != 0) {
840 dprintf("Invalid path to directory %s\n", sysdir->path);
844 if (sysdir->subdirs != NULL) {
845 dlist_destroy(sysdir->subdirs);
846 sysdir->subdirs = NULL;
848 if ((sysfs_read_dir_subdirs(sysdir)) != 0) {
849 dprintf("Error refreshing subdirs for directory %s\n",
858 * sysfs_get_directory_attribute: retrieves attribute attrname from current
860 * @dir: directory to retrieve attribute from
861 * @attrname: name of attribute to look for
863 * NOTE: Since we know the attribute to look for, this routine looks for the
864 * attribute if it was created _after_ the attrlist was read initially.
866 * returns sysfs_attribute if found and NULL if not found
868 struct sysfs_attribute *sysfs_get_directory_attribute
869 (struct sysfs_directory *dir, char *attrname)
871 struct sysfs_attribute *attr = NULL;
872 char new_path[SYSFS_PATH_MAX];
874 if (dir == NULL || attrname == NULL) {
879 if (dir->attributes == NULL)
880 if ((sysfs_read_dir_attributes(dir) != 0)
881 || (dir->attributes == NULL))
884 attr = (struct sysfs_attribute *)dlist_find_custom
885 (dir->attributes, attrname, dir_attribute_name_equal);
887 if ((sysfs_read_attribute(attr)) != 0) {
888 dprintf("Error reading attribute %s\n", attr->name);
892 memset(new_path, 0, SYSFS_PATH_MAX);
893 safestrcpy(new_path, dir->path);
894 safestrcat(new_path, "/");
895 safestrcat(new_path, attrname);
896 if ((sysfs_path_is_file(new_path)) == 0) {
897 if ((add_attribute(dir, new_path)) == 0) {
898 attr = (struct sysfs_attribute *)
899 dlist_find_custom(dir->attributes,
900 attrname, dir_attribute_name_equal);
909 * sysfs_get_directory_link: retrieves link from one directory list
910 * @dir: directory to retrieve link from
911 * @linkname: name of link to look for
912 * returns reference to sysfs_link if found and NULL if not found
914 struct sysfs_link *sysfs_get_directory_link
915 (struct sysfs_directory *dir, char *linkname)
917 if (dir == NULL || linkname == NULL) {
921 if (dir->links == NULL) {
922 if ((sysfs_read_dir_links(dir) != 0) || (dir->links == NULL))
925 if ((sysfs_refresh_dir_links(dir)) != 0)
929 return (struct sysfs_link *)dlist_find_custom(dir->links,
930 linkname, dir_link_name_equal);
934 * sysfs_get_subdirectory: retrieves subdirectory by name.
935 * @dir: directory to search for subdirectory.
936 * @subname: subdirectory name to get.
937 * returns reference to subdirectory or NULL if not found
939 struct sysfs_directory *sysfs_get_subdirectory(struct sysfs_directory *dir,
942 struct sysfs_directory *sub = NULL, *cursub = NULL;
944 if (dir == NULL || subname == NULL) {
949 if (dir->subdirs == NULL)
950 if (sysfs_read_dir_subdirs(dir) != 0)
953 sub = (struct sysfs_directory *)dlist_find_custom(dir->subdirs,
954 subname, dir_subdir_name_equal);
958 if (dir->subdirs != NULL) {
959 dlist_for_each_data(dir->subdirs, cursub,
960 struct sysfs_directory) {
961 if (cursub->subdirs == NULL) {
962 if (sysfs_read_dir_subdirs(cursub) != 0)
964 if (cursub->subdirs == NULL)
967 sub = sysfs_get_subdirectory(cursub, subname);
976 * sysfs_get_subdirectory_link: looks through all subdirs for specific link.
977 * @dir: directory and subdirectories to search for link.
978 * @linkname: link name to get.
979 * returns reference to link or NULL if not found
981 struct sysfs_link *sysfs_get_subdirectory_link(struct sysfs_directory *dir,
984 struct sysfs_directory *cursub = NULL;
985 struct sysfs_link *ln = NULL;
987 if (dir == NULL || linkname == NULL) {
992 ln = sysfs_get_directory_link(dir, linkname);
996 if (dir->subdirs == NULL)
997 if (sysfs_read_dir_subdirs(dir) != 0)
1000 if (dir->subdirs != NULL) {
1001 dlist_for_each_data(dir->subdirs, cursub,
1002 struct sysfs_directory) {
1003 ln = sysfs_get_subdirectory_link(cursub, linkname);
1012 * sysfs_get_dir_attributes: returns dlist of directory attributes
1013 * @dir: directory to retrieve attributes from
1014 * returns dlist of attributes or NULL
1016 struct dlist *sysfs_get_dir_attributes(struct sysfs_directory *dir)
1023 if (dir->attributes == NULL) {
1024 if (sysfs_read_dir_attributes(dir) != 0)
1028 return (dir->attributes);
1032 * sysfs_get_dir_links: returns dlist of directory links
1033 * @dir: directory to return links for
1034 * returns dlist of links or NULL
1036 struct dlist *sysfs_get_dir_links(struct sysfs_directory *dir)
1043 if (dir->links == NULL) {
1044 if (sysfs_read_dir_links(dir) != 0)
1048 return (dir->links);
1052 * sysfs_get_dir_subdirs: returns dlist of directory subdirectories
1053 * @dir: directory to return subdirs for
1054 * returns dlist of subdirs or NULL
1056 struct dlist *sysfs_get_dir_subdirs(struct sysfs_directory *dir)
1063 if (dir->subdirs == NULL) {
1064 if (sysfs_read_dir_subdirs(dir) != 0)
1068 return (dir->subdirs);