modularize
[mapsector.git] / lib / 50_map_partition.sh
1 detect_partition()
2 {
3     [ -z "`fdisk -l $device 2>&1 >/dev/null`" ]
4 }
5
6 describe_partition()
7 {
8     echo "    partition tables"
9 }
10
11 map_partition()
12 {
13     # Step 1: Find partition to which this sector belongs
14
15     local partdev
16     local partstart
17     local partsector
18
19     partdev="`fdisk -ul $device | awk -v sector="$sector" -F '[ *]+' '/^\// && !/Extended$/ && $2<=sector && $3>=sector {print $1,$2}'`" #`"
20
21     if [ -z "$partdev" ]; then
22         echo "# sector $sector is not part of any partition on $device" 1>&2
23         exit 0
24     fi
25
26     partstart="${partdev#* }"
27     partdev="${partdev% *}"
28     partsector="`dc -e "$sector $partstart - p"`" # `"
29
30     echo "offset $partstart"
31     echo "device $partdev partition"
32     echo "sector $partsector"
33
34     device="$partdev"
35     sector="$partsector"
36 }
37
38 register_mapper "partition"