- return -1;
- }
- if (root->directory->subdirs == NULL)
- return 0;
-
- dlist_for_each_data(root->directory->subdirs, cur,
- struct sysfs_directory) {
- dev = sysfs_open_device_tree(cur->path);
- if (dev == NULL) {
- dprintf ("Error opening device at %s\n", cur->path);
- continue;
- }
- if (root->devices == NULL)
- root->devices = dlist_new_with_delete
- (sizeof(struct sysfs_device),
- sysfs_close_dev_tree);
- dlist_unshift(root->devices, dev);
- }
-
- return 0;
-}
-
-/**
- * sysfs_open_root_device: opens sysfs devices root and all of its
- * devices.
- * @name: name of /sys/devices/root to open
- * returns struct sysfs_root_device if success and NULL with error
- */
-struct sysfs_root_device *sysfs_open_root_device(const unsigned char *name)
-{
- struct sysfs_root_device *root = NULL;
- struct sysfs_directory *rootdir = NULL;
-
- if (name == NULL) {
- errno = EINVAL;
- return NULL;
- }
-
- root = (struct sysfs_root_device *)calloc
- (1, sizeof(struct sysfs_root_device));
- if (root == NULL) {
- dprintf("calloc failure\n");
- return NULL;
- }
- rootdir = open_root_device_dir(name);
- if (rootdir == NULL) {
- dprintf ("Invalid root device, %s not supported\n", name);
- sysfs_close_root_device(root);
- return NULL;
- }
- strcpy(root->path, rootdir->path);
- root->directory = rootdir;
- if (get_all_root_devices(root) != 0) {
- dprintf ("Error retrieving devices for root %s\n", name);
- sysfs_close_root_device(root);