wok 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 75c0995b510f
files linux-source/stuff/rdev
line diff
     1.1 --- a/linux-source/stuff/rdev	Sun Aug 05 00:27:09 2012 +0200
     1.2 +++ b/linux-source/stuff/rdev	Sun Aug 05 09:49:35 2012 +0200
     1.3 @@ -1,43 +1,46 @@
     1.4  #!/bin/sh
     1.5  
     1.6  sw=""
     1.7 -case "$(basename $0)" in
     1.8 -rootflags)	sw="-R" ;;
     1.9 -ramsize)	sw="-r" ;;
    1.10 -vidmode)	sw="-v" ;;
    1.11 +case "$0" in
    1.12 +*rootflags)	sw="-R" ;;
    1.13 +*ramsize)	sw="-r" ;;
    1.14 +*vidmode)	sw="-v" ;;
    1.15  esac
    1.16  [ -n "$sw" ] && set -- $sw "$@"
    1.17  
    1.18 -offset=508
    1.19 -image=
    1.20 -value=
    1.21 -format="Root device 0x%X"
    1.22 +ofs=508
    1.23 +img=
    1.24 +val=
    1.25 +fmt="Root device 0x%04X"
    1.26  while [ -n "$1" ]; do
    1.27  	case "$1" in	
    1.28 -	-R)	offset=498; format="Root flags %d";;
    1.29 -	-r)	offset=504; format="Ramsize %d";;
    1.30 -	-v)	offset=506; format="Video mode%d";;
    1.31 -	-o)	offset=$(($2)); shift ;;
    1.32 -	*)	if [ -z "$image" ]; then
    1.33 -			image="$1"
    1.34 -		elif [ -z "$value" ]; then
    1.35 -			value="$1"
    1.36 +	-R)	ofs=498; fmt="Root flags %u" ;;
    1.37 +	-r)	ofs=504; fmt="Ramsize %u" ;;
    1.38 +	-v)	ofs=506; fmt="Video mode %u" ;;
    1.39 +	-o)	ofs=$(($2)); shift ;;
    1.40 +	*-h*)	echo "Usage: rdev [-Rrvh] [-o offset] [kernel [data [offset]]]"
    1.41 +		exit 1 ;;
    1.42 +	*)	if [ -z "$img" ]; then
    1.43 +			img="$1"
    1.44 +		elif [ -z "$val" ]; then
    1.45 +			val="$1"
    1.46 +			[ "${val:0:5}" == "/dev/" ] &&
    1.47 +			val=$((256*$(stat -c %t $val)+$(stat -c %T $val)))
    1.48  		else
    1.49 -			offset=$(($1))
    1.50 +			ofs=$(($1))
    1.51  		fi
    1.52  	esac
    1.53  	shift
    1.54  done
    1.55  
    1.56 -if [ ! -s "$image" ]; then
    1.57 +dd="dd bs=1 conv=notrunc count=2"
    1.58 +if [ ! -s "$img" ]; then
    1.59  	printf "0x%04X /\n" $(cat /proc/sys/kernel/real-root-dev)
    1.60 -elif [ -n "$value" ]; then
    1.61 +elif [ -n "$val" ]; then
    1.62  	for i in 1 2; do
    1.63 -		printf '\\\\x%02X' $(($value & 255))
    1.64 -		value=$(($value >> 8))
    1.65 -	done | xargs echo -en | \
    1.66 -	dd bs=1 conv=notrunc of=$image seek=$offset 2> /dev/null
    1.67 +		printf '\\\\x%02X' $(($val & 255))
    1.68 +		val=$(($val >> 8))
    1.69 +	done | xargs echo -en | $dd of=$img seek=$ofs
    1.70  else
    1.71 -	dd bs=1 conv=notrunc if=$image skip=$offset count=2 2> /dev/null | \
    1.72 -	hexdump -e '"" 1/2 "$format" "\n"'
    1.73 -fi
    1.74 +	$dd if=$img skip=$ofs | hexdump -e "\"\" 1/2 \"$fmt\" \"\n\""
    1.75 +fi 2>/dev/null