-
Notifications
You must be signed in to change notification settings - Fork 0
/
sector-read
47 lines (42 loc) · 884 Bytes
/
sector-read
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash
dev=
offset=0
out=
darg () {
if [ -z "$dev" ]; then dev="$1"; else out="$1"; fi
}
while [ $# -ne 0 ]
do
arg=$1
shift
case "$arg" in
-h | --help)
echo "Usage: $0 [DEVICE] [SECTOR] [OUTFILE]"
echo " DEVICE has the form \"osprd*\" and defaults to \"osprda\""
echo " SECTOR is the sector number and defaults to 0"
echo " OUTFILE is the output file or \"-\" for stdout and defaults to \"-\""
exit 1
;;
osprd[abcd])
darg "/dev/$arg"
;;
/dev/*|-)
darg "$arg"
;;
[0-9]*)
offset="$arg"
;;
*)
out="$arg"
;;
esac
done
[ -z "$dev" ] && dev=/dev/osprda
ifarg="if=$dev"; [ "$dev" = '-' -o "$dev" = '/dev/stdin' ] && ifarg=
ofarg="of=$out"; [ "$out" = '-' -o "$out" = '/dev/stdout' ] && ofarg=
if [ -z "$out" ]
then
dd $ifarg bs=512 count=1 skip=$offset | hexdump -C
else
dd $ifarg $ofarg bs=512 count=1 skip=$offset
fi