Re: use of losetup

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



very good discussion....

On Mon, Oct 20, 2008 at 6:46 PM, Luciano Rocha <luciano@xxxxxxxxxxx> wrote:
> On Mon, Oct 20, 2008 at 03:28:07PM +0530, rishi agrawal wrote:
>> Hello Everyone,
>>
>> I would like to know about the use of "losetup".
>>
>> By use I want mean that in what all situations will I use losetup. Its
>> okay that it attaches a loop device to any regular file but how do we
>> use this feature.
>
> Anytime you use the option loop to mount, you use (indirectly) losetup:
>
> mount -o loop,ro distro.iso /mnt
>

YES, and sometimes, u don't need to mount with loop option to read
these iso files, (or files created via dd + mkfs):

http://user-mode-linux.sourceforge.net/new/index.html   (ie, the UML
executable will take as input these files and mount it as "ubd" - UML
block device, naming is my guess).

Implementation?   Where is it located?

it is in drivers/block (which is why it worked only for regular file
and block devices, but network loopback does exists as well):

loop.c:

static int __init loop_init(void)
{
        int i, nr;

        if (register_blkdev(LOOP_MAJOR, "loop"))
                return -EIO;

===>lsmod |grep loop

"loop" must exists first before u can do any mounting.

For UML, the udb is implemented inside arch/um/drivers/ubd_*.c.

Probing further, how is the information flowed from
drivers/block/loop.c all the way to fs/isofs, where ISO9660 file
format recognition is implemented?

We start here:

file root_fs_val ===>
root_fs_val: Linux rev 1.0 ext2 filesystem data

So the file format is ext2 fs formatted.

Next we use "strace" (output is highly truncated for sake of clarity):

strace mount -o loop -t ext2 root_fs_val /mnt/test3====>

execve("/bin/mount", ["mount", "-o", "loop", "-t", "ext2",
"root_fs_val", "/mnt/test3"], [/* 66 vars */]) = 0
stat64("/dev/loop0", {st_mode=S_IFBLK|0640, st_rdev=makedev(7, 0), ...}) = 0
open("/dev/loop0", O_RDONLY|O_LARGEFILE) = 3
open("root_fs_val", O_RDWR|O_LARGEFILE) = 3
open("/dev/loop0", O_RDWR|O_LARGEFILE)  = 4
stat64("/sbin/mount.ext2", 0xbf8e9eb0)  = -1 ENOENT (No such file or directory)
mount("/dev/loop0", "/mnt/test3", "ext2", MS_MGC_VAL, "") = 0
read(4, "/dev/sdb1 / ext3 rw,acl,user_xat"..., 482) = 482
write(4, "/hdc2/download1/qimage/root_fs_v"..., 74) = 74

The last two lines are reading/writing the ACL attributes.

There goes losetup under the hood :-).

-- 
Regards,
Peter Teoh

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux