[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#48960: stat v8.30 - device number in decimal shown as 16bit number i
From: |
L A Walsh |
Subject: |
bug#48960: stat v8.30 - device number in decimal shown as 16bit number instead of to converted 8bit |
Date: |
Fri, 11 Jun 2021 11:21:04 -0700 |
User-agent: |
Thunderbird 2.0.0.24 (Windows/20100228) |
On 2021/06/11 00:37, Wolfgang Rohm wrote:
Hello.
Stat prints the device number, major and minor, in hex and decimal.
They are both 8bit numbers clamped together. While the hex number is
perfectly fine, the decimal doesn't respect how this number has come
to existence. There is no meaning in the decimal value, if the the hex
value is taken as one 16bit number and then converted.
For example "fd00h" is converted to "64768d". There is no major device
with 647 and no minor device with 768. Its just completely wrong.
---
Aside from complete bogus output on my system for either
hex or decimal and the "seemingly" undocumented appearance of 'd'
to convert a 16-bit decimal value back to 2 8-bit values
divide the number by 256 or shift the value right by 8 bits
for the high number and either mod the number with 256 or
'and' (&) the value with 0xff:
decimal_devno=64768 #(dropping the 'd' on the end)
high=$(($decimal_devno/256))
low=$(($decimal_devno%256))
printf "%s:%s\n" "$high" "$low"
(output:)
253:0
or via shifts+masks
decimal_devno=64768
high=$((decimal_devno>>8))
low=$((decimal_devno & 0xff))
printf "%s:%s\n" "$high" "$low"
(output:)
253:0
bug#48960: stat v8.30 - device number in decimal shown as 16bit number instead of to converted 8bit,
L A Walsh <=