- strcpy(cdev->path, path);
- set_classdev_classname(cdev);
-
- return cdev;
-}
-
-/**
- * sysfs_get_class_devices: gets all devices for class
- * @class: class to get devices for
- * returns dlist of class_devices with success and NULL with error
- */
-struct dlist *sysfs_get_class_devices(struct sysfs_class *cls)
-{
- struct sysfs_class_device *dev = NULL;
- struct sysfs_directory *cur = NULL;
-
- if (cls == NULL) {
- errno = EINVAL;
- return NULL;
- }
- if (cls->directory == NULL) {
- cls->directory = sysfs_open_directory(cls->path);
- if (cls->directory == NULL)
- return NULL;
- }
-
- if ((sysfs_read_dir_subdirs(cls->directory) != 0)
- || cls->directory->subdirs == NULL)
- return NULL;
-
- dlist_for_each_data(cls->directory->subdirs, cur,
- struct sysfs_directory) {
- dev = sysfs_open_class_device(cur->path);
- if (dev == NULL) {
- dprintf("Error opening device at %s\n", cur->path);
- continue;
- }
- if (cls->devices == NULL)
- cls->devices = dlist_new_with_delete
- (sizeof(struct sysfs_class_device),
- sysfs_close_cls_dev);
- dlist_unshift(cls->devices, dev);
- }
- return cls->devices;
-}
-
-/**
- * sysfs_open_class: opens specific class and all its devices on system
- * returns sysfs_class structure with success or NULL with error.
- */
-struct sysfs_class *sysfs_open_class(const unsigned char *name)
-{
- struct sysfs_class *cls = NULL;
- unsigned char classpath[SYSFS_PATH_MAX];
-
- if (name == NULL) {
- errno = EINVAL;
- return NULL;
- }
-
- memset(classpath, 0, SYSFS_PATH_MAX);
- if ((sysfs_get_mnt_path(classpath, SYSFS_PATH_MAX)) != 0) {
- dprintf("Sysfs not supported on this system\n");
- return NULL;
- }
-
- if (sysfs_trailing_slash(classpath) == 0)
- strcat(classpath, "/");
-
- /*
- * We shall now treat "block" also as a class. Hence, check here
- * if "name" is "block" and proceed accordingly
- */
- if (strcmp(name, SYSFS_BLOCK_NAME) == 0) {
- strcat(classpath, SYSFS_BLOCK_NAME);
- } else {
- strcat(classpath, SYSFS_CLASS_NAME);
- strcat(classpath, "/");
- strcat(classpath, name);
- }
- if ((sysfs_path_is_dir(classpath)) != 0) {
- dprintf("Class %s not found on the system\n", name);
- return NULL;
- }
-
- cls = alloc_class();
- if (cls == NULL) {
- dprintf("calloc failed\n");
- return NULL;
- }
- strcpy(cls->name, name);
- strcpy(cls->path, classpath);
-
- return cls;
-}
-
-/**
- * sysfs_get_class_device: Get specific class device using the device's id
- * @class: class to find device on
- * @name: class name of the device
- */
-struct sysfs_class_device *sysfs_get_class_device(struct sysfs_class *class,
- unsigned char *name)
-{
- struct dlist *devlist = NULL;
-
- if (class == NULL || name == NULL) {
- errno = EINVAL;