]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
stat-util: Add xstatfsat()
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 31 Mar 2023 08:39:55 +0000 (10:39 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Sat, 1 Apr 2023 12:25:30 +0000 (14:25 +0200)
src/basic/stat-util.c
src/basic/stat-util.h

index 2b09ab63b2520eb72b2bb6a33b961fa235dda96f..e97770707f2099c8a29ad1d0ac2eb932287efb7b 100644 (file)
@@ -455,6 +455,20 @@ int statx_fallback(int dfd, const char *path, int flags, unsigned mask, struct s
         return 0;
 }
 
+int xstatfsat(int dir_fd, const char *path, struct statfs *ret) {
+        _cleanup_close_ int fd = -EBADF;
+
+        assert(dir_fd >= 0 || dir_fd == AT_FDCWD);
+        assert(path);
+        assert(ret);
+
+        fd = xopenat(dir_fd, path, O_PATH|O_CLOEXEC|O_NOCTTY, 0);
+        if (fd < 0)
+                return fd;
+
+        return RET_NERRNO(fstatfs(fd, ret));
+}
+
 void inode_hash_func(const struct stat *q, struct siphash *state) {
         siphash24_compress(&q->st_dev, sizeof(q->st_dev), state);
         siphash24_compress(&q->st_ino, sizeof(q->st_ino), state);
index 726d0644aa634a142e760df12b2911e022eccc44..e6b84d215e0afca050b91743f581f645cb1c67df 100644 (file)
@@ -79,6 +79,8 @@ 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);
 
+int xstatfsat(int dir_fd, const char *path, struct statfs *ret);
+
 #if HAS_FEATURE_MEMORY_SANITIZER
 #  warning "Explicitly initializing struct statx, to work around msan limitation. Please remove as soon as msan has been updated to not require this."
 #  define STRUCT_STATX_DEFINE(var)              \