[Tutor] free loop device

Nathan McBride nomb85 at comcast.net
Tue May 6 04:14:27 CEST 2008


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Yup, I got some help in IRC.  What I ended up doing was using regex to
pull out each "/dev/loopX".  Then
took the X and fed it to max which in turn gave me the highest numbered
loop device in use.  After which I
then just added 1 to X and added it to the end of "/dev/loop_".  The
only other thing I had to do was put a
check in incase there were no used loop devices in which case then it
defaults to "/dev/loop0".

Works like a charm. :D

Nate

bob gailer wrote:
> Nathan McBride wrote:
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> Hey Guys,
>>
>> I have a program that uses the loop devices.  However I originally was
>> finding the free one with:
>> 'losetup -f'.  Which returns the next free loop device. :D  However, I
>> found that some of the other distros
>> have a version of losetup that does not include that switch.  So I am
>> trying to work up another way to get the
>> next device.
>>
>> What I'm figuring is doing 'losetup -a', parsing the returned data, and
>> incrementing it by one...
>> However I don't know how to accomplish this.  An example 'losetup -a'
>> would be like this:
>>
>> [root at localhost Desktop]# losetup -a
>> /dev/loop0: [fd00]:11305639 (enc)
>> /dev/loop1: [fd00]:11306533 (/home/nmcbride/Desktop/xxxxxxxxxxxxxxx.iso)
>>
>> Can anyone give me a hand?
>>  
>
> I for one have no idea how this relates to Python. If others do then
they are likely to help you.
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org

iD8DBQFIH78C/n+duykW6K8RAuE3AJoDu69W1D7dldLPxXpCfRGuoc++FQCgj2G3
4fG0aSw7fe/noi4hqesG9oA=
=vas+
-----END PGP SIGNATURE-----



More information about the Tutor mailing list