wok-current view linux-source/stuff/rdev @ rev 13195

linux-source/rdev: fix format
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun Aug 05 09:49:35 2012 +0200 (2012-08-05)
parents 593cb33c57e1
children 4d8ac8a31cab
line source
1 #!/bin/sh
3 sw=""
4 case "$0" in
5 *rootflags) sw="-R" ;;
6 *ramsize) sw="-r" ;;
7 *vidmode) sw="-v" ;;
8 esac
9 [ -n "$sw" ] && set -- $sw "$@"
11 ofs=508
12 img=
13 val=
14 fmt="Root device 0x%04X"
15 while [ -n "$1" ]; do
16 case "$1" in
17 -R) ofs=498; fmt="Root flags %u" ;;
18 -r) ofs=504; fmt="Ramsize %u" ;;
19 -v) ofs=506; fmt="Video mode %u" ;;
20 -o) ofs=$(($2)); shift ;;
21 *-h*) echo "Usage: rdev [-Rrvh] [-o offset] [kernel [data [offset]]]"
22 exit 1 ;;
23 *) if [ -z "$img" ]; then
24 img="$1"
25 elif [ -z "$val" ]; then
26 val="$1"
27 [ "${val:0:5}" == "/dev/" ] &&
28 val=$((256*$(stat -c %t $val)+$(stat -c %T $val)))
29 else
30 ofs=$(($1))
31 fi
32 esac
33 shift
34 done
36 dd="dd bs=1 conv=notrunc count=2"
37 if [ ! -s "$img" ]; then
38 printf "0x%04X /\n" $(cat /proc/sys/kernel/real-root-dev)
39 elif [ -n "$val" ]; then
40 for i in 1 2; do
41 printf '\\\\x%02X' $(($val & 255))
42 val=$(($val >> 8))
43 done | xargs echo -en | $dd of=$img seek=$ofs
44 else
45 $dd if=$img skip=$ofs | hexdump -e "\"\" 1/2 \"$fmt\" \"\n\""
46 fi 2>/dev/null