diff options
author | Lennart Poettering <lennart@poettering.net> | 2018-02-19 18:23:38 +0100 |
---|---|---|
committer | Sven Eden <yamakuzure@gmx.net> | 2018-05-30 07:59:00 +0200 |
commit | 71b2b9d7412a0f916f5be02c73f8b12e531babf8 (patch) | |
tree | 7f1555223e8a335ad2c6646b25e9cebdff34f265 /src/basic/fs-util.c | |
parent | a9f82387ce656c98cad320372002eee70369fdb4 (diff) |
fs-util: move fsync_directory_of_file() into generic code
This function used by the journal code is pretty useful generically,
let's move it to fs-util.c to make it useful for other code too.
Diffstat (limited to 'src/basic/fs-util.c')
-rw-r--r-- | src/basic/fs-util.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c index 87116d618..687a406d7 100644 --- a/src/basic/fs-util.c +++ b/src/basic/fs-util.c @@ -982,3 +982,33 @@ int unlinkat_deallocate(int fd, const char *name, int flags) { return 0; } + +int fsync_directory_of_file(int fd) { + _cleanup_free_ char *path = NULL, *dn = NULL; + _cleanup_close_ int dfd = -1; + int r; + + r = fd_verify_regular(fd); + if (r < 0) + return r; + + r = fd_get_path(fd, &path); + if (r < 0) + return r; + + if (!path_is_absolute(path)) + return -EINVAL; + + dn = dirname_malloc(path); + if (!dn) + return -ENOMEM; + + dfd = open(dn, O_RDONLY|O_CLOEXEC|O_DIRECTORY); + if (dfd < 0) + return -errno; + + if (fsync(dfd) < 0) + return -errno; + + return 0; +} |