]> git.ipfire.org Git - thirdparty/systemd.git/commit
devnum-util: add macros to safely convert dev_t to pointers and back
authorLennart Poettering <lennart@poettering.net>
Thu, 23 Jan 2025 10:40:36 +0000 (11:40 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 23 Jan 2025 21:16:24 +0000 (22:16 +0100)
commitd15811d7e5bb3fc3afc1c14e4d5bb3b18fddedc1
treeca47d395b90fd65475e9043db852c153501a3f56
parent16ea491528cb3268b7a6020c8cded1825d17ea9b
devnum-util: add macros to safely convert dev_t to pointers and back

Sometimes it's nice being able to store dev_t as pointer values in
hashmaps/tables, instead of having to allocate memory for them and using
devt_hash_ops. After all dev_t is weird on Linux/glibc: glibc defines it
as 64bit entity (which hence appears as something we cannot encode in a
pointer value for compat with 32bit archs) but it actually is 32bit in
the kernel apis. Hence we can safely cut off the upper 32bit, and still
retain compat with all archs.

But let's hide this in new macros, and validate this is all correct via
a test.
src/basic/devnum-util.h
src/test/test-devnum-util.c