3 # mapsector -- Map sector number to file name(s)
5 # Copyright (C) 2009,2010 Stefan Bund <stefan@j32.de>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the
19 # Free Software Foundation, Inc.,
20 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 ###########################################################################
28 name="`basename "$0"`"
30 # Don't use custom language since we parse the output of lots of standard
36 mappers="${mappers}${mappers:+ }$1"
41 scanners="${scanners}${scanners:+ }$1"
50 if [ "`basename "$X"`" == "bin" ]; then # `"
51 libdir="`dirname "$X"`/share/$name" #`"
53 if [ -z "$libdir" -o ! -d "$libdir" ]; then
57 if [ ! -d "$libdir" ]; then
58 echo "! Library directory not found" 1>&2
62 for lib in `ls "$libdir"/[0-9][0-9]_*.sh | sort`; do
67 # Map device/sector through blockdevice mappings (e.g. lvm)
73 while [ -n "$found" ]; do
75 for name in $mappers; do
89 for name in $scanners; do
98 ###########################################################################
100 #### Load library modules
104 #### Parse command line arguments
106 X=`getopt -o "hV" --long "help,noscan,version" -n "$name" -- "$@"`
107 if [ $? != 0 ]; then exit 1; fi
115 -h|--help) help="0"; shift ;;
116 --noscan) noscan="0"; shift ;;
117 -V|--version) echo "$name $version"; exit 0 ;;
119 *) echo "! internal error"; exit 1 ;;
123 if [ -n "$help" -o -z "$2" ]; then
125 Usage: $name [-h|--help] [--noscan] <device> <sector>"
127 mapsector -- Map sector number to file name(s)
129 Given a device and a sector number, mapsector will try to find the
130 file name(s) mapping to this sector. It will try to gather as much
131 information about the given sector as possible.
133 mapsector currently has support for the following mapping schemes:
136 for mapper in $mappers; do
141 mapsector currently supports the following filesystems
144 for scanner in $scanners; do
149 mapsector will try it's best to find an associated file name but
150 depending on the filesystem state and the type of sector (e.g. if
151 the sector is part of a filesystem metadata block) this may not be
154 For mapsector to work, the filesystem must be currently active
155 (e.g. LVM must be running, crypted devices must have been set up). The
156 filesystem must not necessarily be mounted (though if mounted,
157 mapsector will give you the mountpoint).
159 if '--noscan' is given, the possibly lengthy (!!) filesystem scan for
160 filenames is skipped.
162 -- mapsector $version
170 echo "device $device"
171 echo "sector $sector"
174 if [ -z "$noscan" ]; then