Skip to content

fs: add hardlink and mountpt link/lstat infrastructure - #19949

Open
Kaben123 wants to merge 5 commits into
apache:masterfrom
Kaben123:pse52-01-link-infra
Open

fs: add hardlink and mountpt link/lstat infrastructure#19949
Kaben123 wants to merge 5 commits into
apache:masterfrom
Kaben123:pse52-01-link-infra

Conversation

@Kaben123

@Kaben123 Kaben123 commented Aug 24, 2026

Copy link
Copy Markdown

Summary

This PR adds the core hardlink and mountpoint link infrastructure to the
NuttX filesystem layer. It is the foundation of a larger PSE52/POSIX
filesystem-enhancement stack (path resolution, FS backends, and bug fixes
will follow in separate PRs).

Changes (one upstream commit each):

  1. fs/vfs: add hardlink function of pseudofslink() now creates a
    real hard link within the pseudo-filesystem (instead of silently
    degrading to a symlink). A hard-link inode type (FSNODEFLAG_TYPE_HARDLINK)
    is added, and the target link count is tracked in the high bits of
    i_crefs (INODE_NLINK_INC), enforcing _POSIX_LINK_MAX.
  2. fs: rename PSEUDOFS_SOFTLINKS to FS_LINKS — the config now covers both
    soft and hard links, so the option is renamed. All references
    (syscall.csv, syscall_lookup.h, lib_realpath, link/at wrappers, board
    defconfigs) are updated accordingly.
  3. fs/vfs: add link/symlink/readlink support for mountpt — adds link,
    symlink, readlink methods to mountpt_operations so mounted
    filesystems can implement links; the VFS wrappers are updated to route to
    them.
  4. fs/vfs/rename: rename a directory to an empty directory — implements
    POSIX rename semantics for directories (empty target dir is removed;
    non-empty yields ENOTEMPTY).
  5. fs/vfs: add lstat interface to mountpt_operations — adds lstat so
    rename does not dereference symbolic links.

Impact

  • Breaking config change: CONFIG_PSEUDOFS_SOFTLINKS is renamed to
    CONFIG_FS_LINKS. Out-of-tree configs referencing the old name must be
    updated. In-tree defconfigs are migrated in this PR.
  • New mountpt_operations methods (link/symlink/readlink/lstat) are
    appended at the end of the struct (guarded by CONFIG_FS_LINKS), so
    existing filesystems' positional initializers are unaffected.
  • link() behavior changes for pseudofs: it now creates a true hard link
    rather than a symlink.

Testing

  • Built sim:nsh with CONFIG_FS_LINKS enabled — zero errors/warnings.
  • tools/checkpatch.sh passes on all changed lines.

This is part of a filesystem enhancement stack. Follow-up PRs:

  • inode path-resolution infrastructure (independent, based on master)
  • hostfs/rpmsgfs link/lstat backends (depends on this PR)
  • target FS bug fixes (depends on this PR + the other two)

Depends-On: apache/nuttx-apps#3753

@github-actions

github-actions Bot commented Aug 24, 2026

Copy link
Copy Markdown

MemBrowse Memory Report

arduino-mega2560

  • flash: .text -24 B (-0.0%, 64,370 B / 262,144 B, total: 25% used)

esp32-devkitc

  • ROM: .flash.text -44 B (-0.0%, 124,432 B / 4,194,272 B, total: 3% used)
  • irom0_0_seg: .flash.text -44 B (-0.0%, 88,636 B / 3,342,304 B, total: 3% used)

hifive1-revb

  • flash: .text -4 B (-0.0%, 83,372 B / 4,194,304 B, total: 2% used)

mirtoo

  • kseg0_progmem: .text -40 B (-0.1%, 66,968 B / 131,072 B, total: 51% used)

qemu-armv8a

  • Code: .text.dir_read -8 B, .text.file_vopen -24 B, .text.rename -16 B (-0.0%, 319,092 B)

qemu-intel64

  • Code: .text -38 B (-0.0%, 8,659,048 B)

rx65n-rsk2mb

  • ROM: .text -32 B (-0.0%, 86,464 B / 2,097,152 B, total: 4% used)

s698pm-dkit

  • Code: .text -96 B (-0.0%, 363,552 B)

stm32-nucleo-f103rb

  • flash: .text -16 B (-0.0%, 34,100 B / 131,072 B, total: 26% used)

@xiaoxiang781216

Copy link
Copy Markdown
Contributor

@Kaben123 fix:

../nuttx/tools/checkpatch.sh -c -u -m -g  fae893d4115e43fcf530243b391f7708cc71a6af..HEAD
❌ Missing git commit message
❌ Missing git commit message

@Kaben123
Kaben123 force-pushed the pse52-01-link-infra branch 2 times, most recently from 3f2a431 to 0666a5e Compare August 25, 2026 02:36
1. add the hardlink function
2. _POSIX_LINK_MAX judgement

Signed-off-by: zhengyu16 <zhengyu16@xiaomi.com>
The link support is no longer limited to the pseudo file system and now
covers both soft (symbolic) links and hard links across the VFS.  Rename
the configuration option PSEUDOFS_SOFTLINKS to the more accurate FS_LINKS
and update all references in the source, headers, Kconfig, documentation
and board defconfigs accordingly.

This is a configuration rename; any out-of-tree defconfig that still
selects PSEUDOFS_SOFTLINKS must be updated to FS_LINKS.

Signed-off-by: zhengyu16 <zhengyu16@xiaomi.com>
1. add three func to mountpt_operations:
   link
   symlink
   readlink
2. modify fs_link、fs_symlink、fs_readlink for mountpt

Signed-off-by: zhengyu16 <zhengyu16@xiaomi.com>
resolve rename{7}:
On a call to rename(old, new), when the old argument points to the pathname of a directory, if the directory named by the new argument exists and is empty it shall be removed and old renamed to new.

resolve rename{23}:
EEXIST or ENOTEMPTY in errno and a return value of -1 on a call to rename(old, new) when the link named by new is a directory containing
entries other than dot and dot-dot.  The named files are not changed.

Signed-off-by: zhengyu16 <zhengyu16@xiaomi.com>
Add an lstat method to mountpt_operations so that mounted file systems
can report link metadata without dereferencing symbolic links.

In mountptrename() and stat_recursive(), prefer lstat() over stat()
when it is available so that rename() and the non-following stat path
operate on the link itself rather than its target, matching POSIX
semantics.

Signed-off-by: zhengyu16 <zhengyu16@xiaomi.com>
@Kaben123
Kaben123 force-pushed the pse52-01-link-infra branch from f66e6b1 to fa3a4a9 Compare August 25, 2026 13:33
@github-actions

github-actions Bot commented Aug 25, 2026

Copy link
Copy Markdown

🔗 Cross-repo PR dependencies

The read-only Build run reported the following dependent PR(s) and fetched head SHA(s):

CI run: https://github.com/apache/nuttx/actions/runs/32854101565

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants