loop-util: add call for setting the autoclear flag at arbitrary times

This commit is contained in:
Lennart Poettering
2023-03-09 16:40:55 +01:00
parent 4d2a9e3ea6
commit d2430d5097
2 changed files with 21 additions and 0 deletions
+19
View 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;
}
+2
View 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);