Skip to content

fs/procfs: list registered entries once and in their directory - #21724

Merged
xiaoxiang781216 merged 3 commits into
apache:masterfrom
jingfei195887:fs/procfs-readdir-dup
Nov 12, 2026
Merged

xiaoxiang781216 merged 3 commits into
apache:masterfrom
jingfei195887:fs/procfs-readdir-dup

Conversation

@jingfei195887

Copy link
Copy Markdown
Contributor

Summary

  • fs/procfs: list registered entries once and in their directory.
    procfs_readdir() assumes that the entries of one directory are adjacent
    in g_procfs_entries, and drops a first-level name only when it repeats
    the name reported just before it. procfs_register() appends to the end
    of the table, so after registering fs/foo and foo_bar, ls /proc
    shows fs twice and hides foo_bar, and ls /proc/fs never reaches
    foo. Each directory now scans the rest of the table and skips a name
    an earlier entry already yields.
  • fs/procfs: drop redundant uint8_t casts in the proc node table. The
    field is already uint8_t.
  • fs/procfs: call running_regs() directly in tcbinfo.
    tcbinfo_running_regs() is a non-optimized wrapper that kept
    g_running_tasks from being optimized out; the scheduler now uses
    g_running_tasks on every configuration.

Impact

Only directory listings of procfs change, and only when entries were added
with procfs_register(). The built-in table lists as before.

Testing

Host: Ubuntu x86_64, gcc (Ubuntu 13.1.0-8ubuntu1~22.04) 13.1.0, master 5fbae0c (rebased onto 5fbae0c; no new
commit touches fs/procfs), sim:nsh with CONFIG_FS_PROCFS_REGISTER,
CONFIG_NET_LOOPBACK and CONFIG_NET_ROUTE. A small test program calls
procfs_register() for fs/fsup_a and fsup_nodup, then lists the
directories with opendir()/readdir():

master this PR
/proc ... uptime version fs (fs twice, no fsup_nodup) ... uptime version fsup_nodup
/proc/fs blocks mount usage blocks mount usage fsup_a
/proc/net route lo route lo
/proc/net/route ipv4 ipv4

cat /proc/tcbinfo still prints the current regs pointer.

  • ./tools/checkpatch.sh -g master..HEAD: all checks pass.
  • Make and CMake builds pass; ostest exits with status 0.

yezhonghui2024 and others added 3 commits November 12, 2026 00:35
procfs_readdir() assumes that the entries of one directory are adjacent
in g_procfs_entries, and drops a first-level name only when it repeats
the name reported just before it.  procfs_register() appends to the end
of the table, so after registering "fs/foo" and "foo_bar":

- "ls /proc" reports "fs" a second time, and hides "foo_bar" because
  its first two characters match the "fs" reported before it.
- "ls /proc/fs" stops at the first entry outside fs/ and never reaches
  "foo".

Scan the rest of the table for each directory instead, and skip a name
when an earlier entry already yields it.  Since the scan now covers the
whole table, a member of a subdirectory must also have '/' right after
the directory name, so "foo_bar" is not taken as part of "fs".

Signed-off-by: yezhonghui <[email protected]>
Signed-off-by: jingfei <[email protected]>
The node field of struct proc_node_s is already uint8_t, so the
explicit casts on the initializers do nothing.

Signed-off-by: Xiang Xiao <[email protected]>
Signed-off-by: jingfei <[email protected]>
tcbinfo_running_regs() is a non-optimized wrapper around
running_regs().  It was added to keep g_running_tasks from being
optimized out, but g_running_tasks is now used by the scheduler on
every configuration, so the wrapper is no longer needed.

Signed-off-by: xuxingliang <[email protected]>
Signed-off-by: jingfei <[email protected]>
@xiaoxiang781216
xiaoxiang781216 marked this pull request as ready for review November 11, 2026 16:53
@github-actions github-actions Bot added Area: File System File System issues Size: M The size of the change in this PR is medium labels Nov 11, 2026
@xiaoxiang781216
xiaoxiang781216 merged commit d779963 into apache:master Nov 12, 2026
61 of 63 checks passed
xiaoxiang781216 pushed a commit that referenced this pull request Nov 12, 2026
ab32vg1-generic:ostest runs from the 114 KB SRAM.  After #21724 the
image does not fit:

  riscv-none-elf-ld: region `sram' overflowed by 54 bytes

This configuration starts ostest_main and has no shell, and ostest does
not read /proc, so nothing in it uses procfs.  Disable it: this frees
about 12 KB.

Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Marco Casaroli <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: File System File System 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.

5 participants