#!/bin/sh # Mount partitions within a disk image file # License: LGPLv2 # Author: P@adraigBrady.com # V1.0 29 Jun 2005 Initial release # V1.1 01 Dec 2005 Handle bootable (DOS) parititons # v1.2 25 Jan 2013 Glen Gray: Handle GPT partitions if test "$Argc" -ne "3" { echo "Usage: $[basename $0] " > !2 exit 1 } global FILE := $1 global PART := $2 global DEST := $3 if parted --version >/dev/null !2 > !1 { # Prefer as supports GPT partitions global UNITS := $[parted -s $FILE unit s print !2 >/dev/null | grep " $PART " | tr -d 's' | awk '{print $2}] } elif fdisk -v >/dev/null !2 > !1 { global UNITS := $[fdisk -lu $FILE !2 >/dev/null | grep "$FILE$PART " | tr -d '*' | awk '{print $2}] } else { echo "Can't find the fdisk or parted utils. Are you root?" > !2 exit 1 } global OFFSET := $[expr 512 '*' $UNITS] mount -o loop,offset=$OFFSET $FILE $DEST (CommandList children: [ (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(DQ ($ VSub_Pound "$#"))} {(-ne)} {(DQ (3))} {(Lit_Other "]")}) terminator: ) ] action: [ (SimpleCommand words: [ {(echo)} { (DQ ("Usage: ") (CommandSubPart command_list: (CommandList children:[(C {(basename)} {($ VSub_Number "$0")})]) left_token: spids: [49 53] ) (" ") ) } ] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[57])] ) (C {(exit)} {(1)}) ] spids: [-1 42] ) ] spids: [-1 65] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:FILE) op:Equal rhs:{($ VSub_Number "$1")} spids:[68])] spids: [68] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:PART) op:Equal rhs:{($ VSub_Number "$2")} spids:[71])] spids: [71] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:DEST) op:Equal rhs:{($ VSub_Number "$3")} spids:[74])] spids: [74] ) (If arms: [ (if_arm cond: [ (Sentence child: (SimpleCommand words: [{(parted)} {(--version)}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(/dev/null)} spids: [84] ) (Redir op_id:Redir_GreatAnd fd:2 arg_word:{(1)} spids:[87]) ] ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:UNITS) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (SimpleCommand words: [ {(parted)} {(-s)} {($ VSub_Name "$FILE")} {(unit)} {(s)} {(print)} ] redirects: [ (Redir op_id: Redir_Great fd: 2 arg_word: {(/dev/null)} spids: [111] ) ] ) (C {(grep)} {(DQ (" ") ($ VSub_Name "$PART") (" "))}) (C {(tr)} {(-d)} {(SQ )}) (C {(awk)} {(SQ <"{print $2}">)}) ] negated: False ) ] ) left_token: spids: [98 142] ) } spids: [97] ) ] spids: [97] ) ] spids: [-1 91] ) (if_arm cond: [ (Sentence child: (SimpleCommand words: [{(fdisk)} {(-v)}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(/dev/null)} spids: [150] ) (Redir op_id:Redir_GreatAnd fd:2 arg_word:{(1)} spids:[153]) ] ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:UNITS) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (SimpleCommand words: [{(fdisk)} {(-lu)} {($ VSub_Name "$FILE")}] redirects: [ (Redir op_id: Redir_Great fd: 2 arg_word: {(/dev/null)} spids: [168] ) ] ) (C {(grep)} {(DQ ($ VSub_Name "$FILE") ($ VSub_Name "$PART") (" "))}) (C {(tr)} {(-d)} {(SQ <"*">)}) (C {(awk)} {(SQ <"{print $2}">)}) ] negated: False ) ] ) left_token: spids: [161 199] ) } spids: [160] ) ] spids: [160] ) ] spids: [144 157] ) ] else_action: [ (SimpleCommand words: [{(echo)} {(DQ ("Can't find the fdisk or parted utils. Are you root?"))}] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[210])] ) (C {(exit)} {(1)}) ] spids: [201 218] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:OFFSET) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [(C {(expr)} {(512)} {(SQ <"*">)} {($ VSub_Name "$UNITS")})] ) left_token: spids: [222 232] ) } spids: [221] ) ] spids: [221] ) (C {(mount)} {(-o)} {(loop) (Lit_Comma ",") (Lit_VarLike "offset=") ($ VSub_Name "$OFFSET")} {($ VSub_Name "$FILE")} {($ VSub_Name "$DEST")} ) ] )