diff options
author | Daan De Meyer <daan.j.demeyer@gmail.com> | 2022-09-23 19:00:23 +0200 |
---|---|---|
committer | Daan De Meyer <daan.j.demeyer@gmail.com> | 2022-11-10 15:59:18 +0100 |
commit | ddfdf86f813679a3bfce7f5a50a8143d1bd720c4 (patch) | |
tree | 8386cc4182968d64c48b6da25091b0550c4073ea /src/basic/stat-util.c | |
parent | build: Use -fstrict-flex-arrays=1 if supported (diff) | |
download | systemd-ddfdf86f813679a3bfce7f5a50a8143d1bd720c4.tar.xz systemd-ddfdf86f813679a3bfce7f5a50a8143d1bd720c4.zip |
stat-util: Move inode_hash_ops to stat-util
TO make it usable in other code.
Diffstat (limited to 'src/basic/stat-util.c')
-rw-r--r-- | src/basic/stat-util.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/basic/stat-util.c b/src/basic/stat-util.c index 51adaca9d0..97dbcaac66 100644 --- a/src/basic/stat-util.c +++ b/src/basic/stat-util.c @@ -15,6 +15,7 @@ #include "fileio.h" #include "filesystems.h" #include "fs-util.h" +#include "hash-funcs.h" #include "macro.h" #include "missing_fs.h" #include "missing_magic.h" @@ -441,3 +442,20 @@ int statx_fallback(int dfd, const char *path, int flags, unsigned mask, struct s return 0; } + +void inode_hash_func(const struct stat *q, struct siphash *state) { + siphash24_compress(&q->st_dev, sizeof(q->st_dev), state); + siphash24_compress(&q->st_ino, sizeof(q->st_ino), state); +} + +int inode_compare_func(const struct stat *a, const struct stat *b) { + int r; + + r = CMP(a->st_dev, b->st_dev); + if (r != 0) + return r; + + return CMP(a->st_ino, b->st_ino); +} + +DEFINE_HASH_OPS_WITH_KEY_DESTRUCTOR(inode_hash_ops, struct stat, inode_hash_func, inode_compare_func, free); |