chiark / gitweb /
libudev: udev_device_get_devname -> udev_device_get_devnode
[elogind.git] / udev / udevadm-info.c
index 4a9ebcd..dbcaaff 100644 (file)
@@ -15,8 +15,6 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "config.h"
-
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
@@ -150,7 +148,7 @@ static void print_record(struct udev_device *device)
 
        printf("P: %s\n", udev_device_get_devpath(device));
        len = strlen(udev_get_dev_path(udev_device_get_udev(device)));
 
        printf("P: %s\n", udev_device_get_devpath(device));
        len = strlen(udev_get_dev_path(udev_device_get_udev(device)));
-       printf("N: %s\n", &udev_device_get_devname(device)[len+1]);
+       printf("N: %s\n", &udev_device_get_devnode(device)[len+1]);
        i = device_get_devlink_priority(device);
        if (i != 0)
                printf("L: %i\n", i);
        i = device_get_devlink_priority(device);
        if (i != 0)
                printf("L: %i\n", i);
@@ -165,29 +163,19 @@ static void print_record(struct udev_device *device)
        printf("\n");
 }
 
        printf("\n");
 }
 
-static int export_all_cb(struct udev *udev,
-                        const char *devpath, const char *subsystem, const char *name,
-                        void *data)
+static int export_all_cb(struct udev_device *device, void *data)
 {
 {
-       struct udev_device *device;
-
-       device = udev_device_new_from_devpath(udev, devpath);
-       if (device == NULL)
-               return 0;
-       if (udev_device_get_devname(device) != NULL)
+       if (udev_device_get_devnode(device) != NULL)
                print_record(device);
                print_record(device);
-       udev_device_unref(device);
        return 0;
 }
 
 static struct udev_device *lookup_device_by_name(struct udev *udev, const char *name)
 {
        return 0;
 }
 
 static struct udev_device *lookup_device_by_name(struct udev *udev, const char *name)
 {
-#if 0
-       /* FIXME */
+       struct udev_device *udev_device = NULL;
        LIST_HEAD(name_list);
        int count;
        struct name_entry *device;
        LIST_HEAD(name_list);
        int count;
        struct name_entry *device;
-       int rc  = -1;
 
        count = udev_db_get_devices_by_name(udev, name, &name_list);
        if (count <= 0)
 
        count = udev_db_get_devices_by_name(udev, name, &name_list);
        if (count <= 0)
@@ -195,7 +183,7 @@ static struct udev_device *lookup_device_by_name(struct udev *udev, const char *
 
        info(udev, "found %i devices for '%s'\n", count, name);
 
 
        info(udev, "found %i devices for '%s'\n", count, name);
 
-       /* select the device that seems to match */
+       /* select the device that matches */
        list_for_each_entry(device, &name_list, node) {
                struct udevice *udevice_loop;
                char filename[UTIL_PATH_SIZE];
        list_for_each_entry(device, &name_list, node) {
                struct udevice *udevice_loop;
                char filename[UTIL_PATH_SIZE];
@@ -207,7 +195,6 @@ static struct udev_device *lookup_device_by_name(struct udev *udev, const char *
                if (udev_db_get_device(udevice_loop, device->name) != 0)
                        goto next;
                info(udev, "found db entry '%s'\n", device->name);
                if (udev_db_get_device(udevice_loop, device->name) != 0)
                        goto next;
                info(udev, "found db entry '%s'\n", device->name);
-
                /* make sure, we don't get a link of a different device */
                util_strlcpy(filename, udev_get_dev_path(udev), sizeof(filename));
                util_strlcat(filename, "/", sizeof(filename));
                /* make sure, we don't get a link of a different device */
                util_strlcpy(filename, udev_get_dev_path(udev), sizeof(filename));
                util_strlcat(filename, "/", sizeof(filename));
@@ -218,17 +205,17 @@ static struct udev_device *lookup_device_by_name(struct udev *udev, const char *
                        info(udev, "skip '%s', dev_t doesn't match\n", udevice_loop->name);
                        goto next;
                }
                        info(udev, "skip '%s', dev_t doesn't match\n", udevice_loop->name);
                        goto next;
                }
-               rc = 0;
-               *udevice = udevice_loop;
+               util_strlcpy(filename, udev_get_sys_path(udev), sizeof(filename));
+               util_strlcat(filename,  udevice_loop->dev->devpath, sizeof(filename));
+               udev_device = udev_device_new_from_syspath(udev, filename);
+               udev_device_cleanup(udevice_loop);
                break;
 next:
                udev_device_cleanup(udevice_loop);
        }
 out:
        name_list_cleanup(udev, &name_list);
                break;
 next:
                udev_device_cleanup(udevice_loop);
        }
 out:
        name_list_cleanup(udev, &name_list);
-       return rc;
-#endif
-       return NULL;
+       return udev_device;
 }
 
 static int add_devlink_cb(struct udev_device *device, const char *value, void *data)
 }
 
 static int add_devlink_cb(struct udev_device *device, const char *value, void *data)
@@ -353,13 +340,15 @@ int udevadm_info(struct udev *udev, int argc, char *argv[])
                                rc = 2;
                                goto exit;
                        }
                                rc = 2;
                                goto exit;
                        }
