X-Git-Url: http://git.pld-linux.org/?a=blobdiff_plain;f=mount.vdi;h=69fb458c1f9f8762f50ed852d006fd312d247240;hb=57852ec15ea547287562db638cf8e02f36eebe71;hp=380319011d7ef7469b7645a28cc62716b5aa90d3;hpb=e1ca00508b181d4bd9dba63d7d1df0780e82cc46;p=packages%2FVirtualBox.git diff --git a/mount.vdi b/mount.vdi old mode 100644 new mode 100755 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