]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
loop-util: add call for setting the autoclear flag at arbitrary times
authorLennart Poettering <lennart@poettering.net>
Mon, 6 Mar 2023 11:07:18 +0000 (12:07 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 9 Mar 2023 15:40:55 +0000 (16:40 +0100)
src/shared/loop-util.c
src/shared/loop-util.h

index 96a42b4125797b7b5c01f5730abb834573d145e9..27a58952bbda33436ea1b205a7261278bf52125b 100644 (file)
@@ -1111,3 +1111,22 @@ int loop_device_sync(LoopDevice *d) {
 
         return RET_NERRNO(fsync(d->fd));
 }
+
+int loop_device_set_autoclear(LoopDevice *d, bool autoclear) {
+        struct loop_info64 info;
+
+        assert(d);
+
+        if (ioctl(d->fd, LOOP_GET_STATUS64, &info) < 0)
+                return -errno;
+
+        if (autoclear == FLAGS_SET(info.lo_flags, LO_FLAGS_AUTOCLEAR))
+                return 0;
+
+        SET_FLAG(info.lo_flags, LO_FLAGS_AUTOCLEAR, autoclear);
+
+        if (ioctl(d->fd, LOOP_SET_STATUS64, &info) < 0)
+                return -errno;
+
+        return 1;
+}
index ea461434e9cec65f3f456737d8b46e55f4d21b84..c98b69ceee7197a9237c63e206783c5fb49e0fd3 100644 (file)
@@ -49,3 +49,5 @@ int loop_device_refresh_size(LoopDevice *d, uint64_t offset, uint64_t size);
 
 int loop_device_flock(LoopDevice *d, int operation);
 int loop_device_sync(LoopDevice *d);
+
+int loop_device_set_autoclear(LoopDevice *d, bool autoclear);