summaryrefslogtreecommitdiff
path: root/src/shared
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
parentc37878fcedd9c767db766ddfdeefc3f5281377ef (diff)
downloadsystemd-441ec80468d17a548c8c85e39a0b0e74b75f2650.tar.gz
loop-util: add api for locking the block device with flock()
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/loop-util.c13
-rw-r--r--src/shared/loop-util.h2
2 files changed, 15 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;
+}
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);