| |
| |
| #include "sd-hwdb.h" |
| |
| #include "alloc-util.h" |
| #include "hwdb-util.h" |
| #include "libudev-private.h" |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| struct udev_hwdb { |
| struct udev *udev; |
| int refcount; |
| |
| sd_hwdb *hwdb; |
| |
| struct udev_list properties_list; |
| }; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| _public_ struct udev_hwdb *udev_hwdb_new(struct udev *udev) { |
| _cleanup_(sd_hwdb_unrefp) sd_hwdb *hwdb_internal = NULL; |
| struct udev_hwdb *hwdb; |
| int r; |
| |
| assert_return_errno(udev, NULL, EINVAL); |
| |
| r = sd_hwdb_new(&hwdb_internal); |
| if (r < 0) { |
| errno = -r; |
| return NULL; |
| } |
| |
| hwdb = new0(struct udev_hwdb, 1); |
| if (!hwdb) { |
| errno = ENOMEM; |
| return NULL; |
| } |
| |
| hwdb->refcount = 1; |
| hwdb->hwdb = TAKE_PTR(hwdb_internal); |
| |
| udev_list_init(udev, &hwdb->properties_list, true); |
| |
| return hwdb; |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| _public_ struct udev_hwdb *udev_hwdb_ref(struct udev_hwdb *hwdb) { |
| if (!hwdb) |
| return NULL; |
| hwdb->refcount++; |
| return hwdb; |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| _public_ struct udev_hwdb *udev_hwdb_unref(struct udev_hwdb *hwdb) { |
| if (!hwdb) |
| return NULL; |
| hwdb->refcount--; |
| if (hwdb->refcount > 0) |
| return NULL; |
| sd_hwdb_unref(hwdb->hwdb); |
| udev_list_cleanup(&hwdb->properties_list); |
| return mfree(hwdb); |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| _public_ struct udev_list_entry *udev_hwdb_get_properties_list_entry(struct udev_hwdb *hwdb, const char *modalias, unsigned int flags) { |
| const char *key, *value; |
| struct udev_list_entry *e; |
| |
| if (!hwdb || !modalias) { |
| errno = EINVAL; |
| return NULL; |
| } |
| |
| udev_list_cleanup(&hwdb->properties_list); |
| |
| SD_HWDB_FOREACH_PROPERTY(hwdb->hwdb, modalias, key, value) { |
| if (udev_list_entry_add(&hwdb->properties_list, key, value) == NULL) { |
| errno = ENOMEM; |
| return NULL; |
| } |
| } |
| |
| e = udev_list_get_entry(&hwdb->properties_list); |
| if (!e) |
| errno = ENODATA; |
| |
| return e; |
| } |