Exemplo n.º 1
0
/**
 * sysfs_get_bus_driver: Get specific driver on bus using driver name
 * @bus: bus to find driver on
 * @drvname: name of driver
 * returns struct sysfs_driver reference or NULL if not found.
 */
struct sysfs_driver *sysfs_get_bus_driver(struct sysfs_bus *bus,
		const char *drvname)
{
	struct sysfs_driver *drv;
	char drvpath[SYSFS_PATH_MAX];

	if (!bus || !drvname) {
		errno = EINVAL;
		return NULL;
	}

	if (bus->drivers) {
		drv = (struct sysfs_driver *)dlist_find_custom
			(bus->drivers, (void *)drvname, name_equal);
		if (drv)
			return drv;
	}
	safestrcpy(drvpath, bus->path);
	safestrcat(drvpath, "/");
	safestrcat(drvpath, SYSFS_DRIVERS_NAME);
	safestrcat(drvpath, "/");
	safestrcat(drvpath, drvname);
	drv = sysfs_open_driver_path(drvpath);
	if (!drv) {
		dprintf("Error opening driver at %s\n", drvpath);
		return NULL;
	}
	if (!bus->drivers)
		bus->drivers = dlist_new_with_delete
				(sizeof(struct sysfs_driver),
				 		sysfs_close_drv);
	dlist_unshift_sorted(bus->drivers, drv, sort_list);
	return drv;
}
Exemplo n.º 2
0
static struct sysfs_driver *open_sysfs_stub_driver(void)
{
	int ret;

	char sysfs_mntpath[SYSFS_PATH_MAX];
	char stub_driver_path[SYSFS_PATH_MAX];
	struct sysfs_driver *stub_driver;


	ret = sysfs_get_mnt_path(sysfs_mntpath, SYSFS_PATH_MAX);
	if (ret < 0) {
		err("sysfs must be mounted");
		return NULL;
	}

	snprintf(stub_driver_path, SYSFS_PATH_MAX, "%s/%s/usb/%s/%s",
			sysfs_mntpath, SYSFS_BUS_NAME, SYSFS_DRIVERS_NAME,
			usbip_stub_driver_name);

	stub_driver = sysfs_open_driver_path(stub_driver_path);
	if (!stub_driver) {
		err("usbip_common_mod.ko and usbip.ko must be loaded");
		return NULL;
	}

	return stub_driver;
}
Exemplo n.º 3
0
/**
 * sysfs_get_bus_drivers: gets all drivers for bus
 * @bus: bus to get devices for
 * returns dlist of devices with success and NULL with failure
 */
struct dlist *sysfs_get_bus_drivers(struct sysfs_bus *bus)
{
	struct sysfs_driver *drv;
	struct dlist *dirlist;
	char path[SYSFS_PATH_MAX], drvpath[SYSFS_PATH_MAX];
	char *curdir;

	if (!bus) {
		errno = EINVAL;
		return NULL;
	}
	memset(path, 0, SYSFS_PATH_MAX);
	safestrcpy(path, bus->path);
	safestrcat(path, "/");
	safestrcat(path, SYSFS_DRIVERS_NAME);

	dirlist = read_dir_subdirs(path);
	if (dirlist) {
		dlist_for_each_data(dirlist, curdir, char) {
			if (bus->drivers) {
				drv = (struct sysfs_driver *)
					dlist_find_custom(bus->drivers,
					(void *)curdir, name_equal);
				if (drv)
					continue;
			}
			safestrcpy(drvpath, path);
			safestrcat(drvpath, "/");
			safestrcat(drvpath, curdir);
			drv = sysfs_open_driver_path(drvpath);
			if (!drv) {
				dprintf("Error opening driver at %s\n",
								drvpath);
				continue;
			}
			if (!bus->drivers)
				bus->drivers = dlist_new_with_delete
					(sizeof(struct sysfs_driver),
					 		sysfs_close_drv);
			dlist_unshift_sorted(bus->drivers, drv, sort_list);
		}
		sysfs_close_list(dirlist);
	}
	return (bus->drivers);
}
Exemplo n.º 4
0
int main(int argc, char *argv[])
{
	char *bus = NULL, path[SYSFS_PATH_MAX];
	struct sysfs_driver *driver = NULL;
	struct sysfs_device *device = NULL;
	struct dlist *devlist = NULL;
	struct sysfs_attribute *attr = NULL;

	if (argc != 3) {
		print_usage();
		return 1;
	}

	memset(path, 0, SYSFS_PATH_MAX);
	if ((sysfs_get_mnt_path(path, SYSFS_PATH_MAX)) != 0) {
		fprintf(stdout, "Sysfs not mounted?\n");
		return 1;
	}
	strcat(path, "/");
	strcat(path, SYSFS_BUS_NAME);
	strcat(path, "/");
	strcat(path, argv[1]);
	strcat(path, "/");
	strcat(path, SYSFS_DRIVERS_NAME);
	strcat(path, "/");
	strcat(path, argv[2]);
	driver = sysfs_open_driver_path(path);
	if (driver == NULL) {
		fprintf(stdout, "Driver %s not found\n", argv[1]);
		free(bus);
		return 1;
	}
	devlist = sysfs_get_driver_devices(driver);
	if (devlist != NULL) {
		fprintf(stdout, "%s is used by:\n", argv[2]);
		dlist_for_each_data(devlist, device, struct sysfs_device)
			fprintf(stdout, "\t\t%s\n", device->bus_id);
	} else
Exemplo n.º 5
0
/**
 * sysfs_open_driver: open driver by name, given its bus
 * @bus_name: Name of the bus
 * @drv_name: Name of the driver
 * Returns the sysfs_driver reference on success and NULL on failure
 */
struct sysfs_driver *sysfs_open_driver(const char *bus_name,
			const char *drv_name)
{
	char path[SYSFS_PATH_MAX];
	struct sysfs_driver *driver = NULL;

	if (!drv_name || !bus_name) {
		errno = EINVAL;
		return NULL;
	}

	memset(path, 0, SYSFS_PATH_MAX);
	if (get_driver_path(bus_name, drv_name, path, SYSFS_PATH_MAX)) {
		dprintf("Error getting to driver %s\n", drv_name);
		return NULL;
	}
	driver = sysfs_open_driver_path(path);
	if (!driver) {
		dprintf("Error opening driver at %s\n", path);
		return NULL;
	}
	return driver;
}