| OLD | NEW |
| 1 #!/bin/bash | 1 #!/bin/bash |
| 2 | 2 |
| 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 # Determine script directory | 7 # Determine script directory |
| 8 SCRIPT_DIR=$(dirname $0) | 8 SCRIPT_DIR=$(dirname $0) |
| 9 PROG=$(basename $0) | 9 PROG=$(basename $0) |
| 10 GPT=cgpt | 10 GPT=cgpt |
| 11 | 11 |
| 12 # List of Temporary files and mount points. | 12 # List of Temporary files and mount points. |
| 13 TEMP_FILE_LIST=$(mktemp) | 13 TEMP_FILE_LIST=$(mktemp) |
| 14 TEMP_DIR_LIST=$(mktemp) | 14 TEMP_DIR_LIST=$(mktemp) |
| 15 | 15 |
| 16 # Read GPT table to find the starting location of a specific partition. | 16 # Read GPT table to find the starting location of a specific partition. |
| 17 # Args: DEVICE PARTNUM | 17 # Args: DEVICE PARTNUM |
| 18 # Returns: offset (in sectors) of partition PARTNUM | 18 # Returns: offset (in sectors) of partition PARTNUM |
| 19 partoffset() { | 19 partoffset() { |
| 20 sudo $GPT show -b -i $2 $1 | 20 sudo $GPT show -b -i $2 $1 |
| 21 } | 21 } |
| 22 | 22 |
| 23 # Read GPT table to find the size of a specific partition. | 23 # Read GPT table to find the size of a specific partition. |
| 24 # Args: DEVICE PARTNUM | 24 # Args: DEVICE PARTNUM |
| 25 # Returns: size (in sectors) of partition PARTNUM | 25 # Returns: size (in sectors) of partition PARTNUM |
| 26 partsize() { | 26 partsize() { |
| 27 sudo $GPT show -s -i $2 $1 | 27 sudo $GPT show -s -i $2 $1 |
| 28 } | 28 } |
| 29 | 29 |
| 30 # Mount a partition read-only from an image into a local directory |
| 31 # Args: IMAGE PARTNUM MOUNTDIRECTORY |
| 32 mount_image_partition_ro() { |
| 33 local image=$1 |
| 34 local partnum=$2 |
| 35 local mount_dir=$3 |
| 36 local offset=$(partoffset "$image" "$partnum") |
| 37 sudo mount -o loop,ro,offset=$((offset * 512)) "$image" "$mount_dir" |
| 38 } |
| 39 |
| 30 # Mount a partition from an image into a local directory | 40 # Mount a partition from an image into a local directory |
| 31 # Args: IMAGE PARTNUM MOUNTDIRECTORY | 41 # Args: IMAGE PARTNUM MOUNTDIRECTORY |
| 32 mount_image_partition() { | 42 mount_image_partition() { |
| 33 local image=$1 | 43 local image=$1 |
| 34 local partnum=$2 | 44 local partnum=$2 |
| 35 local mount_dir=$3 | 45 local mount_dir=$3 |
| 36 local offset=$(partoffset "$image" "$partnum") | 46 local offset=$(partoffset "$image" "$partnum") |
| 37 sudo mount -o loop,offset=$((offset * 512)) "$image" "$mount_dir" | 47 sudo mount -o loop,offset=$((offset * 512)) "$image" "$mount_dir" |
| 38 } | 48 } |
| 39 | 49 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 sudo umount -d $i 2>/dev/null | 96 sudo umount -d $i 2>/dev/null |
| 87 rm -rf $i | 97 rm -rf $i |
| 88 fi | 98 fi |
| 89 done | 99 done |
| 90 set -e | 100 set -e |
| 91 rm -rf $TEMP_DIR_LIST $TEMP_FILE_LIST | 101 rm -rf $TEMP_DIR_LIST $TEMP_FILE_LIST |
| 92 } | 102 } |
| 93 | 103 |
| 94 trap "cleanup_temps_and_mounts" EXIT | 104 trap "cleanup_temps_and_mounts" EXIT |
| 95 | 105 |
| OLD | NEW |