[PATCH] losetup -f

Loïc Grenié loic.grenie at gmail.com
Fri Sep 21 07:59:19 UTC 2007


    This is a trivial patch to add a -f option to losetup. losetup -f shows the
  first free loop device. After the patch executable size is not changed in
  two of three arch that I've tested:

     AMD64: unchanged
     i386: unchanged
     i386: +4060bytes (different version of gcc)

  The code is incorrect if 1) there are less than 10 loop devices and 2) they
  are all busy (but I don't know loop devices enough to correct...).

    I use a custom version of ubuntu initrd using busybox 1.6.1 for nearly all
  executables (resulting in a 700kb smaller initrd.gz). losetup -f is
used during
  the boot, so that it'd be better if it got included in busybox.

   Untested suggestion to shave a couple of bytes from losetup.c:

		char dev[sizeof(LOOP_NAME"0")] = LOOP_NAME"0";
		char c;
		for (c = '0'; c <= '9'; ++c) {
			char *s;
			dev[sizeof(LOOP_NAME"0")-2] = c;
			s = query_loop(dev);

  can be modified into:

		char dev[sizeof(LOOP_NAME"0")] = LOOP_NAME"0";
		for (; dev[sizeof(dev)-2] <= '9'; ++dev[sizeof(dev)-2]) {
			char *s;
			s = query_loop(dev);

  (stylewise I prefer char dev[] = LOOP_NAME"0"; but I don't know whether
  all compilers would accept it and produce correct code).

    Cheers,

         Loïc
-------------- next part --------------
A non-text attachment was scrubbed...
Name: losetup-f.diff
Type: text/x-patch
Size: 4119 bytes
Desc: not available
Url : http://lists.busybox.net/pipermail/busybox/attachments/20070921/40dd4ba3/attachment-0002.bin 


More information about the busybox mailing list