-
- trie.f = fopen(SYSCONFDIR "/udev/hwdb.bin", "re");
- if (!trie.f)
- return -errno;
-
- if (fstat(fileno(trie.f), &st) < 0 || (size_t)st.st_size < offsetof(struct trie_header_f, strings_len) + 8) {
- log_error("Error reading '%s'.", SYSCONFDIR "/udev/hwdb.bin: %m");
- fclose(trie.f);
- zero(trie);
- return -EINVAL;
- }
-
- trie.map = mmap(0, st.st_size, PROT_READ, MAP_SHARED, fileno(trie.f), 0);
- if (trie.map == MAP_FAILED) {
- log_error("Error mapping '%s'.", SYSCONFDIR "/udev/hwdb.bin: %m");
- fclose(trie.f);
- return -EINVAL;
- }
- trie.file_time_usec = ts_usec(&st.st_mtim);
- trie.map_size = st.st_size;
-
- if (memcmp(trie.map, sig, sizeof(trie.head->signature)) != 0 || (size_t)st.st_size != le64toh(trie.head->file_size)) {
- log_error("Unable to recognize the format of '%s'.", SYSCONFDIR "/udev/hwdb.bin");
- log_error("Please try 'udevadm hwdb --update' to re-create it.");
- munmap((void *)trie.map, st.st_size);
- fclose(trie.f);
- zero(trie);
- return EINVAL;
- }
-
- log_debug("=== trie on-disk ===\n");
- log_debug("tool version: %llu", (unsigned long long)le64toh(trie.head->tool_version));
- log_debug("file size: %8zi bytes\n", st.st_size);
- log_debug("header size %8zu bytes\n", (size_t)le64toh(trie.head->header_size));
- log_debug("strings %8zu bytes\n", (size_t)le64toh(trie.head->strings_len));
- log_debug("nodes %8zu bytes\n", (size_t)le64toh(trie.head->nodes_len));