Bug 12041 - /bin/stat always prints zero fractional seconds
Summary: /bin/stat always prints zero fractional seconds
Status: RESOLVED FIXED
Alias: None
Product: Busybox
Classification: Unclassified
Component: Other (show other bugs)
Version: unspecified
Hardware: All Linux
: P5 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-07-18 09:27 UTC by Roman Perepelitsa
Modified: 2019-08-05 08:37 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.