1
0
mirror of https://github.com/systemd/systemd.git synced 2024-10-30 06:25:37 +03:00

stat-util: add statx_mount_same() to check if two stax refer to the same mount

This commit is contained in:
Lennart Poettering 2022-09-20 13:39:51 +02:00
parent 2bd315fb2b
commit 52f19d9678
2 changed files with 14 additions and 0 deletions

View 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;

View 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);