loop-util: add call for setting the autoclear flag at arbitrary times
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user