wok 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 518a64ad039f
children 5c15aaeb6c78
files linux-source/stuff/rdev
line diff
     1.1 --- a/linux-source/stuff/rdev	Tue Aug 07 13:38:47 2012 +0200
     1.2 +++ b/linux-source/stuff/rdev	Tue Aug 07 17:35:57 2012 +0200
     1.3 @@ -1,5 +1,13 @@
     1.4  #!/bin/sh
     1.5  
     1.6 +devname()
     1.7 +{
     1.8 +	d=$(find /dev -type b | while read b ; do
     1.9 +		[ "$(stat -c %02t%02T $b)" == "$1" ] && echo $b && break
    1.10 +	done)
    1.11 +	[ -n "$d" ] && echo $d || echo 0x$1
    1.12 +}
    1.13 +
    1.14  sw=""
    1.15  case "$0" in
    1.16  *rootflags)	sw="-R" ;;
    1.17 @@ -11,21 +19,20 @@
    1.18  ofs=508
    1.19  img=
    1.20  val=
    1.21 -fmt="Root device 0x%04X"
    1.22 +fmt=
    1.23  while [ -n "$1" ]; do
    1.24  	case "$1" in	
    1.25 -	-R)	ofs=498; fmt="Root flags %u" ;;
    1.26 -	-r)	ofs=504; fmt="Ramsize %u" ;;
    1.27 -	-v)	ofs=506; fmt="Video mode %u" ;;
    1.28 +	-R)	ofs=498; fmt="Root flags" ;;
    1.29 +	-r)	ofs=504; fmt="Ramsize" ;;
    1.30 +	-v)	ofs=506; fmt="Video mode" ;;
    1.31  	-o)	ofs=$(($2)); shift ;;
    1.32  	*-h*)	echo "Usage: rdev [-Rrvh] [-o offset] [kernel [data [offset]]]"
    1.33  		exit 1 ;;
    1.34  	*)	if [ -z "$img" ]; then
    1.35  			img="$1"
    1.36  		elif [ -z "$val" ]; then
    1.37 -			val="$1"
    1.38 -			[ "${val:0:5}" == "/dev/" ] &&
    1.39 -			val=$((256*$(stat -c %t $val)+$(stat -c %T $val)))
    1.40 +			[ "${1:0:5}" == "/dev/" ] && val=0x$(stat -c %t%02T $1)
    1.41 +			val=$((${val:-$1}))
    1.42  		else
    1.43  			ofs=$(($1))
    1.44  		fi
    1.45 @@ -35,12 +42,15 @@
    1.46  
    1.47  dd="dd bs=1 conv=notrunc count=2"
    1.48  if [ ! -s "$img" ]; then
    1.49 -	printf "0x%04X /\n" $(cat /proc/sys/kernel/real-root-dev)
    1.50 +	echo $(devname $(stat -c %04D /)) /
    1.51  elif [ -n "$val" ]; then
    1.52  	for i in 1 2; do
    1.53  		printf '\\\\x%02X' $(($val & 255))
    1.54  		val=$(($val >> 8))
    1.55  	done | xargs echo -en | $dd of=$img seek=$ofs
    1.56 +elif [ -n "$fmt" ]; then
    1.57 +	$dd if=$img skip=$ofs | hexdump -e "\"\" 1/2 \"$fmt %u\" \"\n\""
    1.58  else
    1.59 -	$dd if=$img skip=$ofs | hexdump -e "\"\" 1/2 \"$fmt\" \"\n\""
    1.60 +	echo -n "Root device "
    1.61 +	devname $($dd if=$img skip=$ofs | hexdump -e '"" 1/2 "%04X" "\n"')
    1.62  fi 2>/dev/null