]> git.ipfire.org Git - thirdparty/systemd.git/commit
hwdb, sd-hwdb: rework priority comparison when loading properties
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 30 Nov 2016 01:26:35 +0000 (20:26 -0500)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 30 Nov 2016 20:49:14 +0000 (15:49 -0500)
commitd8646d05724a658cc60fb03f105db8ead454eba3
treeaa504a6c17788264d9cdd3cb96709aaaba107ce6
parent389be927b485ceb7351963986232fb6975860680
hwdb, sd-hwdb: rework priority comparison when loading properties

We cannot compare filenames directly, because paths are not sortable
lexicographically, e.g. /etc/udev is "later" (has higher priority)
than /usr/lib/udev.

The on-disk format is changed to have a separate field for "file priority",
which is stored when writing the binary file, and then loaded and used in
comparisons. For data in the previous format (as generated by systemd 232),
this information is not available, and we use a trick where the offset into the
string table is used as a proxy for priority. Most of the time strings are
stored in the order in which the files were processed. This is not entirely
reliable, but is good enough to properly order /usr/lib and /etc/, which are
the two most common cases. This hack is included because it allows proper
parsing of files until the binary hwdb is regenerated.

Instead of adding a new field, I reduced the size of line_number from 64 to 32
bits, and added a 16 bit priority field, and 16 bits of padding. Adding a new
field of 16 bytes would significantly screw up alignment and increase file
size, and line number realistically don't need more than ~20 bits.

Fixes #4750.
src/hwdb/hwdb.c
src/libsystemd/sd-hwdb/hwdb-internal.h
src/libsystemd/sd-hwdb/sd-hwdb.c