losetup: support unlimited number of loops
Old implementation:
- supports 256 loop devices only
- doesn't support gaps in list of loop devices
(e.g. loop0, loop1, loop3 -- loop3 is invisible)
Kernel 2.6.21 removes artificial maximum 256 loop device. Now the maximum
of loop devices could be really huge (depends on limit of MINOR
numbers). It means we need a better way how work with loop devices
than blindly call stat(2) for all 0-
1048575 devices.
This patch uses three methods:
a) scan /sys/block/loopN (used for losetup -a only). This method is
probably the fastest way how found used loop device on machine with
huge number of devices in /dev.
b) classic way, stat(2) for all loop[0-7] devices (default number of
loop devices). This cheap method is sufficient for 99% of all machines.
c) scan all /dev/loopN or /dev/loop/N
Signed-off-by: Karel Zak <kzak@redhat.com>