diff --git a/src/shared/loop-util.c b/src/shared/loop-util.c index b1d07fe708..f9be08bf35 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 e5a0ae75b8..5156b46ad6 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);