fs-util: add API for fsync()ing parent dir of path

This commit is contained in:
Lennart Poettering
2021-07-08 10:22:34 +02:00
parent 427c934fdb
commit 814a7e0345
2 changed files with 25 additions and 0 deletions
+24
View File
@@ -1484,6 +1484,30 @@ int fsync_path_at(int at_fd, const char *path) {
return 0;
}
int fsync_parent_at(int at_fd, const char *path) {
_cleanup_close_ int opened_fd = -1;
if (isempty(path)) {
if (at_fd != AT_FDCWD)
return fsync_directory_of_file(at_fd);
opened_fd = open("..", O_RDONLY|O_DIRECTORY|O_CLOEXEC);
if (opened_fd < 0)
return -errno;
if (fsync(opened_fd) < 0)
return -errno;
return 0;
}
opened_fd = openat(at_fd, path, O_PATH|O_CLOEXEC|O_NOFOLLOW);
if (opened_fd < 0)
return -errno;
return fsync_directory_of_file(opened_fd);
}
int syncfs_path(int atfd, const char *path) {
_cleanup_close_ int fd = -1;