[BusyBox] losetup+mount can only do ro mounts. util-linux ones work :(

Denis Vlasenko vda at port.imtp.ilyichevsk.odessa.ua
Fri Jul 25 08:57:41 UTC 2003


> With busybox, i can successfully do:
> 
> mount -t vfat /dev/somedev /new_root
> modprobe loop
> losetup /dev/loop/0 /new_root/diskimg
> mount /dev/loop/0 /new_root2
> 
> This last mount gives me -EPERM.
> I substituted util-linux's mount and it says
> "/dev/loop/0 is ro, mounting readonly" - ??!
> After that I also subst'ed lostup with util-linux
> one - and it works rw now. Bug in busybox?

Stracing both losetup's hangs but I see the reason:

util-linux:
execve("/sbin/losetup", ["losetup", "/dev/loop/0", "image"], [/* 25 vars */]) = 0
...
open("image", O_RDWR|O_LARGEFILE)       = 6
open("/dev/loop/0", O_RDWR|O_LARGEFILE) = 7
mlockall(MCL_CURRENT|MCL_FUTURE)        = 0
ioctl(7, 0x4c00 <hangs forever>

bb:
execve("./busybox", ["./busybox", "losetup", "/dev/loop/0", "image"], [/* 25 vars */]) = 0
...
open("image", O_RDONLY|O_LARGEFILE)     = 6
open("/dev/loop/0", O_RDONLY|O_LARGEFILE) = 7
ioctl(7, 0x4c00 <hangs forever>

Hehe, O_RDONLY!

util-linux/losetup.c:
int
losetup_main (int argc, char **argv)
...
  while ((opt = getopt (argc, argv, "do:")) != -1)
    switch (opt)
      {...}
  if (delete)
    return del_loop (argv[optind]) ? EXIT_SUCCESS : EXIT_FAILURE;
  else
    return set_loop (argv[optind], argv[optind + 1], offset, &opt) ? EXIT_FAILURE : EXIT_SUCCESS;
                                                             ^^^^
So, opt = -1 here due to while(). Always.

libbb/loop.c:
extern int set_loop(const char *device, const char *file, int offset,
                                        int *loopro)
{
        struct loop_info loopinfo;
        int fd, ffd, mode;

        mode = *loopro ? O_RDONLY : O_RDWR;

And we use O_RDONLY. Always.

So, set_loop() in losetup.c seems to have bogus 4th argument.

P.S.
util-linux/mount.c:
                status = mount(specialfile, dir, filesystemtype, flags, string_flags);
                if (status < 0 && errno == EROFS) {
                        bb_error_msg("%s is write-protected, mounting read-only",
                                          specialfile);

does not work for me too, I get EPERM and not EROFS on mounting
ro blockdevices, which makes sense (blockdevice != fs)
--
vda



More information about the busybox mailing list