stat-util: add statx_inode_same() helper to check if two statx structs refer to same...
authorLennart Poettering <lennart@poettering.net>
Mon, 19 Sep 2022 14:51:08 +0000 (16:51 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 20 Sep 2022 11:52:01 +0000 (13:52 +0200)
The same as stat_inode_same(), but for struct statx rather than struct
stat.

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

index c31b4d89d020e35c6d00be51bfa8f5377a4498d1..cb6fe9ebdb647955a268f7e5a6846014a8498e44 100644 (file)
@@ -360,6 +360,19 @@ bool stat_inode_unmodified(const struct stat *a, const struct stat *b) {
                 (!(S_ISCHR(a->st_mode) || S_ISBLK(a->st_mode)) || a->st_rdev == b->st_rdev); /* if device node, also compare major/minor, because we can */
 }
 
+bool statx_inode_same(const struct statx *a, const struct statx *b) {
+
+        /* Same as stat_inode_same() but for struct statx */
+
+        return a && b &&
+                FLAGS_SET(a->stx_mask, STATX_TYPE|STATX_INO) && FLAGS_SET(b->stx_mask, STATX_TYPE|STATX_INO) &&
+                (a->stx_mode & S_IFMT) != 0 &&
+                ((a->stx_mode ^ b->stx_mode) & S_IFMT) == 0 &&
+                a->stx_dev_major == b->stx_dev_major &&
+                a->stx_dev_minor == b->stx_dev_minor &&
+                a->stx_ino == b->stx_ino;
+}
+
 int statx_fallback(int dfd, const char *path, int flags, unsigned mask, struct statx *sx) {
         static bool avoid_statx = false;
         struct stat st;
index 56f15534aa2565d51f0f6b0f1ecd8bc44785f93b..4972af0c695d09eca3a5852b66701eacde10d5e6 100644 (file)
@@ -73,6 +73,8 @@ int proc_mounted(void);
 bool stat_inode_same(const struct stat *a, const struct stat *b);
 bool stat_inode_unmodified(const struct stat *a, const struct stat *b);
 
+bool statx_inode_same(const struct statx *a, const struct statx *b);
+
 int statx_fallback(int dfd, const char *path, int flags, unsigned mask, struct statx *sx);
 
 #if HAS_FEATURE_MEMORY_SANITIZER