diff options
author | Daan De Meyer <daan.j.demeyer@gmail.com> | 2023-06-01 13:57:58 +0200 |
---|---|---|
committer | Daan De Meyer <daan.j.demeyer@gmail.com> | 2023-06-06 14:42:03 +0200 |
commit | b196e17ed40987b102d72993d15de3567be742cb (patch) | |
tree | 48cb2a16a2819587d71a2b2875368fda1eac1f21 /src | |
parent | stat-util: Follow coding style in xstatfsat() (diff) | |
download | systemd-b196e17ed40987b102d72993d15de3567be742cb.tar.xz systemd-b196e17ed40987b102d72993d15de3567be742cb.zip |
stat-util: Add is_fs_type_at()
Diffstat (limited to 'src')
-rw-r--r-- | src/basic/stat-util.c | 17 | ||||
-rw-r--r-- | src/basic/stat-util.h | 9 |
2 files changed, 12 insertions, 14 deletions
diff --git a/src/basic/stat-util.c b/src/basic/stat-util.c index 4db11f9299..3c999098e1 100644 --- a/src/basic/stat-util.c +++ b/src/basic/stat-util.c @@ -207,20 +207,13 @@ bool is_fs_type(const struct statfs *s, statfs_f_type_t magic_value) { return F_TYPE_EQUAL(s->f_type, magic_value); } -int fd_is_fs_type(int fd, statfs_f_type_t magic_value) { - struct statfs s; - - if (fstatfs(fd, &s) < 0) - return -errno; - - return is_fs_type(&s, magic_value); -} - -int path_is_fs_type(const char *path, statfs_f_type_t magic_value) { +int is_fs_type_at(int dir_fd, const char *path, statfs_f_type_t magic_value) { struct statfs s; + int r; - if (statfs(path, &s) < 0) - return -errno; + r = xstatfsat(dir_fd, path, &s); + if (r < 0) + return r; return is_fs_type(&s, magic_value); } diff --git a/src/basic/stat-util.h b/src/basic/stat-util.h index 3ae8b3eeb1..ae0aaf8f51 100644 --- a/src/basic/stat-util.h +++ b/src/basic/stat-util.h @@ -48,8 +48,13 @@ static inline int inode_same(const char *filea, const char *fileb, int flags) { typedef typeof(((struct statfs*)NULL)->f_type) statfs_f_type_t; bool is_fs_type(const struct statfs *s, statfs_f_type_t magic_value) _pure_; -int fd_is_fs_type(int fd, statfs_f_type_t magic_value); -int path_is_fs_type(const char *path, statfs_f_type_t magic_value); +int is_fs_type_at(int dir_fd, const char *path, statfs_f_type_t magic_value); +static inline int fd_is_fs_type(int fd, statfs_f_type_t magic_value) { + return is_fs_type_at(fd, NULL, magic_value); +} +static inline int path_is_fs_type(const char *path, statfs_f_type_t magic_value) { + return is_fs_type_at(AT_FDCWD, path, magic_value); +} bool is_temporary_fs(const struct statfs *s) _pure_; bool is_network_fs(const struct statfs *s) _pure_; |