From: Lennart Poettering Date: Tue, 21 May 2019 16:04:04 +0000 (+0200) Subject: loop-util: add api for locking the block device with flock() X-Git-Tag: v245-rc1~310^2~4 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=441ec80468d17a548c8c85e39a0b0e74b75f2650;p=thirdparty%2Fsystemd.git loop-util: add api for locking the block device with flock() --- diff --git a/src/shared/loop-util.c b/src/shared/loop-util.c index b1d07fe708f..f9be08bf35a 100644 --- a/src/shared/loop-util.c +++ b/src/shared/loop-util.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include "alloc-util.h" @@ -233,3 +234,15 @@ int loop_device_refresh_size(LoopDevice *d, uint64_t offset, uint64_t size) { return 0; } + +int loop_device_flock(LoopDevice *d, int operation) { + assert(d); + + if (d->fd < 0) + return -EBADF; + + if (flock(d->fd, operation) < 0) + return -errno; + + return 0; +} diff --git a/src/shared/loop-util.h b/src/shared/loop-util.h index e5a0ae75b8c..5156b46ad61 100644 --- a/src/shared/loop-util.h +++ b/src/shared/loop-util.h @@ -28,3 +28,5 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(LoopDevice*, loop_device_unref); 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);