-                       /* remove /sys if given */
-                       if (strncmp(optarg, udev_get_sys_path(udev), strlen(udev_get_sys_path(udev))) == 0)
-                               util_strlcpy(path, &optarg[strlen(udev_get_sys_path(udev))], sizeof(path));
-                       else
+                       /* add /sys if needed */
+                       if (strncmp(optarg, udev_get_sys_path(udev), strlen(udev_get_sys_path(udev))) != 0) {
+                               util_strlcpy(path, udev_get_sys_path(udev), sizeof(path));
+                               util_strlcat(path, optarg, sizeof(path));
+                       } else {
                                util_strlcpy(path, optarg, sizeof(path));
                                util_strlcpy(path, optarg, sizeof(path));
+                       }
                        util_remove_trailing_chars(path, '/');
                        util_remove_trailing_chars(path, '/');
-                       device = udev_device_new_from_devpath(udev, path);
+                       device = udev_device_new_from_syspath(udev, path);
                        break;
                case 'q':
                        action = ACTION_QUERY;
                        break;
                case 'q':
                        action = ACTION_QUERY;
@@ -439,7 +428,7 @@ int udevadm_info(struct udev *udev, int argc, char *argv[])
        switch (action) {
        case ACTION_QUERY:
                if (device == NULL) {
        switch (action) {
        case ACTION_QUERY:
                if (device == NULL) {
-                       fprintf(stderr, "query needs --path= or node --name= specified\n");
+                       fprintf(stderr, "query needs a valid device specified by --path= or --name=\n");
                        rc = 4;
                        goto exit;
                }
                        rc = 4;
                        goto exit;
                }
@@ -447,12 +436,12 @@ int udevadm_info(struct udev *udev, int argc, char *argv[])
                switch(query) {
                case QUERY_NAME:
                        if (root) {
                switch(query) {
                case QUERY_NAME:
                        if (root) {
-                               printf("%s\n", udev_device_get_devname(device));
+                               printf("%s\n", udev_device_get_devnode(device));
                        } else {
                                size_t len;
 
                                len = strlen(udev_get_dev_path(udev));
                        } else {
                                size_t len;
 
                                len = strlen(udev_get_dev_path(udev));
-                               printf("%s\n", &udev_device_get_devname(device)[len+1]);
+                               printf("%s\n", &udev_device_get_devnode(device)[len+1]);
                        }
                        break;
                case QUERY_SYMLINK:
                        }
                        break;
                case QUERY_SYMLINK:
@@ -480,7 +469,7 @@ int udevadm_info(struct udev *udev, int argc, char *argv[])
                break;
        case ACTION_ATTRIBUTE_WALK:
                if (device == NULL) {
                break;
        case ACTION_ATTRIBUTE_WALK:
                if (device == NULL) {
-                       fprintf(stderr, "attribute walk needs --path or node --name specified\n");
+                       fprintf(stderr, "query needs a valid device specified by --path= or --name=\n");
                        rc = 5;
                        goto exit;
                }
                        rc = 5;
                        goto exit;
                }