[PATCH v2 04/13] tools/nolibc: add missing nanoseconds support for __NR_statx

Thomas Weißschuh thomas at t-8ch.de
Mon May 29 14:39:11 PDT 2023


On 2023-05-30 03:50:34+0800, Zhangjin Wu wrote:
> Commit a89c937d781a ("tools/nolibc: support nanoseconds in stat()")
> added nanoseconds for stat() but missed the statx case, this adds it.

Welp, I should have thought of that.
At least the testcase seems to have been useful.

Thanks for the fix!

> The stx_atime, stx_mtime, stx_ctime are in type of 'struct
> statx_timestamp', which is incompatible with 'struct timespec', should
> convert explicitly.
> 
>     /* include/uapi/linux/stat.h */
> 
>     struct statx_timestamp {
>     	__s64	tv_sec;
>     	__u32	tv_nsec;
>     	__s32	__reserved;
>     };
> 
>     /* include/uapi/linux/time_types.h */
>     struct __kernel_timespec {
>     	__kernel_time64_t       tv_sec;                 /* seconds */
>     	long long               tv_nsec;                /* nanoseconds */
>     };
> 
>     /* tools/include/nolibc/types.h */
>     #define timespec __kernel_timespec
> 
> Without this patch, the stat_timestamps test case would fail on rv32.
> 
> Fixes: a89c937d781a ("tools/nolibc: support nanoseconds in stat()")
> Signed-off-by: Zhangjin Wu <falcon at tinylab.org>
> ---
>  tools/include/nolibc/sys.h | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h
> index 154194056962..98cfa2f6d021 100644
> --- a/tools/include/nolibc/sys.h
> +++ b/tools/include/nolibc/sys.h
> @@ -1175,9 +1175,9 @@ int sys_stat(const char *path, struct stat *buf)
>  	buf->st_size    = statx.stx_size;
>  	buf->st_blksize = statx.stx_blksize;
>  	buf->st_blocks  = statx.stx_blocks;
> -	buf->st_atime   = statx.stx_atime.tv_sec;
> -	buf->st_mtime   = statx.stx_mtime.tv_sec;
> -	buf->st_ctime   = statx.stx_ctime.tv_sec;
> +	buf->st_atim    = (struct timespec){ .tv_sec = statx.stx_atime.tv_sec, .tv_nsec = statx.stx_atime.tv_nsec };
> +	buf->st_mtim    = (struct timespec){ .tv_sec = statx.stx_mtime.tv_sec, .tv_nsec = statx.stx_mtime.tv_nsec };
> +	buf->st_ctim    = (struct timespec){ .tv_sec = statx.stx_ctime.tv_sec, .tv_nsec = statx.stx_ctime.tv_nsec };

I would prefer to split the compound assignment into two single
assignments, though.

buf->st_ctim.tv_sec = statx.stx_ctime.tv_sec;
buf->st_ctim.tv_nsec = statx.stx_ctime.tv_nsec;

>  	return ret;
>  }
>  #else
> -- 
> 2.25.1
> 



More information about the linux-riscv mailing list