]> err.no Git - systemd/commitdiff
add util_resolve_subsys_kernel()
authorKay Sievers <kay.sievers@vrfy.org>
Wed, 22 Oct 2008 16:03:38 +0000 (18:03 +0200)
committerKay Sievers <kay.sievers@vrfy.org>
Wed, 22 Oct 2008 16:03:38 +0000 (18:03 +0200)
extras/floppy/Makefile.am
udev/udev-util.c
udev/udev.h

index c812689586c1533817e84c25b0dd9d31daa7c818..8dadefa08d4b61b60740975936dcc2afb85a0622 100644 (file)
@@ -10,6 +10,8 @@ create_floppy_devices_SOURCES = \
        ../../udev/lib/libudev.c \
        ../../udev/lib/libudev-list.c \
        ../../udev/lib/libudev-util.c \
+       ../../udev/lib/libudev-device.c \
+       ../../udev/lib/libudev-enumerate.c \
        ../../udev/udev-util.c
 
 if USE_SELINUX
index 76445bbcdcc234bc2adb9668cfa1385b01a9b16a..3c2e2a508908a9be48f960ffc8c99b965fb82125 100644 (file)
@@ -162,6 +162,69 @@ extern gid_t util_lookup_group(struct udev *udev, const char *group)
        return gid;
 }
 
+/* handle "[<SUBSYSTEM>/<KERNEL>]<attribute>" format */
+int util_resolve_subsys_kernel(struct udev *udev, const char *string,
+                              char *result, size_t maxsize, int read_value)
+{
+       char temp[UTIL_PATH_SIZE];
+       char *subsys;
+       char *sysname;
+       struct udev_device *dev;
+       char *attr;
+
+       if (string == NULL)
+               string = result;
+       if (string[0] != '[')
+               return -1;
+
+       util_strlcpy(temp, string, sizeof(temp));
+
+       subsys = &temp[1];
+
+       sysname = strchr(subsys, '/');
+       if (sysname == NULL)
+               return -1;
+       sysname[0] = '\0';
+       sysname = &sysname[1];
+
+       attr = strchr(sysname, ']');
+       if (attr == NULL)
+               return -1;
+       attr[0] = '\0';
+       attr = &attr[1];
+       if (attr[0] == '/')
+               attr = &attr[1];
+       if (attr[0] == '\0')
+               attr = NULL;
+
+       if (read_value && attr == NULL)
+               return -1;
+
+       dev = udev_device_new_from_subsystem_sysname(udev, subsys, sysname);
+       if (dev == NULL)
+               return -1;
+
+       if (read_value) {
+               const char *val;
+
+               val = udev_device_get_sysattr_value(dev, attr);
+               if (val != NULL)
+                       util_strlcpy(result, val, maxsize);
+               else
+                       result[0] = '\0';
+               info(udev, "value '[%s/%s]%s' is '%s'\n", subsys, sysname, attr, result);
+       } else {
+               util_strlcpy(result, udev_device_get_syspath(dev), maxsize);
+               if (attr != NULL) {
+                       util_strlcat(result, "/", maxsize);
+                       util_strlcat(result, attr, maxsize);
+               }
+               info(udev, "path '[%s/%s]%s' is '%s'\n", subsys, sysname, attr, result);
+       }
+       udev_device_unref(dev);
+       return 0;
+}
+
 int util_run_program(struct udev *udev, const char *command, char **envp,
                     char *result, size_t ressize, size_t *reslen)
 {
index 89f6f11edfd1b1262b5dae3f42f46dbb028b590b..217e942c18fddb05f806b1ef79df11fb7b7df6bb 100644 (file)
@@ -112,6 +112,8 @@ extern uid_t util_lookup_user(struct udev *udev, const char *user);
 extern gid_t util_lookup_group(struct udev *udev, const char *group);
 extern int util_run_program(struct udev *udev, const char *command, char **envp,
                            char *result, size_t ressize, size_t *reslen);
+extern int util_resolve_subsys_kernel(struct udev *udev, const char *string,
+                                     char *result, size_t maxsize, int read_value);
 
 /* udev-selinux.c */
 #ifndef USE_SELINUX