]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fs-util: add new helper syncfs_path()
authorLennart Poettering <lennart@poettering.net>
Wed, 23 Jan 2019 15:08:55 +0000 (16:08 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 1 Mar 2019 11:41:32 +0000 (12:41 +0100)
src/basic/fs-util.c
src/basic/fs-util.h

index 3ff861579735c3bf573d8207d4a1360c9e3945f9..0d631093b29fabac8ef20ed74b1a57b8d1825300 100644 (file)
@@ -1330,6 +1330,21 @@ int fsync_path_at(int at_fd, const char *path) {
         return 0;
 }
 
+int syncfs_path(int atfd, const char *path) {
+        _cleanup_close_ int fd = -1;
+
+        assert(path);
+
+        fd = openat(atfd, path, O_CLOEXEC|O_RDONLY|O_NONBLOCK);
+        if (fd < 0)
+                return -errno;
+
+        if (syncfs(fd) < 0)
+                return -errno;
+
+        return 0;
+}
+
 int open_parent(const char *path, int flags, mode_t mode) {
         _cleanup_free_ char *parent = NULL;
         int fd;
index 7ad030be5d0e4a7c71a136e371f953892b4b81dd..9c9044669d9c436672870c91b297105703100fc8 100644 (file)
@@ -108,4 +108,6 @@ int unlinkat_deallocate(int fd, const char *name, int flags);
 int fsync_directory_of_file(int fd);
 int fsync_path_at(int at_fd, const char *path);
 
+int syncfs_path(int atfd, const char *path);
+
 int open_parent(const char *path, int flags, mode_t mode);