]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
stat-util: add statx_mount_same() to check if two stax refer to the same mount
authorLennart Poettering <lennart@poettering.net>
Tue, 20 Sep 2022 11:39:51 +0000 (13:39 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 20 Sep 2022 11:52:01 +0000 (13:52 +0200)
src/basic/stat-util.c
src/basic/stat-util.h

index cb6fe9ebdb647955a268f7e5a6846014a8498e44..51adaca9d070ce10d0838a3801d460586bc83fd5 100644 (file)
@@ -373,6 +373,19 @@ bool statx_inode_same(const struct statx *a, const struct statx *b) {
                 a->stx_ino == b->stx_ino;
 }
 
+bool statx_mount_same(const struct new_statx *a, const struct new_statx *b) {
+        if (!a || !b)
+                return false;
+
+        /* if we have the mount ID, that's all we need */
+        if (FLAGS_SET(a->stx_mask, STATX_MNT_ID) && FLAGS_SET(b->stx_mask, STATX_MNT_ID))
+                return a->stx_mnt_id == b->stx_mnt_id;
+
+        /* Otherwise, major/minor of backing device must match */
+        return a->stx_dev_major == b->stx_dev_major &&
+                a->stx_dev_minor == b->stx_dev_minor;
+}
+
 int statx_fallback(int dfd, const char *path, int flags, unsigned mask, struct statx *sx) {
         static bool avoid_statx = false;
         struct stat st;
index 4972af0c695d09eca3a5852b66701eacde10d5e6..f9519d8cbde3591cb142d059238a641e5751f449 100644 (file)
@@ -74,6 +74,7 @@ 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);
+bool statx_mount_same(const struct new_statx *a, const struct new_statx *b);
 
 int statx_fallback(int dfd, const char *path, int flags, unsigned mask, struct statx *sx);