wok-next annotate linux-source/stuff/rdev @ rev 13211
linux-source/rdev: use device name
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Tue Aug 07 17:35:57 2012 +0200 (2012-08-07) |
parents | f5438bbbdb73 |
children | e36062a9b169 |
rev | line source |
---|---|
pascal@13194 | 1 #!/bin/sh |
pascal@13194 | 2 |
pascal@13211 | 3 devname() |
pascal@13211 | 4 { |
pascal@13211 | 5 d=$(find /dev -type b | while read b ; do |
pascal@13211 | 6 [ "$(stat -c %02t%02T $b)" == "$1" ] && echo $b && break |
pascal@13211 | 7 done) |
pascal@13211 | 8 [ -n "$d" ] && echo $d || echo 0x$1 |
pascal@13211 | 9 } |
pascal@13211 | 10 |
pascal@13194 | 11 sw="" |
pascal@13195 | 12 case "$0" in |
pascal@13195 | 13 *rootflags) sw="-R" ;; |
pascal@13195 | 14 *ramsize) sw="-r" ;; |
pascal@13195 | 15 *vidmode) sw="-v" ;; |
pascal@13194 | 16 esac |
pascal@13194 | 17 [ -n "$sw" ] && set -- $sw "$@" |
pascal@13194 | 18 |
pascal@13195 | 19 ofs=508 |
pascal@13195 | 20 img= |
pascal@13195 | 21 val= |
pascal@13211 | 22 fmt= |
pascal@13194 | 23 while [ -n "$1" ]; do |
pascal@13194 | 24 case "$1" in |
pascal@13211 | 25 -R) ofs=498; fmt="Root flags" ;; |
pascal@13211 | 26 -r) ofs=504; fmt="Ramsize" ;; |
pascal@13211 | 27 -v) ofs=506; fmt="Video mode" ;; |
pascal@13195 | 28 -o) ofs=$(($2)); shift ;; |
pascal@13195 | 29 *-h*) echo "Usage: rdev [-Rrvh] [-o offset] [kernel [data [offset]]]" |
pascal@13195 | 30 exit 1 ;; |
pascal@13195 | 31 *) if [ -z "$img" ]; then |
pascal@13195 | 32 img="$1" |
pascal@13195 | 33 elif [ -z "$val" ]; then |
pascal@13211 | 34 [ "${1:0:5}" == "/dev/" ] && val=0x$(stat -c %t%02T $1) |
pascal@13211 | 35 val=$((${val:-$1})) |
pascal@13194 | 36 else |
pascal@13195 | 37 ofs=$(($1)) |
pascal@13194 | 38 fi |
pascal@13194 | 39 esac |
pascal@13194 | 40 shift |
pascal@13194 | 41 done |
pascal@13194 | 42 |
pascal@13195 | 43 dd="dd bs=1 conv=notrunc count=2" |
pascal@13195 | 44 if [ ! -s "$img" ]; then |
pascal@13211 | 45 echo $(devname $(stat -c %04D /)) / |
pascal@13195 | 46 elif [ -n "$val" ]; then |
pascal@13194 | 47 for i in 1 2; do |
pascal@13195 | 48 printf '\\\\x%02X' $(($val & 255)) |
pascal@13195 | 49 val=$(($val >> 8)) |
pascal@13195 | 50 done | xargs echo -en | $dd of=$img seek=$ofs |
pascal@13211 | 51 elif [ -n "$fmt" ]; then |
pascal@13211 | 52 $dd if=$img skip=$ofs | hexdump -e "\"\" 1/2 \"$fmt %u\" \"\n\"" |
pascal@13194 | 53 else |
pascal@13211 | 54 echo -n "Root device " |
pascal@13211 | 55 devname $($dd if=$img skip=$ofs | hexdump -e '"" 1/2 "%04X" "\n"') |
pascal@13195 | 56 fi 2>/dev/null |