From 52f19d9678208ff18a18eb3560ece4ac465115c8 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 20 Sep 2022 13:39:51 +0200 Subject: [PATCH] stat-util: add statx_mount_same() to check if two stax refer to the same mount --- src/basic/stat-util.c | 13 +++++++++++++ src/basic/stat-util.h | 1 + 2 files changed, 14 insertions(+) diff --git a/src/basic/stat-util.c b/src/basic/stat-util.c index cb6fe9ebdb6..51adaca9d07 100644 --- a/src/basic/stat-util.c +++ b/src/basic/stat-util.c @@ -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; diff --git a/src/basic/stat-util.h b/src/basic/stat-util.h index 4972af0c695..f9519d8cbde 100644 --- a/src/basic/stat-util.h +++ b/src/basic/stat-util.h @@ -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);