LOOP_CONFIGURE is added to Linux 5.8 This allows userspace to completely setup a loop device with a single ioctl, removing the in-between state where the device can be partially configured - eg the loop device has a backing file associated with it, but is reading from the wrong offset.
https://lwn.net/Articles/820408/ https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=3448914e8cc5 LINUX_VERSION_CODE >= KERNEL_VERSION(5,8,0): function old new delta set_loop 703 626 -77 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-77) Total: -77 bytes else: add/remove: 0/0 grow/shrink: 0/0 up/down: 0/0 (0) Signed-off-by: Xiaoming Ni <nixiaom...@huawei.com> --- libbb/loop.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/libbb/loop.c b/libbb/loop.c index 9a7ca666d..d4f4906b0 100644 --- a/libbb/loop.c +++ b/libbb/loop.c @@ -126,6 +126,30 @@ static int open_file(const char *file, unsigned flags, int *mode) return ffd; } +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,8,0) + +/* + * loop: Add LOOP_CONFIGURE ioctl + * https://lwn.net/Articles/820408/ + * https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=3448914e8cc5 + */ +static int set_loop_configure(int ffd, int lfd, bb_loop_info *loopinfo) +{ + int rc; + struct loop_config config; + + memset(&config, 0, sizeof(config)); + config.fd = ffd; + memcpy(&config.info, loopinfo, sizeof(config.info)); + + rc = ioctl(lfd, LOOP_CONFIGURE, &config); + if (rc == 0) { + return lfd; + } + return -1; +} + +#else static int set_loop_configure(int ffd, int lfd, bb_loop_info *loopinfo) { int rc; @@ -149,6 +173,7 @@ static int set_loop_configure(int ffd, int lfd, bb_loop_info *loopinfo) ioctl(lfd, LOOP_CLR_FD, 0); // actually, 0 param is unnecessary return -1; } +#endif static int set_loop_info(int ffd, int lfd, bb_loop_info *loopinfo) { -- 2.27.0 _______________________________________________ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox