libsysfs: remove brute-force "bus", "driver" searching for old kernels

Signed-off-by: Kay Sievers <kay.sievers@suse.de>
This commit is contained in:
Kay Sievers 2005-11-02 04:58:59 +01:00
parent 0747dd884a
commit 8687cbfffb

View File

@ -29,10 +29,8 @@
*/
static int get_dev_driver(struct sysfs_device *dev)
{
struct dlist *drvlist;
char path[SYSFS_PATH_MAX];
char devpath[SYSFS_PATH_MAX];
char *drv = NULL, *c;
if (!dev) {
errno = EINVAL;
@ -50,44 +48,6 @@ static int get_dev_driver(struct sysfs_device *dev)
}
return 0;
}
/*
* Devices on earlier kernels do not have the "driver" link.
* Look it up in the bus directory.
*/
if (dev->bus[0] == '\0')
return -1;
memset(path, 0, SYSFS_PATH_MAX);
memset(devpath, 0, SYSFS_PATH_MAX);
safestrcpy(path, dev->path);
c = strstr(path, SYSFS_DEVICES_NAME);
if (c == NULL) {
dprintf("Invalid path to device - %s\n", dev->path);
return -1;
} else
*c = '\0';
safestrcat(path, SYSFS_BUS_NAME);
safestrcat(path, "/");
safestrcat(path, dev->bus);
safestrcat(path, "/");
safestrcat(path, SYSFS_DRIVERS_NAME);
drvlist = sysfs_open_directory_list(path);
if (drvlist) {
dlist_for_each_data(drvlist, drv, char) {
safestrcpy(devpath, path);
safestrcat(devpath, "/");
safestrcat(devpath, drv);
safestrcat(devpath, "/");
safestrcat(devpath, dev->bus_id);
if (!sysfs_path_is_link(devpath)) {
safestrcpy(dev->driver_name, drv);
sysfs_close_list(drvlist);
return 0;
}
}
sysfs_close_list(drvlist);
}
return -1;
}
@ -100,11 +60,7 @@ static int get_dev_driver(struct sysfs_device *dev)
int sysfs_get_device_bus(struct sysfs_device *dev)
{
char devpath[SYSFS_PATH_MAX];
char subsys[SYSFS_NAME_LEN];
char path[SYSFS_PATH_MAX];
char target[SYSFS_PATH_MAX];
char *bus = NULL, *c;
struct dlist *buslist;
if (!dev) {
errno = EINVAL;
@ -123,49 +79,6 @@ int sysfs_get_device_bus(struct sysfs_device *dev)
}
return 0;
}
/*
* Devices on on earlier kernels do not have the "bus" link.
* Look it up in the bus directory.
*/
memset(subsys, 0, SYSFS_NAME_LEN);
safestrcpy(subsys, dev->path);
c = strstr(subsys, SYSFS_DEVICES_NAME);
if (c == NULL) {
dprintf("Invalid path to device - %s\n", dev->path);
return -1;
} else
*c = '\0';
safestrcat(subsys, SYSFS_BUS_NAME);
buslist = sysfs_open_directory_list(subsys);
if (buslist) {
dlist_for_each_data(buslist, bus, char) {
memset(path, 0, SYSFS_PATH_MAX);
safestrcpy(path, subsys);
safestrcat(path, "/");
safestrcat(path, bus);
safestrcat(path, "/");
safestrcat(path, SYSFS_DEVICES_NAME);
safestrcat(path, "/");
safestrcat(path, dev->bus_id);
if (!sysfs_path_is_link(path)) {
memset(target, 0, SYSFS_PATH_MAX);
if (sysfs_get_link(path, target,
SYSFS_PATH_MAX)) {
dprintf("Error getting link target\n");
sysfs_close_list(buslist);
return -1;
}
if (!(strncmp(target, dev->path,
SYSFS_PATH_MAX))) {
safestrcpy(dev->bus, bus);
sysfs_close_list(buslist);
return 0;
}
}
}
sysfs_close_list(buslist);
}
return -1;
}
@ -371,7 +284,6 @@ struct sysfs_device *sysfs_open_device(const char *bus, const char *bus_id)
dprintf("Error opening device %s\n", bus_id);
return NULL;
}
return device;
}