+ * sysfs_get_bus_devices: gets all devices for bus
+ * @bus: bus to get devices for
+ * returns dlist of devices with success and NULL with failure
+ */
+struct dlist *sysfs_get_bus_devices(struct sysfs_bus *bus)
+{
+ struct sysfs_device *bdev = NULL;
+ struct sysfs_directory *devdir = NULL;
+ struct sysfs_link *curl = NULL;
+ unsigned char path[SYSFS_PATH_MAX];
+
+ if (bus == NULL) {
+ errno = EINVAL;
+ return NULL;
+ }
+ memset(path, 0, SYSFS_PATH_MAX);
+ strcpy(path, bus->path);
+ strcat(path, "/");
+ strcat(path, SYSFS_DEVICES_NAME);
+ devdir = sysfs_open_directory(path);
+ if (devdir == NULL)
+ return NULL;
+
+ if (sysfs_read_dir_links(devdir) != 0) {
+ sysfs_close_directory(devdir);
+ return NULL;
+ }
+
+ if (devdir->links != 0) {
+ dlist_for_each_data(devdir->links, curl, struct sysfs_link) {
+ bdev = sysfs_open_device_path(curl->target);
+ if (bdev == NULL) {
+ dprintf("Error opening device at %s\n",
+ curl->target);
+ continue;
+ }
+ if (bus->devices == NULL)
+ bus->devices = dlist_new_with_delete
+ (sizeof(struct sysfs_device),
+ sysfs_close_dev);
+ dlist_unshift(bus->devices, bdev);
+ }
+ }
+ sysfs_close_directory(devdir);
+
+ return (bus->devices);
+}
+
+/**
+ * sysfs_get_bus_drivers: get all pci drivers
+ * @bus: pci bus to add drivers to
+ * returns dlist of drivers with success and NULL with error
+ */
+struct dlist *sysfs_get_bus_drivers(struct sysfs_bus *bus)
+{
+ struct sysfs_driver *driver = NULL;
+ struct sysfs_directory *drvdir = NULL;
+ struct sysfs_directory *cursub = NULL;
+ unsigned char path[SYSFS_PATH_MAX];
+
+ if (bus == NULL) {
+ errno = EINVAL;
+ return NULL;
+ }
+ memset(path, 0, SYSFS_PATH_MAX);
+ strcpy(path, bus->path);
+ strcat(path, "/");
+ strcat(path, SYSFS_DRIVERS_NAME);
+ drvdir = sysfs_open_directory(path);
+ if (drvdir == NULL)
+ return NULL;
+
+ if (sysfs_read_dir_subdirs(drvdir) != 0) {
+ sysfs_close_directory(drvdir);
+ return NULL;
+ }
+ if (drvdir->subdirs != NULL) {
+ dlist_for_each_data(drvdir->subdirs, cursub,
+ struct sysfs_directory) {
+ driver = sysfs_open_driver_path(cursub->path);
+ if (driver == NULL) {
+ dprintf("Error opening driver at %s\n",
+ cursub->path);
+ continue;
+ }
+ if (bus->drivers == NULL)
+ bus->drivers = dlist_new_with_delete
+ (sizeof(struct sysfs_driver),
+ sysfs_close_drv);
+ dlist_unshift(bus->drivers, driver);
+ }
+ }
+ sysfs_close_directory(drvdir);
+ return (bus->drivers);
+}
+
+/**
+ * sysfs_open_bus: opens specific bus and all its devices on system
+ * returns sysfs_bus structure with success or NULL with error.