wok-current annotate linux-source/stuff/rdev @ rev 13352
Add perl-io-tty, perl-io-stty, perl-number-range, perl-expect, perl-algorithm-permute
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Mon Sep 10 09:49:31 2012 +0200 (2012-09-10) |
parents | 4d8ac8a31cab |
children | 8144275286f2 |
rev | line source |
---|---|
pascal@13194 | 1 #!/bin/sh |
pascal@13194 | 2 |
pascal@13214 | 3 dev() |
pascal@13211 | 4 { |
pascal@13214 | 5 for b in $(find /dev -type b); do |
pascal@13214 | 6 [ $(stat -c %02t%02T $b) = $1 ] && echo $b && return |
pascal@13214 | 7 done |
pascal@13214 | 8 echo 0x$1 |
pascal@13211 | 9 } |
pascal@13211 | 10 |
pascal@13214 | 11 s= |
pascal@13195 | 12 case "$0" in |
pascal@13214 | 13 *gs) s=-R;; |
pascal@13214 | 14 *ze) s=-r;; |
pascal@13214 | 15 *de) s=-v |
pascal@13194 | 16 esac |
pascal@13214 | 17 set -- $s "$@" |
pascal@13194 | 18 |
pascal@13214 | 19 o=508 |
pascal@13214 | 20 i= |
pascal@13214 | 21 v= |
pascal@13214 | 22 f= |
pascal@13194 | 23 while [ -n "$1" ]; do |
pascal@13214 | 24 case "$1" in |
pascal@13214 | 25 -R) o=498; f="Root flags";; |
pascal@13214 | 26 -r) o=504; f="Ramsize";; |
pascal@13214 | 27 -v) o=506; f="Video mode";; |
pascal@13214 | 28 -o) o=$(($2)); f=" "; shift;; |
pascal@13214 | 29 -*) echo "Usage: rdev [-Rrvh] [-o offset] [kernel [data [offset]]]" |
pascal@13214 | 30 exit 1;; |
pascal@13214 | 31 *) if [ -z "$i" ]; then |
pascal@13214 | 32 i="$1" |
pascal@13214 | 33 elif [ -z "$v" ]; then |
pascal@13214 | 34 [ -b "$1" ] && v=0x$(stat -c %t%02T $1) |
pascal@13214 | 35 v=$((${v:-$1})) |
pascal@13214 | 36 else |
pascal@13214 | 37 o=$(($1)) |
pascal@13214 | 38 fi |
pascal@13214 | 39 esac |
pascal@13214 | 40 shift |
pascal@13194 | 41 done |
pascal@13194 | 42 |
pascal@13195 | 43 dd="dd bs=1 conv=notrunc count=2" |
pascal@13214 | 44 if [ ! -s "$i" ]; then |
pascal@13214 | 45 echo $(dev $(stat -c %04D /)) / |
pascal@13214 | 46 elif [ -n "$v" ]; then |
pascal@13194 | 47 for i in 1 2; do |
pascal@13214 | 48 printf '\\\\x%02X' $(($v&255)) |
pascal@13214 | 49 v=$(($v>>8)) |
pascal@13214 | 50 done | xargs echo -en | $dd of=$i seek=$o |
pascal@13214 | 51 elif [ -n "$f" ]; then |
pascal@13214 | 52 echo $f $($dd if=$i skip=$o | od -dAn) |
pascal@13194 | 53 else |
pascal@13214 | 54 echo "Root device $(dev $($dd if=$i skip=$o | od -xAn))" |
pascal@13195 | 55 fi 2>/dev/null |