GNU bug report logs - #48960
stat v8.30 - device number in decimal shown as 16bit number instead of to converted 8bit

Previous Next

Package: coreutils;

Reported by: wolfgang.rohm <at> arcor.de

Date: Fri, 11 Jun 2021 14:58:03 UTC

Severity: normal

Done: Pádraig Brady <P <at> draigBrady.com>

Bug is archived. No further changes may be made.

Full log


Message #11 received at 48960 <at> debbugs.gnu.org (full text, mbox):

From: L A Walsh <coreutils <at> tlinx.org>
To: Wolfgang Rohm <wolfgang.rohm <at> arcor.de>
Cc: 48960 <at> debbugs.gnu.org
Subject: Re: 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
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









This bug report was last modified 3 years and 340 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.