On Sun, Jun 10, 2007 at 11:59:26AM -0700, H. Peter Anvin wrote: > losetup provides an -f option to discover an unused loop device. As > implemented, it is racy. > > The problem is that -f prints the loop device to stdout only when used > standalone. This means a script has to do: > > lodev=`losetup -f` > losetup $lodev $filename > > ... which is racy if another script may be running. The syntax: Yes, this method is useless. > > lodev=`losetup -f $filename` > > ... doesn't work, because although it will set up the loop device for > you (and it better do it atomically!), it never prints out the selected > loop device for the script to use. I use in util-linux-ng regression tests something like: losetup -f "$IMAGE" DEV=$( losetup -a | gawk 'BEGIN {FS=":"} /'$IMAGE'/ { print $1 }' ) (Note, old versions don't support the '-a' option. The '-a' means list all used loop devices.) We can print out the selected loop device name, but this change is not backwardly compatible (it means scripts without "> /dev/null" will be print the name of device to stdout, or log file, ...). The other possibility is add a new option ('-p' when you need a device name): $lodev=`losetup -f -p filename.img` Comments? Karel -- Karel Zak <kzak@xxxxxxxxxx> - To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html