summaryrefslogtreecommitdiffstats
path: root/src/shared/loop-util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2019-05-21 18:04:04 +0200
committerLennart Poettering <lennart@poettering.net>2019-12-02 10:06:12 +0100
commit441ec80468d17a548c8c85e39a0b0e74b75f2650 (patch)
tree2fecfd97547074e3ed6d0118066288ed9c13fd54 /src/shared/loop-util.c
parentloop-util: allow refreshing offset (diff)
downloadsystemd-441ec80468d17a548c8c85e39a0b0e74b75f2650.tar.xz
systemd-441ec80468d17a548c8c85e39a0b0e74b75f2650.zip
loop-util: add api for locking the block device with flock()
Diffstat (limited to 'src/shared/loop-util.c')
-rw-r--r--src/shared/loop-util.c13
1 files changed, 13 insertions, 0 deletions
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 <errno.h>
#include <fcntl.h>
#include <linux/loop.h>
+#include <sys/file.h>
#include <sys/ioctl.h>
#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;
+}