- strncpy(dev->name, dev->bus_id, SYSFS_NAME_LEN);
-
- if (sysfs_get_device_bus(dev) != 0)
- dprintf("Could not get device bus\n");
-
- return dev;
-}
-
-/**
- * sysfs_open_device_tree: opens root device and all of its children,
- * creating a tree of devices. Only opens children.
- * @path: sysfs path to devices
- * returns struct sysfs_device and its children with success or NULL with
- * error.
- */
-static struct sysfs_device *sysfs_open_device_tree(const unsigned char *path)
-{
- struct sysfs_device *rootdev = NULL, *new = NULL;
- struct sysfs_directory *cur = NULL;
-
- if (path == NULL) {
- errno = EINVAL;
- return NULL;
- }
- rootdev = sysfs_open_device_path(path);
- if (rootdev == NULL) {
- dprintf("Error opening root device at %s\n", path);
- return NULL;
- }
- if (rootdev->directory == NULL) {
- rootdev->directory = open_device_dir(rootdev->path);
- if (rootdev->directory == NULL)
- return NULL;
- }
- if (rootdev->directory->subdirs != NULL) {
- dlist_for_each_data(rootdev->directory->subdirs, cur,
- struct sysfs_directory) {
- new = sysfs_open_device_tree(cur->path);
- if (new == NULL) {
- dprintf("Error opening device tree at %s\n",
- cur->path);
- sysfs_close_device_tree(rootdev);
- return NULL;
- }
- if (rootdev->children == NULL)
- rootdev->children = dlist_new_with_delete
- (sizeof(struct sysfs_device),
- sysfs_close_dev_tree);
- dlist_unshift(rootdev->children, new);
- }
- }
-
- return rootdev;
-}
-
-/**
- * sysfs_close_root_device: closes root and all devices
- * @root: root device to close
- */
-void sysfs_close_root_device(struct sysfs_root_device *root)
-{
- if (root != NULL) {
- if (root->devices != NULL)
- dlist_destroy(root->devices);
- if (root->directory != NULL)
- sysfs_close_directory(root->directory);
- free(root);
- }
-}
-
-/**
- * sysfs_get_root_devices: opens up all the devices under this root device
- * @root: root device to open devices for
- * returns dlist of devices with success and NULL with error
- */
-struct dlist *sysfs_get_root_devices(struct sysfs_root_device *root)
-{
- struct sysfs_device *dev = NULL;
- struct sysfs_directory *cur = NULL;
-
- if (root == NULL) {
- errno = EINVAL;
- return NULL;
- }
- if (root->directory == NULL) {
- root->directory = open_device_dir(root->path);
- if (root->directory == NULL)
- return NULL;
- }
-
- 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);
- }