-
Notifications
You must be signed in to change notification settings - Fork 0
/
sector-write
58 lines (51 loc) · 991 Bytes
/
sector-write
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
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
dev=
offset=0
in=
darg () {
if [ -z "$dev" ]; then dev="$1"; else out="$1"; fi
}
usage()
{
echo "Usage: $0 [DEVICE] [SECTOR] INFILE"
echo " DEVICE has the form \"osprd*\" and defaults to \"osprda\""
echo " SECTOR is the sector number and defaults to 0"
echo " INFILE is the file to copy to the device"
exit 1
}
while [ $# -ne 0 ]
do
arg=$1
shift
case "$arg" in
-h | --help)
usage
;;
osprd[abcd])
darg "/dev/$arg"
;;
/dev/*)
darg "$arg"
;;
[0-9]*)
offset="$arg"
;;
*)
in="$arg"
;;
esac
done
if [ -z "$in" -a -t 0 ]; then
echo "sector_write: Refusing to read from terminal! Supply a filename or '-'." 1>&2
exit 1
fi
[ -z "$dev" ] && dev=/dev/osprda
ifarg="if=$in"; [ "$in" = '-' -o "$in" = '/dev/stdin' -o -z "$in" ] && ifarg=
ofarg="of=$dev"; [ "$dev" = '-' -o "$dev" = '/dev/stdout' ] && ofarg=
if [ -z "$in" ]
then
echo "Error: Must provide input file"
usage
else
dd $ifarg $ofarg bs=512 count=1 seek=$offset
fi