]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
loop-util: add api for locking the block device with flock()
authorLennart Poettering <lennart@poettering.net>
Tue, 21 May 2019 16:04:04 +0000 (18:04 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 2 Dec 2019 09:06:12 +0000 (10:06 +0100)
src/shared/loop-util.c
src/shared/loop-util.h

index b1d07fe708f3c76e665217fe96e4425fd1bb94bc..f9be08bf35ad11b40ab2af9efd339c537ddb9d92 100644 (file)
@@ -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;
+}
index e5a0ae75b8cf0aee144b1f6697a5eee3caa87b64..5156b46ad611a37d856af0151503ad75be301219 100644 (file)
@@ -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);