]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fs-util: add fsync_full() helper
authorLennart Poettering <lennart@poettering.net>
Mon, 22 Jul 2019 11:48:12 +0000 (13:48 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 25 Jul 2019 15:10:51 +0000 (17:10 +0200)
We usually combine an fsync() with fsync_directory_of_file() hence let's
add a helper that does both in one.

src/basic/fs-util.c
src/basic/fs-util.h

index 3ed8e2c8a9371bf62865fbac4cebb0cc5493433b..f929db9c23006e27212bc657eb474bd020b94bf1 100644 (file)
@@ -1298,6 +1298,17 @@ int fsync_directory_of_file(int fd) {
         return 0;
 }
 
+int fsync_full(int fd) {
+        int r, q;
+
+        /* Sync both the file and the directory */
+
+        r = fsync(fd) < 0 ? -errno : 0;
+        q = fsync_directory_of_file(fd);
+
+        return r < 0 ? r : q;
+}
+
 int fsync_path_at(int at_fd, const char *path) {
         _cleanup_close_ int opened_fd = -1;
         int fd;
index c5527cc44fdf18a9d101f1e53de5c5002d76dbcf..c7c58998155d06a3bcdf3c1e800a3a98d714ade9 100644 (file)
@@ -114,6 +114,7 @@ void unlink_tempfilep(char (*p)[]);
 int unlinkat_deallocate(int fd, const char *name, int flags);
 
 int fsync_directory_of_file(int fd);
+int fsync_full(int fd);
 int fsync_path_at(int at_fd, const char *path);
 
 int syncfs_path(int atfd, const char *path);