util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev), "/.udev/tags/", tag, "/", id, NULL);
if (add) {
+ int fd;
+
util_create_path(udev, filename);
- symlink(udev_device_get_devpath(dev), filename);
+ fd = open(filename, O_WRONLY|O_CREAT|O_CLOEXEC|O_TRUNC|O_NOFOLLOW, 0444);
+ if (fd >= 0)
+ close(fd);
} else {
unlink(filename);
}
return udev_device_new_from_syspath(udev, path);
}
+struct udev_device *udev_device_new_from_id_filename(struct udev *udev, char *id)
+{
+ char type;
+ int maj, min;
+ char subsys[UTIL_PATH_SIZE];
+ char *sysname;
+
+ switch(id[0]) {
+ case 'b':
+ case 'c':
+ if (sscanf(id, "%c%i:%i", &type, &maj, &min) != 3)
+ return NULL;
+ return udev_device_new_from_devnum(udev, type, makedev(maj, min));
+ case '+':
+ util_strscpy(subsys, sizeof(subsys), &id[1]);
+ sysname = strchr(subsys, ':');
+ if (sysname == NULL)
+ return NULL;
+ sysname[0] = '\0';
+ sysname = &sysname[1];
+ return udev_device_new_from_subsystem_sysname(udev, subsys, sysname);
+ default:
+ return NULL;
+ }
+}
+
/**
* udev_device_new_from_subsystem_sysname:
* @udev: udev library context
continue;
for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
struct udev_device *dev;
- char syspath[UTIL_PATH_SIZE];
- char *s;
- size_t l;
- ssize_t len;
if (dent->d_name[0] == '.')
continue;
- s = syspath;
- l = util_strpcpyl(&s, sizeof(syspath), udev_get_sys_path(udev), NULL);
- len = readlinkat(dirfd(dir), dent->d_name, s, l);
- if (len <= 0 || (size_t)len == l)
- continue;
- s[len] = '\0';
-
- dev = udev_device_new_from_syspath(udev_enumerate->udev, syspath);
+ dev = udev_device_new_from_id_filename(udev_enumerate->udev, dent->d_name);
if (dev == NULL)
continue;
syspath_add(udev_enumerate, udev_device_get_syspath(dev));
/* libudev-device.c */
struct udev_device *udev_device_new(struct udev *udev);
+struct udev_device *udev_device_new_from_id_filename(struct udev *udev, char *id);
int udev_device_set_syspath(struct udev_device *udev_device, const char *syspath);
int udev_device_set_subsystem(struct udev_device *udev_device, const char *subsystem);
int udev_device_set_devtype(struct udev_device *udev_device, const char *devtype);
for (;;) {
struct udev_device *dev_db;
struct dirent *dent;
- int maj, min;
- char type, type2;
- dev_t devnum;
dent = readdir(dir);
if (dent == NULL || dent->d_name[0] == '\0')
break;
if (dent->d_name[0] == '.')
continue;
- if (sscanf(dent->d_name, "%c%i:%i", &type, &maj, &min) != 3)
- continue;
- info(udev, "found '%c%i:%i' claiming '%s'\n", type, maj, min, stackdir);
- devnum = makedev(maj, min);
+
+ info(udev, "found '%s' claiming '%s'\n", dent->d_name, stackdir);
/* did we find ourself? */
- type2 = strcmp(udev_device_get_subsystem(dev), "block") == 0 ? 'b' : 'c';
- if (udev_device_get_devnum(dev) == devnum && type == type2)
+ if (strcmp(dent->d_name, udev_device_get_id_filename(dev)) == 0)
continue;
- dev_db = udev_device_new_from_devnum(udev, type, devnum);
+ dev_db = udev_device_new_from_id_filename(udev, dent->d_name);
if (dev_db != NULL) {
const char *devnode;
size_t l;
ssize_t len;
struct udev_device *dev;
- int maj, min;
- char type;
if (ent->d_name[0] == '.')
continue;
goto unlink;
s[len] = '\0';
- if (sscanf(s, "%c%i:%i", &type, &maj, &min) != 3)
- goto unlink;
- dev = udev_device_new_from_devnum(udev, type, makedev(maj, min));
+ dev = udev_device_new_from_id_filename(udev, s);
if (dev == NULL)
goto unlink;
char *s;
size_t l;
ssize_t len;
- int maj, min;
- char type;
- dev_t devnum;
if (inotify_fd < 0 || wd < 0)
return NULL;
return NULL;
s[len] = '\0';
- if (sscanf(s, "%c%i:%i", &type, &maj, &min) != 3)
- return NULL;
- devnum = makedev(maj, min);
- return udev_device_new_from_devnum(udev, type, devnum);
+ return udev_device_new_from_id_filename(udev, s);
}