chiark / gitweb /
[PATCH] new version of libsysfs patch
[elogind.git] / namedev.c
index ac05fd88e4d4e4cc31ddd2dbc44a40164cffab7c..c21a5be7ad53549ba086b577de84b946d6bbf0bf 100644 (file)
--- a/namedev.c
+++ b/namedev.c
@@ -547,7 +547,7 @@ static int get_attr(struct sysfs_class_device *class_dev, struct device_attr *at
 
        attr->mode = 0;
        if (class_dev->sysdevice) {
 
        attr->mode = 0;
        if (class_dev->sysdevice) {
-               dbg_parse("class_dev->sysdevice->directory->path = '%s'", class_dev->sysdevice->directory->path);
+               dbg_parse("class_dev->sysdevice->path = '%s'", class_dev->sysdevice->path);
                dbg_parse("class_dev->sysdevice->bus_id = '%s'", class_dev->sysdevice->bus_id);
        } else {
                dbg_parse("class_dev->name = '%s'", class_dev->name);
                dbg_parse("class_dev->sysdevice->bus_id = '%s'", class_dev->sysdevice->bus_id);
        } else {
                dbg_parse("class_dev->name = '%s'", class_dev->name);
@@ -557,19 +557,21 @@ static int get_attr(struct sysfs_class_device *class_dev, struct device_attr *at
                switch (dev->type) {
                case LABEL:
                        {
                switch (dev->type) {
                case LABEL:
                        {
-                       char *temp;
+                       struct sysfs_attribute *tmpattr = NULL;
+                       struct sysfs_class_device *class_dev_parent = NULL;
+                       char *temp = NULL;
 
                        dbg_parse("LABEL: match file '%s' with value '%s'",
                                        dev->sysfs_file, dev->sysfs_value);
                        /* try to find the attribute in the class device directory */
 
                        dbg_parse("LABEL: match file '%s' with value '%s'",
                                        dev->sysfs_file, dev->sysfs_value);
                        /* try to find the attribute in the class device directory */
-                       temp = sysfs_get_value_from_attributes(class_dev->directory->attributes, dev->sysfs_file);
-                       if (temp)
+                       tmpattr = sysfs_get_classdev_attr(class_dev, dev->sysfs_file);
+                       if (tmpattr)
                                goto label_found;
 
                        /* look in the class device device directory if present */
                        if (class_dev->sysdevice) {
                                goto label_found;
 
                        /* look in the class device device directory if present */
                        if (class_dev->sysdevice) {
-                               temp = sysfs_get_value_from_attributes(class_dev->sysdevice->directory->attributes, dev->sysfs_file);
-                               if (temp)
+                               tmpattr = sysfs_get_classdev_attr(class_dev, dev->sysfs_file);
+                               if (tmpattr)
                                        goto label_found;
                        }
 
                                        goto label_found;
                        }
 
@@ -577,14 +579,13 @@ static int get_attr(struct sysfs_class_device *class_dev, struct device_attr *at
                         * as block partitions don't point to the physical device.  Need to fix that
                         * up in the kernel...
                         */
                         * as block partitions don't point to the physical device.  Need to fix that
                         * up in the kernel...
                         */
-                       if (strstr(class_dev->directory->path, "block")) {
+                       if (strstr(class_dev->path, "block")) {
                                dbg_parse("looking at block device...");
                                dbg_parse("looking at block device...");
-                               if (isdigit(class_dev->directory->path[strlen(class_dev->directory->path)-1])) {
+                               if (isdigit(class_dev->path[strlen(class_dev->path)-1])) {
                                        char path[SYSFS_PATH_MAX];
                                        char path[SYSFS_PATH_MAX];
-                                       struct sysfs_class_device *class_dev_parent;
 
                                        dbg_parse("really is a partition...");
 
                                        dbg_parse("really is a partition...");
-                                       strcpy(path, class_dev->directory->path);
+                                       strcpy(path, class_dev->path);
                                        temp = strrchr(path, '/');
                                        *temp = 0x00;
                                        dbg_parse("looking for a class device at '%s'", path);
                                        temp = strrchr(path, '/');
                                        *temp = 0x00;
                                        dbg_parse("looking for a class device at '%s'", path);
@@ -596,35 +597,36 @@ static int get_attr(struct sysfs_class_device *class_dev, struct device_attr *at
                                        dbg_parse("class_dev_parent->name = %s", class_dev_parent->name);
 
                                        /* try to find the attribute in the class device directory */
                                        dbg_parse("class_dev_parent->name = %s", class_dev_parent->name);
 
                                        /* try to find the attribute in the class device directory */
-                                       temp = sysfs_get_value_from_attributes(class_dev_parent->directory->attributes, dev->sysfs_file);
-                                       if (temp) {
-                                               //sysfs_close_class_device(class_dev_parent);
+                                       tmpattr = sysfs_get_classdev_attr(class_dev_parent, dev->sysfs_file);
+                                       if (tmpattr) 
                                                goto label_found;
                                                goto label_found;
-                                       }
 
                                        /* look in the class device device directory if present */
                                        if (class_dev_parent->sysdevice) {
 
                                        /* look in the class device device directory if present */
                                        if (class_dev_parent->sysdevice) {
-                                               temp = sysfs_get_value_from_attributes(class_dev_parent->sysdevice->directory->attributes, dev->sysfs_file);
-                                               if (temp) {
-                                                       // sysfs_close_class_device(class_dev_parent);
+                                               tmpattr = sysfs_get_classdev_attr(class_dev_parent, dev->sysfs_file);
+                                               if (tmpattr) 
                                                        goto label_found;
                                                        goto label_found;
-                                               }
                                        }
                                        
                                }
                        }
                                        }
                                        
                                }
                        }
+                       if (class_dev_parent)
+                               sysfs_close_class_device(class_dev_parent);
+
                        continue;
 
 label_found:
                        continue;
 
 label_found:
-                       temp[strlen(temp)-1] = 0x00;
-                       dbg_parse("file '%s' found with value '%s' compare with '%s'", dev->sysfs_file, temp, dev->sysfs_value);
-                       if (strcmp(dev->sysfs_value, temp) != 0)
+                       tmpattr->value[strlen(tmpattr->value)-1] = 0x00;
+                       dbg_parse("file '%s' found with value '%s' compare with '%s'", dev->sysfs_file, tmpattr->value, dev->sysfs_value);
+                       if (strcmp(dev->sysfs_value, tmpattr->value) != 0) {
+                               if (class_dev_parent) 
+                                       sysfs_close_class_device(class_dev_parent);
                                continue;
                                continue;
+                       }
 
                        strcpy(attr->name, dev->attr.name);
 
                        strcpy(attr->name, dev->attr.name);
-                       if (isdigit(class_dev->directory->path[strlen(class_dev->directory->path)-1])) {
-                               temp[0] = class_dev->directory->path[strlen(class_dev->directory->path)-1];
-                               temp[1] = 0x00;
+                       if (isdigit(class_dev->path[strlen(class_dev->path)-1])) {
+                               temp = &class_dev->path[strlen(class_dev->path)-1];
                                strcat(attr->name, temp);
                        }
                        if (dev->attr.mode != 0) {
                                strcat(attr->name, temp);
                        }
                        if (dev->attr.mode != 0) {
@@ -635,6 +637,8 @@ label_found:
                        dbg_parse("file '%s' with value '%s' becomes '%s' - owner = %s, group = %s, mode = %#o",
                                dev->sysfs_file, dev->sysfs_value, attr->name, 
                                dev->attr.owner, dev->attr.group, dev->attr.mode);
                        dbg_parse("file '%s' with value '%s' becomes '%s' - owner = %s, group = %s, mode = %#o",
                                dev->sysfs_file, dev->sysfs_value, attr->name, 
                                dev->attr.owner, dev->attr.group, dev->attr.mode);
+                       if (class_dev_parent)
+                               sysfs_close_class_device(class_dev_parent);
                        goto done;
                        break;
                        }
                        goto done;
                        break;
                        }
@@ -646,7 +650,7 @@ label_found:
                        found = 0;
                        if (!class_dev->sysdevice)
                                continue;
                        found = 0;
                        if (!class_dev->sysdevice)
                                continue;
-                       strcpy(path, class_dev->sysdevice->directory->path);
+                       strcpy(path, class_dev->sysdevice->path);
                        temp = strrchr(path, '/');
                        dbg_parse("NUMBER path = '%s'", path);
                        dbg_parse("NUMBER temp = '%s' id = '%s'", temp, dev->id);
                        temp = strrchr(path, '/');
                        dbg_parse("NUMBER path = '%s'", path);
                        dbg_parse("NUMBER temp = '%s' id = '%s'", temp, dev->id);
@@ -682,7 +686,7 @@ label_found:
                        if (!class_dev->sysdevice)
                                continue;
                        found = 0;      
                        if (!class_dev->sysdevice)
                                continue;
                        found = 0;      
-                       strcpy(path, class_dev->sysdevice->directory->path);
+                       strcpy(path, class_dev->sysdevice->path);
                        temp = strrchr(path, '/');
                        dbg_parse("TOPOLOGY path = '%s'", path);
                        dbg_parse("TOPOLOGY temp = '%s' place = '%s'", temp, dev->place);
                        temp = strrchr(path, '/');
                        dbg_parse("TOPOLOGY path = '%s'", path);
                        dbg_parse("TOPOLOGY temp = '%s' place = '%s'", temp, dev->place);