Lines Matching refs:hwdb
103 static const struct trie_child_entry_f *trie_node_children(struct udev_hwdb *hwdb, const struct tri… in trie_node_children() argument
104 … return (const struct trie_child_entry_f *)((const char *)node + le64toh(hwdb->head->node_size)); in trie_node_children()
107 static const struct trie_value_entry_f *trie_node_values(struct udev_hwdb *hwdb, const struct trie_… in trie_node_values() argument
110 base += le64toh(hwdb->head->node_size); in trie_node_values()
111 base += node->children_count * le64toh(hwdb->head->child_entry_size); in trie_node_values()
115 static const struct trie_node_f *trie_node_from_off(struct udev_hwdb *hwdb, le64_t off) { in trie_node_from_off() argument
116 return (const struct trie_node_f *)(hwdb->map + le64toh(off)); in trie_node_from_off()
119 static const char *trie_string(struct udev_hwdb *hwdb, le64_t off) { in trie_string() argument
120 return hwdb->map + le64toh(off); in trie_string()
130 static const struct trie_node_f *node_lookup_f(struct udev_hwdb *hwdb, const struct trie_node_f *no… in node_lookup_f() argument
135 child = bsearch(&search, trie_node_children(hwdb, node), node->children_count, in node_lookup_f()
136 le64toh(hwdb->head->child_entry_size), trie_children_cmp_f); in node_lookup_f()
138 return trie_node_from_off(hwdb, child->child_off); in node_lookup_f()
142 static int hwdb_add_property(struct udev_hwdb *hwdb, const char *key, const char *value) { in hwdb_add_property() argument
150 if (udev_list_entry_add(&hwdb->properties_list, key+1, value) == NULL) in hwdb_add_property()
155 static int trie_fnmatch_f(struct udev_hwdb *hwdb, const struct trie_node_f *node, size_t p, in trie_fnmatch_f() argument
162 prefix = trie_string(hwdb, node->prefix_off); in trie_fnmatch_f()
167 const struct trie_child_entry_f *child = &trie_node_children(hwdb, node)[i]; in trie_fnmatch_f()
170 … err = trie_fnmatch_f(hwdb, trie_node_from_off(hwdb, child->child_off), 0, buf, search); in trie_fnmatch_f()
178 … err = hwdb_add_property(hwdb, trie_string(hwdb, trie_node_values(hwdb, node)[i].key_off), in trie_fnmatch_f()
179 … trie_string(hwdb, trie_node_values(hwdb, node)[i].value_off)); in trie_fnmatch_f()
188 static int trie_search_f(struct udev_hwdb *hwdb, const char *search) { in trie_search_f() argument
196 node = trie_node_from_off(hwdb, hwdb->head->nodes_root_off); in trie_search_f()
204 for (; (c = trie_string(hwdb, node->prefix_off)[p]); p++) { in trie_search_f()
206 return trie_fnmatch_f(hwdb, node, p, &buf, search + i + p); in trie_search_f()
213 child = node_lookup_f(hwdb, node, '*'); in trie_search_f()
216 err = trie_fnmatch_f(hwdb, child, 0, &buf, search + i); in trie_search_f()
222 child = node_lookup_f(hwdb, node, '?'); in trie_search_f()
225 err = trie_fnmatch_f(hwdb, child, 0, &buf, search + i); in trie_search_f()
231 child = node_lookup_f(hwdb, node, '['); in trie_search_f()
234 err = trie_fnmatch_f(hwdb, child, 0, &buf, search + i); in trie_search_f()
244 … err = hwdb_add_property(hwdb, trie_string(hwdb, trie_node_values(hwdb, node)[n].key_off), in trie_search_f()
245 … trie_string(hwdb, trie_node_values(hwdb, node)[n].value_off)); in trie_search_f()
252 child = node_lookup_f(hwdb, node, search[i]); in trie_search_f()
268 struct udev_hwdb *hwdb; in udev_hwdb_new() local
271 hwdb = new0(struct udev_hwdb, 1); in udev_hwdb_new()
272 if (!hwdb) in udev_hwdb_new()
275 hwdb->refcount = 1; in udev_hwdb_new()
276 udev_list_init(udev, &hwdb->properties_list, true); in udev_hwdb_new()
278 hwdb->f = fopen(UDEV_HWDB_BIN, "re"); in udev_hwdb_new()
279 if (!hwdb->f) { in udev_hwdb_new()
281 udev_hwdb_unref(hwdb); in udev_hwdb_new()
285 if (fstat(fileno(hwdb->f), &hwdb->st) < 0 || in udev_hwdb_new()
286 (size_t)hwdb->st.st_size < offsetof(struct trie_header_f, strings_len) + 8) { in udev_hwdb_new()
288 udev_hwdb_unref(hwdb); in udev_hwdb_new()
292 hwdb->map = mmap(0, hwdb->st.st_size, PROT_READ, MAP_SHARED, fileno(hwdb->f), 0); in udev_hwdb_new()
293 if (hwdb->map == MAP_FAILED) { in udev_hwdb_new()
295 udev_hwdb_unref(hwdb); in udev_hwdb_new()
299 if (memcmp(hwdb->map, sig, sizeof(hwdb->head->signature)) != 0 || in udev_hwdb_new()
300 (size_t)hwdb->st.st_size != le64toh(hwdb->head->file_size)) { in udev_hwdb_new()
302 udev_hwdb_unref(hwdb); in udev_hwdb_new()
307 log_debug("tool version: %"PRIu64, le64toh(hwdb->head->tool_version)); in udev_hwdb_new()
308 log_debug("file size: %8"PRIu64" bytes", hwdb->st.st_size); in udev_hwdb_new()
309 log_debug("header size %8"PRIu64" bytes", le64toh(hwdb->head->header_size)); in udev_hwdb_new()
310 log_debug("strings %8"PRIu64" bytes", le64toh(hwdb->head->strings_len)); in udev_hwdb_new()
311 log_debug("nodes %8"PRIu64" bytes", le64toh(hwdb->head->nodes_len)); in udev_hwdb_new()
312 return hwdb; in udev_hwdb_new()
323 _public_ struct udev_hwdb *udev_hwdb_ref(struct udev_hwdb *hwdb) { in udev_hwdb_ref() argument
324 if (!hwdb) in udev_hwdb_ref()
326 hwdb->refcount++; in udev_hwdb_ref()
327 return hwdb; in udev_hwdb_ref()
339 _public_ struct udev_hwdb *udev_hwdb_unref(struct udev_hwdb *hwdb) { in udev_hwdb_unref() argument
340 if (!hwdb) in udev_hwdb_unref()
342 hwdb->refcount--; in udev_hwdb_unref()
343 if (hwdb->refcount > 0) in udev_hwdb_unref()
345 if (hwdb->map) in udev_hwdb_unref()
346 munmap((void *)hwdb->map, hwdb->st.st_size); in udev_hwdb_unref()
347 if (hwdb->f) in udev_hwdb_unref()
348 fclose(hwdb->f); in udev_hwdb_unref()
349 udev_list_cleanup(&hwdb->properties_list); in udev_hwdb_unref()
350 free(hwdb); in udev_hwdb_unref()
354 bool udev_hwdb_validate(struct udev_hwdb *hwdb) { in udev_hwdb_validate() argument
357 if (!hwdb) in udev_hwdb_validate()
359 if (!hwdb->f) in udev_hwdb_validate()
364 if (timespec_load(&hwdb->st.st_mtim) != timespec_load(&st.st_mtim)) in udev_hwdb_validate()
382 _public_ struct udev_list_entry *udev_hwdb_get_properties_list_entry(struct udev_hwdb *hwdb, const … in udev_hwdb_get_properties_list_entry() argument
385 if (!hwdb || !hwdb->f) { in udev_hwdb_get_properties_list_entry()
390 udev_list_cleanup(&hwdb->properties_list); in udev_hwdb_get_properties_list_entry()
391 err = trie_search_f(hwdb, modalias); in udev_hwdb_get_properties_list_entry()
396 return udev_list_get_entry(&hwdb->properties_list); in udev_hwdb_get_properties_list_entry()