Use losetup rather than -o loop
authorGuido Trotter <ultrotter@google.com>
Mon, 26 Jan 2009 12:19:31 +0000 (12:19 +0000)
committerGuido Trotter <ultrotter@google.com>
Mon, 26 Jan 2009 12:19:31 +0000 (12:19 +0000)
If the device we're given is actually a file, rather than just mounting
it with the -o loop option, we'll explicitely losetup it to a device,
and losetup -d (detach) it at the end. This allows us to do more actions
on the target device (for example partition it, if needed).

Reviewed-by: iustinp

create.in

index 7840789..cbe3ae4 100755 (executable)
--- a/create.in
+++ b/create.in
@@ -62,6 +62,14 @@ CACHE_FILE="$CACHE_DIR/cache-${SUITE}-${DPKG_ARCH}.tar"
 
 . common.sh
 
+# If the target device is not a real block device we'll first losetup it.
+# This is needed for file disks.
+if [ ! -b $blockdev ]; then
+  ORIGINAL_BLOCKDEV=$blockdev
+  blockdev=$(losetup -sf $blockdev)
+  CLEANUP+=("losetup -d $blockdev")
+fi
+
 mke2fs -Fjq $blockdev
 root_uuid=$($VOL_ID -u $blockdev )
 if [ -n "$swapdev" ]; then
@@ -72,13 +80,7 @@ fi
 TMPDIR=`mktemp -d` || exit 1
 CLEANUP+=("rmdir $TMPDIR")
 
-# If it's not a block device try to mount it via loopback device.
-# This is needed for file disks.
-MOUNT_OPTIONS=""
-if [ ! -b $blockdev ]; then
-  MOUNT_OPTIONS="$MOUNT_OPTIONS -o loop"
-fi
-mount $MOUNT_OPTIONS $blockdev $TMPDIR
+mount $blockdev $TMPDIR
 CLEANUP+=("umount $TMPDIR")
 
 # remove the cache file if it's old (> 2 weeks) and writable by the owner (the