tools/nolibc: support nanoseconds in stat()
authorThomas Weißschuh <linux@weissschuh.net>
Sat, 27 May 2023 12:56:42 +0000 (14:56 +0200)
committerPaul E. McKenney <paulmck@kernel.org>
Fri, 9 Jun 2023 18:46:09 +0000 (11:46 -0700)
commit87b9fa66af9ad92097c0593626dea3654ec19fd0
tree499fa987f15efb7da8cee8b3a6587fd9006d8686
parent9a75575b81b5639f7ca82c9701fb199401fd6471
tools/nolibc: support nanoseconds in stat()

Keep backwards compatibility through unions.

The compatibility macros like

 #define st_atime st_atim.tv_sec

as documented in stat(3type) don't work for nolibc because it would
break with other stat-like structures that contain the field st_atime.

The stx_atime, stx_mtime, stx_ctime are in type of 'struct
statx_timestamp', which is incompatible with 'struct timespec', should
be converted explicitly.

    /* include/uapi/linux/stat.h */

    struct statx_timestamp {
     __s64 tv_sec;
     __u32 tv_nsec;
     __s32 __reserved;
    };

    /* include/uapi/linux/time.h */
    struct timespec {
     __kernel_old_time_t tv_sec; /* seconds */
     long tv_nsec; /* nanoseconds */
    };

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Link: https://lore.kernel.org/linux-riscv/3a3edd48-1ace-4c89-89e8-9c594dd1b3c9@t-8ch.de/
Co-authored-by: Zhangjin Wu <falcon@tinylab.org>
Signed-off-by: Zhangjin Wu <falcon@tinylab.org>
[wt: squashed Zhangjin & Thomas' patches into one to preserve "bisectability"]
Signed-off-by: Willy Tarreau <w@1wt.eu>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
tools/include/nolibc/sys.h
tools/include/nolibc/types.h
tools/testing/selftests/nolibc/nolibc-test.c