+
+ util_strlcpy(path, udev_device_get_syspath(udev_device), sizeof(path));
+ util_strlcat(path, "/", sizeof(path));
+ util_strlcat(path, attr, sizeof(path));
+
+ if (lstat(path, &statbuf) != 0) {
+ info(udev_device->udev, "stat '%s' failed: %s\n", path, strerror(errno));
+ goto out;
+ }
+
+ if (S_ISLNK(statbuf.st_mode)) {
+ /* links return the last element of the target path */
+ char target[UTIL_NAME_SIZE];
+ int len;
+ char *pos;
+
+ len = readlink(path, target, sizeof(target));
+ if (len > 0) {
+ target[len] = '\0';
+ pos = strrchr(target, '/');
+ if (pos != NULL) {
+ pos = &pos[1];
+ info(udev_device->udev, "cache '%s' with link value '%s'\n", attr, pos);
+ list_entry = list_entry_add(udev_device->udev, &udev_device->attr_list, attr, pos, 0, 0);
+ val = udev_list_entry_get_value(list_entry);
+ }
+ }
+ goto out;
+ }
+
+ /* skip directories */
+ if (S_ISDIR(statbuf.st_mode))
+ goto out;
+
+ /* skip non-readable files */
+ if ((statbuf.st_mode & S_IRUSR) == 0)
+ goto out;
+
+ /* read attribute value */
+ fd = open(path, O_RDONLY);
+ if (fd < 0) {
+ info(udev_device->udev, "attribute '%s' can not be opened\n", path);
+ goto out;
+ }
+ size = read(fd, value, sizeof(value));
+ close(fd);
+ if (size < 0)
+ goto out;
+ if (size == sizeof(value))
+ goto out;
+
+ /* got a valid value, store it in cache and return it */
+ value[size] = '\0';
+ util_remove_trailing_chars(value, '\n');
+ info(udev_device->udev, "'%s' has attribute value '%s'\n", path, value);
+ list_entry = list_entry_add(udev_device->udev, &udev_device->attr_list, attr, value, 0, 0);
+ val = udev_list_entry_get_value(list_entry);
+out:
+ return val;
+}
+int device_set_syspath(struct udev_device *udev_device, const char *syspath)
+{
+ const char *pos;
+
+ udev_device->syspath = strdup(syspath);
+ if (udev_device->syspath == NULL)
+ return -ENOMEM;
+ udev_device->devpath = &udev_device->syspath[strlen(udev_get_sys_path(udev_device->udev))];
+ pos = strrchr(udev_device->syspath, '/');
+ if (pos == NULL)
+ return -EINVAL;
+ udev_device->sysname = &pos[1];
+ return 0;
+}
+
+int device_set_subsystem(struct udev_device *udev_device, const char *subsystem)
+{
+ udev_device->subsystem = strdup(subsystem);
+ if (udev_device->subsystem == NULL)
+ return -1;
+ return 0;
+}
+
+int device_set_devnode(struct udev_device *udev_device, const char *devnode)
+{
+ udev_device->devnode = strdup(devnode);
+ if (udev_device->devnode == NULL)
+ return -ENOMEM;
+ return 0;
+}
+
+int device_add_devlink(struct udev_device *udev_device, const char *devlink)
+{
+ if (list_entry_add(udev_device->udev, &udev_device->devlink_list, devlink, NULL, 1, 0) == NULL)
+ return -ENOMEM;
+ return 0;
+}
+
+int device_add_property(struct udev_device *udev_device, const char *key, const char *value)
+{
+ if (list_entry_add(udev_device->udev, &udev_device->properties_list, key, value, 1, 0) == NULL)
+ return -ENOMEM;
+ return 0;
+}
+
+int device_add_property_from_string(struct udev_device *udev_device, const char *property)
+{
+ char name[UTIL_PATH_SIZE];
+ char *val;
+
+ strncpy(name, property, sizeof(name));
+ val = strchr(name, '=');
+ if (val == NULL)
+ return -1;
+ val[0] = '\0';
+ val = &val[1];
+ if (val[0] == '\0')
+ val = NULL;
+ device_add_property(udev_device, name, val);
+ return 0;
+}
+
+int device_set_action(struct udev_device *udev_device, const char *action)
+{
+ udev_device->action = strdup(action);
+ if (udev_device->action == NULL)
+ return -ENOMEM;
+ return 0;
+}
+
+int device_set_driver(struct udev_device *udev_device, const char *driver)
+{
+ udev_device->driver = strdup(driver);
+ if (udev_device->driver == NULL)
+ return -ENOMEM;
+ return 0;
+}
+
+const char *device_get_devpath_old(struct udev_device *udev_device)
+{
+ return udev_device->devpath_old;
+}
+
+int device_set_devpath_old(struct udev_device *udev_device, const char *devpath_old)
+{
+ udev_device->devpath_old = strdup(devpath_old);
+ if (udev_device->devpath_old == NULL)
+ return -ENOMEM;
+ return 0;
+}
+
+const char *device_get_physdevpath(struct udev_device *udev_device)
+{
+ return udev_device->physdevpath;
+}
+
+int device_set_physdevpath(struct udev_device *udev_device, const char *physdevpath)
+{
+ udev_device->physdevpath = strdup(physdevpath);
+ if (udev_device->physdevpath == NULL)
+ return -ENOMEM;
+ return 0;
+}
+
+int device_get_timeout(struct udev_device *udev_device)
+{
+ return udev_device->timeout;
+}
+
+int device_set_timeout(struct udev_device *udev_device, int timeout)
+{
+ udev_device->timeout = timeout;
+ return 0;
+}
+int device_get_event_timeout(struct udev_device *udev_device)
+{
+ if (!udev_device->info_loaded)
+ device_load_info(udev_device);
+ return udev_device->event_timeout;
+}
+
+int device_set_event_timeout(struct udev_device *udev_device, int event_timeout)
+{
+ udev_device->event_timeout = event_timeout;
+ return 0;