Skip to contentSkip to conversation

the major/minor value of statx(kernel samples/vfs/test-statx.c) does not match /usr/bin/stat

DISCUSSION Wang Yugui 2 participants 3 messages Jun 17, 2021 – Jun 23, 2021

Subsystems (2)
lore
Share & tools
lore

Wang Yugui

author
#0 lore raw

Hi,

the major/minor value of statx(kernel samples/vfs/test-statx.c) does not match /usr/bin/stat.

major/minor of statx result seems be truncated by something like old_decode_dev()?

kernel:5.10.44
kernel-headers:5.10.44
test fs: vfat, xfs, btrfs

btrfs output sample:

[root@T640 vfs]# ./test-statx /ssd/
statx(/ssd/) = 0
results=1fff

  Size: 200             Blocks: 0          IO Block: 4096    directory
Device: 00:31           Inode: 256         Links: 1

Access: (0755/drwxr-xr-x) Uid: 0 Gid: 0
Access: 2021-06-16 19:16:56.644344956+0800
Modify: 2021-05-06 16:14:33.676248229+0800
Change: 2021-05-06 16:14:33.676248229+0800
Birth: 2020-11-18 14:03:35.324915316+0800
Attributes: 0000000000002000 (........ ........ ........ ........ ........ ..-..... ..?-.... .---.-..) [root@T640 vfs]# stat /ssd/
File: ‘/ssd/’
Size: 200 Blocks: 0 IO Block: 4096 directory
Device: 31h/49d Inode: 256 Links: 1
Access: (0755/drwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2021-06-16 19:16:56.644344956 +0800
Modify: 2021-05-06 16:14:33.676248229 +0800
Change: 2021-05-06 16:14:33.676248229 +0800
Birth: -

vfat output sample:
[root@T640 vfs]# ./test-statx /boot/efi/
statx(/boot/efi/) = 0
results=17ff

  Size: 4096            Blocks: 8          IO Block: 4096    directory
Device: 08:01           Inode: 1           Links: 3

Access: (0700/drwx------) Uid: 0 Gid: 0
Access: 1970-01-01 08:00:00.000000000+0800
Modify: 1970-01-01 08:00:00.000000000+0800
Change: 1970-01-01 08:00:00.000000000+0800
Attributes: 0000000000002000 (........ ........ ........ ........ ........ ..-..... ..?-.... ........) [root@T640 vfs]# stat /boot/efi/
File: ‘/boot/efi/’

  Size: 4096            Blocks: 8          IO Block: 4096   directory
Device: 801h/2049d      Inode: 1           Links: 3
Access: (0700/drwx------)  Uid: (    0/    root)   Gid: (    0/    root)

Access: 1970-01-01 08:00:00.000000000 +0800
Modify: 1970-01-01 08:00:00.000000000 +0800
Change: 1970-01-01 08:00:00.000000000 +0800
Birth: -

Best Regards
Wang Yugui ([email protected])
2021/06/17

#1 lore raw
Quoted 5 lines · Wang Yugui

the major/minor value of statx(kernel samples/vfs/test-statx.c) does not match /usr/bin/stat.

major/minor of statx result seems be truncated by something like old_decode_dev()?

I've checked the code first, both stat/statx seem to be doing the same thing.

Quoted 5 lines

[root@T640 vfs]# ./test-statx /ssd/
statx(/ssd/) = 0
results=1fff

  Size: 200             Blocks: 0          IO Block: 4096    directory
Device: 00:31           Inode: 256         Links: 1

So Device is 00:31, printed as two fields in hex.

Quoted 10 lines

Access: (0755/drwxr-xr-x) Uid: 0 Gid: 0
Access: 2021-06-16 19:16:56.644344956+0800
Modify: 2021-05-06 16:14:33.676248229+0800
Change: 2021-05-06 16:14:33.676248229+0800
Birth: 2020-11-18 14:03:35.324915316+0800
Attributes: 0000000000002000 (........ ........ ........ ........ ........ ..-..... ..?-.... .---.-..) [root@T640 vfs]# stat /ssd/
File: ‘/ssd/’
Size: 200 Blocks: 0 IO Block: 4096 directory
Device: 31h/49d Inode: 256 Links: 1

And here it's also 31, the 'h' suffix means it's hexadecimal and "49d" si the same value in decimal.

Quoted 6 lines

Access: (0755/drwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2021-06-16 19:16:56.644344956 +0800
Modify: 2021-05-06 16:14:33.676248229 +0800
Change: 2021-05-06 16:14:33.676248229 +0800
Birth: -

Quoted 6 lines

vfat output sample:
[root@T640 vfs]# ./test-statx /boot/efi/
statx(/boot/efi/) = 0
results=17ff

  Size: 4096            Blocks: 8          IO Block: 4096    directory
Device: 08:01           Inode: 1           Links: 3

08:01

Quoted 9 lines

Access: (0700/drwx------) Uid: 0 Gid: 0
Access: 1970-01-01 08:00:00.000000000+0800
Modify: 1970-01-01 08:00:00.000000000+0800
Change: 1970-01-01 08:00:00.000000000+0800
Attributes: 0000000000002000 (........ ........ ........ ........ ........ ..-..... ..?-.... ........) [root@T640 vfs]# stat /boot/efi/
File: ‘/boot/efi/’

  Size: 4096            Blocks: 8          IO Block: 4096   directory
Device: 801h/2049d      Inode: 1           Links: 3

801h == 0801h the same value, so it's just a matter of formatting the output and the values are indeed the same.

If you change the format in test-statx.c to "%2xh/%2dd" and the value to "(stx->stx_dev_major << 8) + stx->stx_dev_minor", the output is exactly the same.

author
#2 lore raw

Hi,

Quoted 57 lines · Wang Yugui
Quoted 5 lines

the major/minor value of statx(kernel samples/vfs/test-statx.c) does not match /usr/bin/stat.

major/minor of statx result seems be truncated by something like old_decode_dev()?

I've checked the code first, both stat/statx seem to be doing the same thing.

Quoted 5 lines

[root@T640 vfs]# ./test-statx /ssd/
statx(/ssd/) = 0
results=1fff

  Size: 200             Blocks: 0          IO Block: 4096    directory
Device: 00:31           Inode: 256         Links: 1

So Device is 00:31, printed as two fields in hex.

Quoted 10 lines

Access: (0755/drwxr-xr-x) Uid: 0 Gid: 0
Access: 2021-06-16 19:16:56.644344956+0800
Modify: 2021-05-06 16:14:33.676248229+0800
Change: 2021-05-06 16:14:33.676248229+0800
Birth: 2020-11-18 14:03:35.324915316+0800
Attributes: 0000000000002000 (........ ........ ........ ........ ........ ..-..... ..?-.... .---.-..) [root@T640 vfs]# stat /ssd/
File: ‘/ssd/’
Size: 200 Blocks: 0 IO Block: 4096 directory
Device: 31h/49d Inode: 256 Links: 1

And here it's also 31, the 'h' suffix means it's hexadecimal and "49d" si the same value in decimal.

Quoted 6 lines

Access: (0755/drwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2021-06-16 19:16:56.644344956 +0800
Modify: 2021-05-06 16:14:33.676248229 +0800
Change: 2021-05-06 16:14:33.676248229 +0800
Birth: -

Quoted 6 lines

vfat output sample:
[root@T640 vfs]# ./test-statx /boot/efi/
statx(/boot/efi/) = 0
results=17ff

  Size: 4096            Blocks: 8          IO Block: 4096    directory
Device: 08:01           Inode: 1           Links: 3

08:01

Quoted 9 lines

Access: (0700/drwx------) Uid: 0 Gid: 0
Access: 1970-01-01 08:00:00.000000000+0800
Modify: 1970-01-01 08:00:00.000000000+0800
Change: 1970-01-01 08:00:00.000000000+0800
Attributes: 0000000000002000 (........ ........ ........ ........ ........ ..-..... ..?-.... ........) [root@T640 vfs]# stat /boot/efi/
File: ‘/boot/efi/’

  Size: 4096            Blocks: 8          IO Block: 4096   directory
Device: 801h/2049d      Inode: 1           Links: 3
Quoted 6 lines

801h == 0801h the same value, so it's just a matter of formatting the output and the values are indeed the same.

If you change the format in test-statx.c to "%2xh/%2dd" and the value to "(stx->stx_dev_major << 8) + stx->stx_dev_minor", the output is exactly the same.

'/bin/stat' output (struct stat).st_dev in both hex and decimal.

coreutils-8.32/src/stat.c

    case 'd':
      out_uint (pformat, prefix_len, statbuf->st_dev);
      break;
    case 'D':
      out_uint_x (pformat, prefix_len, statbuf->st_dev);
      break;

But I thought it output the major and minor of (struct stat).st_dev.

That is my bad. Thanks a lot.

Best Regards
Wang Yugui ([email protected])
2021/06/24