]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
stat-util: also include inode type in hash ops
authorLennart Poettering <lennart@amutable.com>
Tue, 24 Mar 2026 15:56:40 +0000 (16:56 +0100)
committerLennart Poettering <lennart@amutable.com>
Tue, 24 Mar 2026 20:21:10 +0000 (21:21 +0100)
This doesn't really have any major benefit, but it does make this nicely
mirror stat_inode_same() which also checks this triplet for identifying
identical inodes.

src/basic/stat-util.c
src/basic/stat-util.h

index ef39562992ca0ef282ab472036e24a3e16d745a4..98dfa8c5a97374d5d29110ac1df2eeef73f79125 100644 (file)
@@ -709,6 +709,10 @@ nsec_t statx_timestamp_load_nsec(const struct statx_timestamp *ts) {
 void inode_hash_func(const struct stat *q, struct siphash *state) {
         siphash24_compress_typesafe(q->st_dev, state);
         siphash24_compress_typesafe(q->st_ino, state);
+
+        /* Also include inode type, to mirror stat_inode_same() */
+        mode_t type = q->st_mode & S_IFMT;
+        siphash24_compress_typesafe(type, state);
 }
 
 int inode_compare_func(const struct stat *a, const struct stat *b) {
@@ -718,7 +722,11 @@ int inode_compare_func(const struct stat *a, const struct stat *b) {
         if (r != 0)
                 return r;
 
-        return CMP(a->st_ino, b->st_ino);
+        r = CMP(a->st_ino, b->st_ino);
+        if (r != 0)
+                return r;
+
+        return CMP(a->st_mode & S_IFMT, b->st_mode & S_IFMT);
 }
 
 DEFINE_HASH_OPS_WITH_KEY_DESTRUCTOR(inode_hash_ops, struct stat, inode_hash_func, inode_compare_func, free);
index c261014cd2953fed1301eb4ff4a789c9ef30a981..939a0fc398db4bb25bd0060bd794177aa6a96e63 100644 (file)
@@ -122,6 +122,7 @@ int xstatfsat(int dir_fd, const char *path, struct statfs *ret);
 usec_t statx_timestamp_load(const struct statx_timestamp *ts) _pure_;
 nsec_t statx_timestamp_load_nsec(const struct statx_timestamp *ts) _pure_;
 
+/* This compares inode number, backing device and inode type, but not modification info */
 void inode_hash_func(const struct stat *q, struct siphash *state);
 int inode_compare_func(const struct stat *a, const struct stat *b);
 extern const struct hash_ops inode_hash_ops;