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

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