+/* reverse mapping from the device file name to the devpath */
+static int name_index(const char *devpath, const char *name, int add)
+{
+ char device[PATH_SIZE];
+ char filename[PATH_SIZE * 2];
+ size_t start;
+ int fd;
+
+ /* directory with device name */
+ strlcpy(filename, udev_root, sizeof(filename));
+ start = strlcat(filename, "/"DB_NAME_INDEX_DIR"/", sizeof(filename));
+ strlcat(filename, name, sizeof(filename));
+ path_encode(&filename[start], sizeof(filename) - start);
+ /* entry with the devpath */
+ strlcpy(device, devpath, sizeof(device));
+ path_encode(device, sizeof(device));
+ strlcat(filename, "/", sizeof(filename));
+ strlcat(filename, device, sizeof(filename));
+
+ if (add) {
+ info("creating index: '%s'", filename);
+ create_path(filename);
+ fd = open(filename, O_WRONLY|O_TRUNC|O_CREAT, 0644);
+ if (fd > 0)
+ close(fd);
+ } else {
+ info("removing index: '%s'", filename);
+ unlink(filename);
+ delete_path(filename);
+ }