]> git.pld-linux.org Git - packages/VirtualBox.git/blobdiff - mount.vdi
install VBoxClient-all, drop xinitrc.d, assume modern desktop for autostart stuff
[packages/VirtualBox.git] / mount.vdi
old mode 100644 (file)
new mode 100755 (executable)
index 3803190..69fb458
--- a/mount.vdi
+++ b/mount.vdi
@@ -27,7 +27,7 @@ export PATH=/bin:/sbin:/usr/bin:/usr/sbin
 # Commands
 LOSETUP=/sbin/losetup
 MOUNT=/bin/mount
-SFDISK=/sbin/sfdisk
+PARTED=/usr/sbin/parted
 SED=/bin/sed
 
 PROGRAM=${0##*/}
@@ -95,10 +95,17 @@ fi
 
 # check magic
 magic=$(head -n 1 "$DEVICE")
-if [ "$magic" != "<<< innotek VirtualBox Disk Image >>>" ]; then
+case "$magic" in
+"<<< innotek VirtualBox Disk Image >>>")
+       ;;
+"<<< Sun VirtualBox Disk Image >>>")
+       ;;
+"<<< Oracle VM VirtualBox Disk Image >>>")
+       ;;
+*)
        echo >&2 "$PROGRAM: $DEVICE: bad magic, not VDI image"
        exit 1
-fi
+esac
 
 MOUNTOPTIONS=
 PARTITION=
@@ -106,8 +113,8 @@ OFFSET=
 OLDIFS=$IFS
 IFS=", "
 for opt in $OPTIONS; do
-    KEY=${opt%=*};
-    VAL=${opt#*=};
+       KEY=${opt%=*};
+       VAL=${opt#*=};
        case "$KEY" in
        part|partition)
                PARTITION="$VAL"
@@ -135,33 +142,15 @@ fi
 dskoff=8704
 
 # find free loop device. XXX race possible
-imgdev=$($LOSETUP -f)
+imgdev=$($LOSETUP -f) || exit 1
 $LOSETUP $imgdev -o $dskoff "$DEVICE"
-# http://vserver.13thfloor.at/Stuff/QEMU/hdloop.sh
-sfd=$($SFDISK -dump $imgdev 2>/dev/null | $SED -n '
-       /:/ s/[a-zA-Z]*=\ *\([0-9a-f]*\)\(,\|$\)/\1/g;
-       T;  s/^.*:\ //; p' | tr ' ' '.')
-$LOSETUP -d $imgdev
-
-getoffset() {
-       pstart=$1
-       psize=$2
-
-       blksize=512
-       offset=$((pstart*blksize))
-       size=$((psize*blksize))
-       echo $((offset+dskoff))
-}
-
-p=1
-for a in $sfd; do
-       if [ "$p" = "$PARTITION" ]; then
-               OFFSET=$(getoffset $(echo "$a" | tr '.' ' '))
-       fi
-       x=$((p++))
-done
+dump=$($PARTED -s -m $imgdev unit B print)
+$LOSETUP -d $imgdev || exit 1
+
+partoff=$(echo "$dump" | $SED -ne "s/^$PARTITION:"'\([0-9]*\)B:.*/\1/p')
+OFFSET=$((dskoff + partoff))
 
-if [ -z "$OFFSET" ]; then
+if [ -z "$partoff" -o -z "$OFFSET" ]; then
        echo >&2 "$PROGRAM: couldn't figure out offset, perhaps out of range?"
        exit 1
 fi
@@ -175,5 +164,5 @@ fi
 # $MOUNTPOINT might not exist as mount can try to read it from /etc/fstab
 $MOUNT $MOUNTARGS ${FSTYPE:+-t "$FSTYPE"} ${MOUNTOPTIONS:+-o "$MOUNTOPTIONS"} "$DEVICE" "$MOUNTPOINT"
 if [ $? -ne 0 ]; then
-    echo >&2 "$PROGRAM: error mounting $DEVICE"
+       echo >&2 "$PROGRAM: error mounting $DEVICE"
 fi
This page took 0.061946 seconds and 4 git commands to generate.