Skip to content

fs/inode: build the foreach_inode() path without snprintf() - #22166

Merged
xiaoxiang781216 merged 1 commit into
apache:masterfrom
jingfei195887:fs/foreachinode-no-snprintf
Nov 23, 2026
Merged

xiaoxiang781216 merged 1 commit into
apache:masterfrom
jingfei195887:fs/foreachinode-no-snprintf

Conversation

@jingfei195887

Copy link
Copy Markdown
Contributor

Summary

  • fs/inode: build the foreach_inode() path without snprintf().
    foreach_inodelevel() appended each path segment with
    snprintf("/%s"). Since fs/vfs: sync mounted filesystems in sync() #21999, sync() walks the mountpoints with
    foreach_inode(), and sync() is always linked through the reboot
    notifier (fs_reboot_initialize()), so an image that does not otherwise
    use printf now links the whole printf engine. Copy the segment with
    strlcpy() instead; the length is already checked against PATH_MAX.

Reported by @raiden00pl in #21999 (comment) (size of minimal images).

Impact

  • No functional change: the path handed to the callbacks is the same.
  • Size: images that do not otherwise use printf no longer link it.
  • Build, hardware, documentation, security, compatibility: NO.

Testing

Host: Ubuntu 22.04 x86_64, arm-none-eabi-gcc 10.3.1 and 13.2.1.
Base: master b2b0bde. Flash = text + data.

nucleo-f302r8:nsh reduced to a minimal image: CONFIG_DEFAULT_SMALL=y,
CONFIG_LTO_FULL=y, CONFIG_INIT_NONE=y, no USART/console/syslog
channel, no /dev nodes, no procfs/romfs/tmpfs. "revert" is master with
#21999 and #22046 reverted.

image gcc 10.3 gcc 13.2 printf in image
revert #21999 + #22046 12152 12048 no
master 15672 (+3520) 15576 (+3528) yes
this PR 13220 (+1068) 13116 (+1068) no
this PR + CONFIG_DISABLE_MOUNTPOINT=y 12124 12024 no

This PR removes the printf engine (snprintf, __udivmoddi4 and the
stream helpers, about 2.4 KB). The remaining ~1 KB is the mountpoint walk
itself (sync() inlined into the reboot handler, foreach_inodelevel(),
mountpt_syncfs()); CONFIG_DISABLE_MOUNTPOINT=y removes it.

  • sim:nsh with tmpfs mounts at /x1/y2/z3 and /t1: cat /proc/fs/mount
    and umount_all() give the same output before and after.
  • ./tools/checkpatch.sh -g master..HEAD: all checks pass.
  • sim:nsh Make and CMake builds pass with no warnings in the changed
    file; ostest exits with status 0.

PR verification Self-Check

  • This PR introduces only one functional change.
  • I have updated all required description fields above.
  • My PR adheres to Contributing Guidelines and Documentation (git commit title and message, coding standard, etc).
  • My PR is still work in progress (not ready for review).
  • My PR is ready for review and can be safely merged into a codebase.

foreach_inodelevel() appended each path segment with snprintf("/%s").
sync() walks the mountpoints and is always linked through the reboot
notifier, so images that do not otherwise use printf now link the
whole printf engine.  Copy the segment with strlcpy() instead; the
length is already checked against PATH_MAX.

Signed-off-by: jingfei <[email protected]>
@github-actions github-actions Bot added Area: File System File System issues Size: XS The size of the change in this PR is very small labels Nov 23, 2026
@github-actions

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

esp32-devkitc

  • ROM: .flash.text -8 B (-0.0%, 133,580 B / 4,194,272 B, total: 3% used)
  • irom0_0_seg: .flash.text -8 B (-0.0%, 99,260 B / 3,342,304 B, total: 3% used)

mps2-an500-citest

  • flash: .text +8 B (+0.0%, 247,400 B / 4,194,304 B, total: 6% used)

qemu-intel64

  • Code: .text -14 B (-0.0%, 8,707,101 B)

stm32-nucleo-f103rb

  • flash: .text +4 B (+0.0%, 35,400 B / 131,072 B, total: 27% used)

No memory changes detected for:


Catch memory regressions in CI with MemBrowse. Free for open source.

@xiaoxiang781216
xiaoxiang781216 merged commit ea14533 into apache:master Nov 23, 2026
58 checks passed
@xiaoxiang781216 xiaoxiang781216 linked an issue Nov 23, 2026 that may be closed by this pull request
1 task done
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: XS The size of the change in this PR is very small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[HELP] Improve NuttX bloated size

4 participants