+ if (!cls->devices)
+ cls->devices = dlist_new_with_delete
+ (sizeof(struct sysfs_class_device),
+ sysfs_close_cls_dev);
+
+ dlist_unshift_sorted(cls->devices, cdev, sort_list);
+ return cdev;
+}
+
+/**
+ * Add class devices to list
+ */
+static void add_cdevs_to_classlist(struct sysfs_class *cls, struct dlist *list)
+{
+ char path[SYSFS_PATH_MAX], *cdev_name;
+ struct sysfs_class_device *cdev = NULL;
+
+ if (cls == NULL || list == NULL)
+ return;
+
+ dlist_for_each_data(list, cdev_name, char) {
+ if (cls->devices) {
+ cdev = (struct sysfs_class_device *)
+ dlist_find_custom(cls->devices,
+ (void *)cdev_name, cdev_name_equal);
+ if (cdev)
+ continue;
+ }
+ safestrcpy(path, cls->path);
+ safestrcat(path, "/");
+ safestrcat(path, cdev_name);
+ cdev = sysfs_open_class_device_path(path);
+ if (cdev) {
+ if (!cls->devices)
+ cls->devices = dlist_new_with_delete
+ (sizeof(struct sysfs_class_device),
+ sysfs_close_cls_dev);
+ dlist_unshift_sorted(cls->devices, cdev,
+ sort_list);
+ }
+ }
+}
+
+/**
+ * sysfs_get_class_devices: get all class devices in the given class
+ * @cls: sysfs_class whose devices list is needed
+ *
+ * Returns a dlist of sysfs_class_device * on success and NULL on failure
+ */
+struct dlist *sysfs_get_class_devices(struct sysfs_class *cls)
+{
+ char path[SYSFS_PATH_MAX];
+ struct dlist *dirlist, *linklist;
+
+ if (!cls) {
+ errno = EINVAL;