From: Stefan Bund Date: Sat, 7 Nov 2009 09:05:22 +0000 (+0100) Subject: Fix/finish modularization X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=a289841fd09d35ec7d9db3a740170500212e0f36;p=mapsector.git Fix/finish modularization --- diff --git a/debian/changelog b/debian/changelog index d9607b9..3c4fc18 100644 --- a/debian/changelog +++ b/debian/changelog @@ -6,8 +6,9 @@ mapsector (0.0.1~1.gbpc67543) UNRELEASED; urgency=low * [63c6e663] Add version variable * [9b845b7a] Add --version/-V command line option * [c6754307] add updateversion.sh script + * [cd564bd2] debianize - -- Stefan Bund Fri, 06 Nov 2009 14:38:29 +0100 + -- Stefan Bund Fri, 06 Nov 2009 15:04:36 +0100 mapsector (0.0.0) unstable; urgency=low diff --git a/lib/10_map_raid.sh b/lib/10_map_raid.sh index 7c1b462..919817c 100644 --- a/lib/10_map_raid.sh +++ b/lib/10_map_raid.sh @@ -8,11 +8,13 @@ describe_raid() echo " RAID level 1" } -map_raid() +do_raid() { local mddevice local mdlevel + echo "# $device: RAID detected" 1>&2 + mddevice="`mdadm -Q $device | sed -ne 's/.*\(raid[0-9] \/dev\/[^.]*\).*/\1/' -eT -ep`" if [ -z "$mddevice" ]; then @@ -28,6 +30,8 @@ map_raid() echo "sector $sector" device="$mddevice" + + return 1 } register_mapper "raid" diff --git a/lib/10_scan_mountpoint.sh b/lib/10_scan_mountpoint.sh index e020fb9..fc6a549 100644 --- a/lib/10_scan_mountpoint.sh +++ b/lib/10_scan_mountpoint.sh @@ -24,6 +24,8 @@ do_mountpoint() ;; esac done < /proc/mounts + + return 1 } register_scanner "mountpoint" diff --git a/lib/50_map_crtypt.sh b/lib/50_map_crtypt.sh index 4ec0ec0..927633b 100644 --- a/lib/50_map_crtypt.sh +++ b/lib/50_map_crtypt.sh @@ -8,7 +8,7 @@ describe_crypt() echo " cryptsetup (luks and dmcrypt)" } -map_crypt() +do_crypt() { # Step 2: Find the crypted volume defined for this partition @@ -18,6 +18,8 @@ map_crypt() local cryptsector local type + echo "# $device: cryptsetup detected" 1>&2 + offset="`cryptsetup luksDump $device 2>/dev/null | awk '/^Payload offset/{print $3}'`" if [ -z "$offset" ]; then @@ -44,6 +46,8 @@ map_crypt() device="$cryptdev" sector="$cryptsector" + + return 1 } register_mapper "crypt" diff --git a/lib/50_map_lvm.sh b/lib/50_map_lvm.sh index 51fbffc..8bd5b02 100644 --- a/lib/50_map_lvm.sh +++ b/lib/50_map_lvm.sh @@ -8,7 +8,7 @@ describe_lvm() echo " LVM (linear allocation scheme)" } -map_lvm() +do_lvm() { local pvname local pesize @@ -21,6 +21,8 @@ map_lvm() local lenum local fsdev local fssector + + echo "# $device: LVM detected" 1>&2 # Step 3: Get pysical extent number @@ -81,6 +83,8 @@ map_lvm() device="$fsdev" sector="$fssector" + + return 1 } register_mapper "lvm" diff --git a/lib/50_map_partition.sh b/lib/50_map_partition.sh index 1e16873..c3d5886 100644 --- a/lib/50_map_partition.sh +++ b/lib/50_map_partition.sh @@ -8,7 +8,7 @@ describe_partition() echo " partition tables" } -map_partition() +do_partition() { # Step 1: Find partition to which this sector belongs @@ -16,6 +16,8 @@ map_partition() local partstart local partsector + echo "# $device: partition table detected" 1>&2 + partdev="`fdisk -ul $device | awk -v sector="$sector" -F '[ *]+' '/^\// && !/Extended$/ && $2<=sector && $3>=sector {print $1,$2}'`" #`" if [ -z "$partdev" ]; then @@ -33,6 +35,8 @@ map_partition() device="$partdev" sector="$partsector" + + return 1 } register_mapper "partition" diff --git a/lib/50_scan_extfs.sh b/lib/50_scan_extfs.sh index cccf7f7..f2004f1 100644 --- a/lib/50_scan_extfs.sh +++ b/lib/50_scan_extfs.sh @@ -8,7 +8,7 @@ describe_extfs() echo " ext2-4" } -scan_extfs() +do_extfs() { local fsblocksize local fsblock @@ -16,6 +16,8 @@ scan_extfs() local fstype local inode + echo "$device: ext2-4 filesystem detected" 1>&2 + fstype="`file -s $device | sed -e 's/.*\(ext[0-9]\).*/\1/'`" echo "fstype $fstype" @@ -75,6 +77,8 @@ scan_extfs() echo "blocktype journal?" fi ) 3>&1 + + return 0 } register_scanner "extfs" diff --git a/lib/50_scan_reiserfs.sh b/lib/50_scan_reiserfs.sh index 6d44cf3..9c91d31 100644 --- a/lib/50_scan_reiserfs.sh +++ b/lib/50_scan_reiserfs.sh @@ -8,11 +8,13 @@ describe_reiserfs() echo " reiserfs" } -scan_reiserfs() +do_reiserfs() { local blocksize local block local subsector + + echo "# $device: reiserfs filesystem detected" 1>&2 echo "fstype reiserfs" @@ -169,6 +171,7 @@ for path in scan_path(blockid): sys.stdout.write("name %s\n" % path) EOF + return 0 } register_scanner "reiserfs" diff --git a/mapsector b/mapsector index 353c6de..9eb97c6 100755 --- a/mapsector +++ b/mapsector @@ -25,13 +25,13 @@ load() # Map device/sector through blockdevice mappings (e.g. lvm) -run() +map() { local found - foundm=1 + found=1 while [ -n "$found" ]; do found="" - for name in "$@"; do + for name in $mappers; do if detect_$name; then found=1 if do_$name; then @@ -43,6 +43,17 @@ run() done } +scan() +{ + for name in $scanners; do + if detect_$name; then + if do_$name; then + return + fi + fi + done +} + ########################################################################### unset LANG @@ -134,7 +145,7 @@ sector="$2" echo "device $device" echo "sector $sector" -run $mappers +map if [ -z "$noscan" ]; then - run $scanners + scan fi