Re: [PATCH v4 2/3] tools/nolibc: Add statfs()
From: Thomas Weißschuh
Date: Thu May 14 2026 - 07:45:55 EST
On 2026-05-07 18:03:52+0900, Daniel Palmer wrote:
> Add statfs().
>
> Signed-off-by: Daniel Palmer <daniel@xxxxxxxxx>
> ---
> tools/include/nolibc/Makefile | 1 +
> tools/include/nolibc/nolibc.h | 1 +
> tools/include/nolibc/sys/statfs.h | 50 +++++++++++++++++++++++++++++++
> 3 files changed, 52 insertions(+)
> create mode 100644 tools/include/nolibc/sys/statfs.h
>
> diff --git a/tools/include/nolibc/Makefile b/tools/include/nolibc/Makefile
> index 00fd2e566d75..e6281f58e6e2 100644
> --- a/tools/include/nolibc/Makefile
> +++ b/tools/include/nolibc/Makefile
> @@ -60,6 +60,7 @@ all_files := \
> sys/resource.h \
> sys/select.h \
> sys/stat.h \
> + sys/statfs.h \
> sys/syscall.h \
> sys/sysmacros.h \
> sys/time.h \
> diff --git a/tools/include/nolibc/nolibc.h b/tools/include/nolibc/nolibc.h
> index faa94f247281..425cf87befdc 100644
> --- a/tools/include/nolibc/nolibc.h
> +++ b/tools/include/nolibc/nolibc.h
> @@ -107,6 +107,7 @@
> #include "sys/resource.h"
> #include "sys/select.h"
> #include "sys/stat.h"
> +#include "sys/statfs.h"
> #include "sys/syscall.h"
> #include "sys/sysmacros.h"
> #include "sys/time.h"
> diff --git a/tools/include/nolibc/sys/statfs.h b/tools/include/nolibc/sys/statfs.h
> new file mode 100644
> index 000000000000..26976ac2e94a
> --- /dev/null
> +++ b/tools/include/nolibc/sys/statfs.h
> @@ -0,0 +1,50 @@
> +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */
> +/*
> + * statfs for NOLIBC
> + * Copyright (C) 2026 Daniel Palmer <daniel@xxxxxxxxx>
> + */
> +
> +/* make sure to include all global symbols */
> +#include "../nolibc.h"
> +
> +#ifndef _NOLIBC_SYS_STATFS_H
> +#define _NOLIBC_SYS_STATFS_H
> +
> +#include "../sys.h"
> +
> +/* Some preprocessor hackery to get struct statfs to
> + * always be the 64bit one.
> + */
> +#define statfs __nolibc_kernel_statfs
> +#define statfs64 __nolibc_kernel_statfs64
> +#include <asm/statfs.h>
> +#undef statfs
> +#undef statfs64
> +
> +#ifdef __NR_statfs64
> +#define statfs __nolibc_kernel_statfs64
> +#else
> +#define statfs __nolibc_kernel_statfs
> +#endif
This #define can wreak havoc in user code.
While it would be nice to have statfs() in nolibc,
I don't see a proper way to work with the current UAPI header.
Can we do without statfs() for now?
> +
> +/*
> + * statfs(const char *path, struct statfs *buf);
> + */
> +
> +static __attribute__((unused))
> +int _sys_statfs(const char *path, struct statfs *buf)
> +{
> +#ifdef __NR_statfs64
> + return __nolibc_syscall3(__NR_statfs64, path, sizeof(*buf), buf);
> +#else
> + return __nolibc_syscall2(__NR_statfs, path, buf);
> +#endif
> +}
(...)