From: Lennart Poettering Date: Mon, 22 Jul 2019 11:48:12 +0000 (+0200) Subject: fs-util: add fsync_full() helper X-Git-Tag: v243-rc1~32^2~25 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=63d59b8dcf4a911703e5188bc14c39b5eea0d050;p=thirdparty%2Fsystemd.git fs-util: add fsync_full() helper We usually combine an fsync() with fsync_directory_of_file() hence let's add a helper that does both in one. --- diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c index 3ed8e2c8a93..f929db9c230 100644 --- a/src/basic/fs-util.c +++ b/src/basic/fs-util.c @@ -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; diff --git a/src/basic/fs-util.h b/src/basic/fs-util.h index c5527cc44fd..c7c58998155 100644 --- a/src/basic/fs-util.h +++ b/src/basic/fs-util.h @@ -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);