chiark / gitweb /
libudev: list - use bit flags for 'sort' and 'unique'
[elogind.git] / libudev / libudev-device-private.c
index 406d8704f54e465f2d761cdce06e5f54d1a2b76f..b78b6c9553503b61e0c9aa07731c6ce2b894b2da 100644 (file)
@@ -31,7 +31,7 @@ static void udev_device_tag(struct udev_device *dev, const char *tag, bool add)
        id = udev_device_get_id_filename(dev);
        if (id == NULL)
                return;
-       util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev), "/.udev/tags/", tag, "/", id, NULL);
+       util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev), "/tags/", tag, "/", id, NULL);
 
        if (add) {
                int fd;
@@ -78,6 +78,7 @@ int udev_device_tag_index(struct udev_device *dev, struct udev_device *dev_old,
 
 static bool device_has_info(struct udev_device *udev_device)
 {
+       struct udev *udev = udev_device_get_udev(udev_device);
        struct udev_list_entry *list_entry;
 
        if (udev_device_get_devlinks_list_entry(udev_device) != NULL)
@@ -85,13 +86,16 @@ static bool device_has_info(struct udev_device *udev_device)
        if (udev_device_get_devlink_priority(udev_device) != 0)
                return true;
        udev_list_entry_foreach(list_entry, udev_device_get_properties_list_entry(udev_device))
-               if (udev_list_entry_get_flags(list_entry))
+               if (udev_list_entry_get_num(list_entry))
                        return true;
        if (udev_device_get_tags_list_entry(udev_device) != NULL)
                return true;
-       if (udev_device_get_knodename(udev_device) != NULL)
-               if (strcmp(udev_device_get_devnode(udev_device), udev_device_get_knodename(udev_device)) != 0)
+       if (udev_device_get_devnode(udev_device) != NULL && udev_device_get_knodename(udev_device) != NULL) {
+               size_t devlen = strlen(udev_get_dev_path(udev))+1;
+
+               if (strcmp(&udev_device_get_devnode(udev_device)[devlen], udev_device_get_knodename(udev_device)) != 0)
                        return true;
+       }
        if (udev_device_get_watch_handle(udev_device) >= 0)
                return true;
        return false;
@@ -111,10 +115,12 @@ int udev_device_update_db(struct udev_device *udev_device)
                return -1;
 
        has_info = device_has_info(udev_device);
-       util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev), "/.udev/db/", id, NULL);
+       util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev), "/data/", id, NULL);
 
        /* do not store anything for otherwise empty devices */
-       if (!has_info && udev_device_get_devnode(udev_device) == NULL) {
+       if (!has_info &&
+           major(udev_device_get_devnum(udev_device)) == 0 &&
+           udev_device_get_ifindex(udev_device) == 0) {
                unlink(filename);
                return 0;
        }
@@ -128,6 +134,13 @@ int udev_device_update_db(struct udev_device *udev_device)
                return -1;
        }
 
+       /*
+        * set 'sticky' bit to indicate that we should not clean the
+        * database when we transition from initramfs to the real root
+        */
+       if (udev_device_get_db_persist(udev_device))
+               fchmod(fileno(f), 01644);
+
        if (has_info) {
                size_t devlen = strlen(udev_get_dev_path(udev))+1;
                struct udev_list_entry *list_entry;
@@ -141,8 +154,10 @@ int udev_device_update_db(struct udev_device *udev_device)
                        fprintf(f, "L:%i\n", udev_device_get_devlink_priority(udev_device));
                if (udev_device_get_watch_handle(udev_device) >= 0)
                        fprintf(f, "W:%i\n", udev_device_get_watch_handle(udev_device));
+               if (udev_device_get_usec_initialized(udev_device) > 0)
+                       fprintf(f, "I:%llu\n", udev_device_get_usec_initialized(udev_device));
                udev_list_entry_foreach(list_entry, udev_device_get_properties_list_entry(udev_device)) {
-                       if (!udev_list_entry_get_flags(list_entry))
+                       if (!udev_list_entry_get_num(list_entry))
                                continue;
                        fprintf(f, "E:%s=%s\n",
                                udev_list_entry_get_name(list_entry),
@@ -168,7 +183,7 @@ int udev_device_delete_db(struct udev_device *udev_device)
        id = udev_device_get_id_filename(udev_device);
        if (id == NULL)
                return -1;
-       util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev), "/.udev/db/", id, NULL);
+       util_strscpyl(filename, sizeof(filename), udev_get_run_path(udev), "/data/", id, NULL);
        unlink(filename);
        return 0;
 }