- 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;
- }
- if (S_ISDIR(astats.st_mode))
- retval = add_subdirectory(sysdir, file_path);
-
- else if (S_ISLNK(astats.st_mode))
- retval = add_link(sysdir, file_path);
-
- else if (S_ISREG(astats.st_mode))
- retval = add_attribute(sysdir, file_path);
- }
- closedir(dir);
- return(retval);
-}
-
-/**
- * sysfs_refresh_dir_attributes: Refresh attributes list
- * @sysdir: directory whose list of attributes to refresh
- * Returns 0 on success, 1 on failure
- */
-int sysfs_refresh_dir_attributes(struct sysfs_directory *sysdir)
-{
- if (sysdir == NULL) {
- errno = EINVAL;
- return 1;
- }
- if ((sysfs_path_is_dir(sysdir->path)) != 0) {
- dprintf("Invalid path to directory %s\n", sysdir->path);
- errno = EINVAL;
- return 1;
- }
- if (sysdir->attributes != NULL) {
- dlist_destroy(sysdir->attributes);
- sysdir->attributes = NULL;
- }
- if ((sysfs_read_dir_attributes(sysdir)) != 0) {
- dprintf("Error refreshing attributes for directory %s\n",
- sysdir->path);
- return 1;
- }
- return 0;
-}
-
-/**
- * sysfs_refresh_dir_links: Refresh links list
- * @sysdir: directory whose list of links to refresh
- * Returns 0 on success, 1 on failure
- */
-int sysfs_refresh_dir_links(struct sysfs_directory *sysdir)
-{
- if (sysdir == NULL) {
- errno = EINVAL;
- return 1;
- }
- if ((sysfs_path_is_dir(sysdir->path)) != 0) {
- dprintf("Invalid path to directory %s\n", sysdir->path);
- errno = EINVAL;
- return 1;
- }
- if (sysdir->links != NULL) {
- dlist_destroy(sysdir->links);
- sysdir->links = NULL;
- }
- if ((sysfs_read_dir_links(sysdir)) != 0) {
- dprintf("Error refreshing links for directory %s\n",
- sysdir->path);
- return 1;
- }
- return 0;
-}
-
-/**
- * sysfs_refresh_dir_subdirs: Refresh subdirs list
- * @sysdir: directory whose list of subdirs to refresh
- * Returns 0 on success, 1 on failure
- */
-int sysfs_refresh_dir_subdirs(struct sysfs_directory *sysdir)
-{
- if (sysdir == NULL) {
- errno = EINVAL;
- return 1;
- }
- if ((sysfs_path_is_dir(sysdir->path)) != 0) {
- dprintf("Invalid path to directory %s\n", sysdir->path);
- errno = EINVAL;
- return 1;
- }
- if (sysdir->subdirs != NULL) {
- dlist_destroy(sysdir->subdirs);
- sysdir->subdirs = NULL;
- }
- if ((sysfs_read_dir_subdirs(sysdir)) != 0) {
- dprintf("Error refreshing subdirs for directory %s\n",
- sysdir->path);
- return 1;
- }
- return 0;
-}
-
-/**
- * sysfs_get_directory_attribute: retrieves attribute attrname from current
- * directory only
- * @dir: directory to retrieve attribute from
- * @attrname: name of attribute to look for
- * returns sysfs_attribute if found and NULL if not found
- */
-struct sysfs_attribute *sysfs_get_directory_attribute
- (struct sysfs_directory *dir, unsigned char *attrname)
-{
- struct sysfs_attribute *attr = NULL;
- unsigned char new_path[SYSFS_PATH_MAX];
-
- if (dir == NULL || attrname == NULL) {
- errno = EINVAL;
- return NULL;
- }
-
- if (dir->attributes == NULL)
- if ((sysfs_read_dir_attributes(dir) != 0)
- || (dir->attributes == NULL))
- return NULL;
-
- attr = (struct sysfs_attribute *)dlist_find_custom
- (dir->attributes, attrname, dir_attribute_name_equal);
- if (attr != NULL) {
- if ((sysfs_read_attribute(attr)) != 0) {
- dprintf("Error reading attribute %s\n", attr->name);
- return NULL;
- }
- } else {
- 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) {