]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
loop-util: define API for syncing loopback device
authorLennart Poettering <lennart@poettering.net>
Thu, 30 Jul 2020 16:48:52 +0000 (18:48 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 24 Aug 2020 19:59:35 +0000 (21:59 +0200)
src/shared/loop-util.c
src/shared/loop-util.h

index 8db2fed66ff3ee4336e0a68678000e1f099998ad..fb88f51849a70f1e0fb8c3d4e59e77d81320c956 100644 (file)
@@ -472,3 +472,18 @@ int loop_device_flock(LoopDevice *d, int operation) {
 
         return 0;
 }
+
+int loop_device_sync(LoopDevice *d) {
+        assert(d);
+
+        /* We also do this implicitly in loop_device_unref(). Doing this explicitly here has the benefit that
+         * we can check the return value though. */
+
+        if (d->fd < 0)
+                return -EBADF;
+
+        if (fsync(d->fd) < 0)
+                return -errno;
+
+        return 0;
+}
index 73f82a6d3054ecbdb5a7b7b0d0830759fffa9d43..16f215b059ab3fd68231b1321aaf841ebb0abc24 100644 (file)
@@ -26,3 +26,4 @@ void loop_device_relinquish(LoopDevice *d);
 int loop_device_refresh_size(LoopDevice *d, uint64_t offset, uint64_t size);
 
 int loop_device_flock(LoopDevice *d, int operation);
+int loop_device_sync(LoopDevice *d);