Bug 12041

Summary: /bin/stat always prints zero fractional seconds
Product: Busybox Reporter: Roman Perepelitsa <roman.perepelitsa>
Component: OtherAssignee: unassigned
Status: RESOLVED FIXED    
Severity: normal CC: busybox-cvs
Priority: P5    
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: Linux   
Host: Target:
Build:

Description Roman Perepelitsa 2019-07-18 09:27:43 UTC
This came from https://gitlab.alpinelinux.org/alpine/aports/issues/10542.

/bin/stat from Busybox prints zero fractional seconds for mtime, atime and ctime. For example, on default install of Alpine Linux:

    touch /tmp/test
    stat /tmp/test

Output:

    File: /tmp/test
    Size: 0 Blocks: 0 IO Block: 4096 regular empty file
    Device: 7ah/122d Inode: 2909137 Links: 1
    Access: (0644/-rw-r—r—) Uid: ( 0/ root) Gid: ( 0/ root)
    Access: 2019-06-07 12:14:02.000000000
    Modify: 2019-06-07 12:14:02.000000000
    Change: 2019-06-07 12:14:02.000000000

Compare to /bin/stat from coreutils on the same system:

    File: /tmp/test
    Size: 0 Blocks: 0 IO Block: 4096 regular empty file
    Device: 7ah/122d Inode: 2909137 Links: 1
    Access: (0644/-rw-r—r—) Uid: ( 0/ root) Gid: ( 0/ root)
    Access: 2019-06-07 12:14:02.906502175 +0000
    Modify: 2019-06-07 12:14:02.906502175 +0000
    Change: 2019-06-07 12:14:02.906502175 +0000
    Birth: -

Apparently, Busybox deliberately prints zeros instead of the real fractional seconds: https://git.busybox.net/busybox/tree/coreutils/stat.c?id=e2026381bed88e79b6f7657eef8319e60ff83041#n166. Is it possible to fix this? This is confusing since the output isn't just missing data but contains incorrect data. When seeing the output with 000000000 for fractional seconds, one can reasonably take this to mean that fractional seconds are zero.
Comment 1 Denys Vlasenko 2019-08-05 08:37:56 UTC
Fixed in git. Thanks.