Skip to content

libc/misc: Add statx() via struct stat composition. - #20035

Closed
xiaoxiang781216 wants to merge 1 commit into
apache:masterfrom
xiaoxiang781216:upstream-statx
Closed

libc/misc: Add statx() via struct stat composition.#20035
xiaoxiang781216 wants to merge 1 commit into
apache:masterfrom
xiaoxiang781216:upstream-statx

Conversation

@xiaoxiang781216

Copy link
Copy Markdown
Contributor

Summary

Add the Linux statx(2) extended-status interface to the libc as a composition of the existing stat/lstat/fstat/fstatat implementations, following the fstatat() pattern:

  • include/sys/stat.h: expose the exact Linux struct statx / struct statx_timestamp ABI (fixed-width fields, so the layout is stable across toolchains and a future kernel-space implementation will not break the user-space ABI), the STATX_* request/result mask constants, and the STATX_ATTR_* attribute constants.
  • include/fcntl.h: add the AT_STATX_SYNC_AS_STAT / AT_STATX_FORCE_SYNC / AT_STATX_DONT_SYNC / AT_STATX_SYNC_TYPE and AT_RECURSIVE constants.
  • libs/libc/misc/lib_statx.c: implement statx() by resolving the path like fstatat() (via lib_getfullpath()) and translating the resulting struct stat into the struct statx layout.

Semantics: NuttX can only fill STATX_BASIC_STATS; birth time, mount ID and DIO alignment stay zero with their mask bits clear. AT_EMPTY_PATH is handled via fstat(), AT_STATX_SYNC_* and AT_NO_AUTOMOUNT are accepted as no-ops, and the mask argument is treated as a hint, which Linux also permits (the kernel may return more or fewer fields than requested).

Ported code that uses statx() (libuv, glib, libfuse, ...) now builds and runs unchanged.

Impact

  • New libc API, no existing behavior is changed. struct stat, stat(), lstat(), fstat() and fstatat() are untouched.
  • No new Kconfig options; statx() is always available like the other stat family members.
  • Impact on size: one new small object file in libc (lib_statx.c).
  • Testing covered by build + boot below; the LTP statx testcases compile against this interface (they need /proc/mounts at runtime, so they are black-listed in the LTP port for now).

Testing

Built and booted sim:nsh with this change on top of apache/master (commit 035d131b3cc):

NuttShell (NSH) NuttX-10.4.0
nsh> uname -a
NuttX 10.4.0 035d131b3cc Sep  1 2026 21:37:48 sim sim

ostest passes with 0 failures:

ostest_main: Started user_main at PID=6
user_main: Begin argument test
...
user_main: Exiting
ostest_main: Exiting with status 0

tools/checkpatch.sh -c -u -m -g apache/master..HEAD passes.

Implement the Linux statx(2) extended-status interface as a libc
function that composes stat/lstat/fstat, following the existing
fstatat() pattern. Expose the exact Linux struct statx ABI together
with the STATX_* mask/attribute constants and AT_STATX_SYNC_* flags
so ported code such as libuv, glib and libfuse builds unchanged.

NuttX can only fill STATX_BASIC_STATS; btime, mount ID and DIO
alignment remain zero with their mask bits clear. AT_EMPTY_PATH is
handled via fstat(), AT_STATX_SYNC_* and AT_NO_AUTOMOUNT are accepted
as no-ops, and the mask argument is treated as a hint, which Linux
permits.

Assisted-by: Copilot:zhipuai/glm-5.3
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
@github-actions github-actions Bot added Area: OS Components OS Components issues Size: M The size of the change in this PR is medium labels Sep 1, 2026
@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown

MemBrowse Memory Report

No memory changes detected for:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: OS Components OS Components issues Size: M The size of the change in this PR is medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant