diff options
author | Lennart Poettering <lennart@poettering.net> | 2022-09-19 16:51:08 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2022-09-20 13:52:01 +0200 |
commit | 2bd315fb2be91654839e148c02d96a837f87a38b (patch) | |
tree | ea250802bce9b6bc0f816b1fa3a372ab58ae73d3 /src/basic/stat-util.c | |
parent | d45dee7c0073d22943f367a35314396bb0b40168 (diff) | |
download | systemd-2bd315fb2be91654839e148c02d96a837f87a38b.tar.gz |
stat-util: add statx_inode_same() helper to check if two statx structs refer to same inode
The same as stat_inode_same(), but for struct statx rather than struct
stat.
Diffstat (limited to 'src/basic/stat-util.c')
-rw-r--r-- | src/basic/stat-util.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/basic/stat-util.c b/src/basic/stat-util.c index c31b4d89d0..cb6fe9ebdb 100644 --- a/src/basic/stat-util.c +++ b/src/basic/stat-util.c @@ -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; |