From: Lennart Poettering Date: Thu, 30 Jul 2020 16:48:52 +0000 (+0200) Subject: loop-util: define API for syncing loopback device X-Git-Tag: v247-rc1~369^2~17 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8dbc208cc1a7bbd9af44d98df4a4eb472266699a;p=thirdparty%2Fsystemd.git loop-util: define API for syncing loopback device --- diff --git a/src/shared/loop-util.c b/src/shared/loop-util.c index 8db2fed66ff..fb88f51849a 100644 --- a/src/shared/loop-util.c +++ b/src/shared/loop-util.c @@ -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; +} diff --git a/src/shared/loop-util.h b/src/shared/loop-util.h index 73f82a6d305..16f215b059a 100644 --- a/src/shared/loop-util.h +++ b/src/shared/loop-util.h @@ -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);