Skip to content

[dfs][posix] Report open failures with positive errno - #12067

Merged
Rbb666 merged 4 commits into
RT-Thread:masterfrom
lizezhong233:fix/dfs-open-errno
Nov 23, 2026
Merged

Rbb666 merged 4 commits into
RT-Thread:masterfrom
lizezhong233:fix/dfs-open-errno

Conversation

@lizezhong233

@lizezhong233 lizezhong233 commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

拉取/合并请求描述:(PR description)

Related to #10558.

Why

On 6fdfe70062ec, opening a missing file on a mounted filesystem returns -1 with negative errno in both DFS versions. When the descriptor table is full, DFS v1 reports -ENOMEM in errno. DFS v2 returns 0, which callers treat as an open descriptor. An RT-Smart process on ARM also receives that false success from the raw syscall and from musl.

Changes

  • Carry the reason for descriptor allocation failure through the private slot helpers. Report EMFILE at the descriptor limit and ENOMEM when table growth or file-object allocation fails. The shared descriptor allocator publishes the error after unlocking. Existing public descriptor and duplication failure return values are preserved.
  • Return -1 from POSIX open() on allocation failure. When dfs_file_open() returns a negative error, release the descriptor and publish the corresponding positive errno. A successful open can still return descriptor zero.
  • Add missing-file and full-table regression units to the existing POSIX suite. Update the A9 DFS CI profile to select the current Kconfig symbols and the BSP's sd device so the native and POSIX suites actually run.

Verification

BSP bsp/qemu-vexpress-a9, QEMU 7.2.22, Intel macOS host with a Linux build container.

Configuration Observed on the candidate
Standard, Newlib, DFS v1 and v2, tmpfs, DFS_FD_MAX=12 Missing file yields -1/ENOENT. A full table yields -1/EMFILE. Injected failure of each of the two allocator operations yields -1/ENOMEM. An independent thread retains its sentinel errno.
Standard with DFS_STDIO_OFFSET=0, POSIX stdio and termios disabled Both DFS versions open a real file as fd 0, write and read back one byte, close it and reopen after exhaustion.
A9 Standard, ELM/FAT, repository DFS CI configuration, v1 and v2 Both suites finish and pass for each version. Applying just the test and CI changes to the base makes both new units fail while the native suite passes.
RT-Smart, DFS v2, ARM MMU, two CPUs, musl user process The same user executable observes raw -ENOENT and -EMFILE, and libc -1 with positive errno. Closing stdin and opening a file returns a working fd 0.

The corresponding single-core RT-Smart configuration with context assertions enabled stops in rt_aspace_fault_try_fix before user main() on both revisions. Picolibc and non-MMU LWP received source review only. Scope is the DFS open() path and the allocation errors it consumes.

The table above reports local QEMU runs. GitHub Actions also built bsp/qemu-vexpress-a9 with CONFIG_RT_USING_DFS_V2=y at 014db4634def. Passing ARM build on the PR branch.

当前拉取/合并请求的状态 Intent for your PR

必须选择一项 Choose one (Mandatory):

  • 本拉取/合并请求是一个草稿版本 This PR is for a code-review and is intended to get feedback
  • 本拉取/合并请求是一个成熟版本 This PR is mature, and ready to be integrated into the repo

代码质量 Code Quality:

我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:

  • 已经仔细查看过代码改动的对比 Already check the difference between PR and old code
  • 代码风格正确,包括缩进空格,命名及其他风格 Style guide is adhered to, including spacing, naming and other styles
  • 没有垃圾代码,代码尽量精简,不包含#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up
  • 所有变更均有原因及合理的,并且不会影响到其他软件组件代码或BSP All modifications are justified and not affect other components or BSP
  • 对难懂代码均提供对应的注释 I've commented appropriately where code is tricky
  • 代码是高质量的 Code in this PR is of high quality
  • 已经使用clang-format 源码格式化工具确保格式符合RT-Thread代码规范 This PR has been formatted with clang-format and complies with RT-Thread code specification
  • 如果是新增bsp, 已经添加ci检查到.github/ALL_BSP_COMPILE.json 详细请参考链接BSP自查

Distinguish a full descriptor table from allocation failure. Preserve native negative DFS errors and publish positive errno at the POSIX open boundary.
Return -1 when a descriptor cannot be allocated, including when the table is full. A genuine fd 0 remains valid.
Check errno on failed opens and reopen the file after releasing the descriptors held by the test.
Select the current DFS and POSIX UTEST symbols and use the block device registered by qemu-vexpress-a9.
@CLAassistant

CLAassistant commented Nov 19, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@github-actions

Copy link
Copy Markdown

👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread!

为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。
To ensure your code complies with RT-Thread's coding style, please run the code formatting workflow by following the steps below (If the formatting of CI fails to run).


🛠 操作步骤 | Steps

  1. 前往 Actions 页面 | Go to the Actions page
    点击进入工作流 → | Click to open workflow →

  2. 点击 Run workflow | Click Run workflow

  • Use workflow from 保持默认分支(通常为 master)
    Keep the default branch (usually master) in Use workflow from
  • 在 branch 输入框填写 PR 分支 fix/dfs-open-errno
    Enter PR branch fix/dfs-open-errno in the branch field
  • 设置需排除的文件/目录(目录请以"/"结尾)
    Set files/directories to exclude (directories should end with "/")
  1. 等待工作流完成 | Wait for the workflow to complete
    格式化后的代码将作为独立提交推送至你的分支。
    The formatting changes will be pushed to your branch as a separate commit.

完成后,提交将自动更新至 fix/dfs-open-errno 分支,关联的 Pull Request 也会同步更新。
Once completed, commits will be pushed to the fix/dfs-open-errno branch automatically, and the related Pull Request will be updated.

如有问题欢迎联系我们,再次感谢您的贡献!💐
If you have any questions, feel free to reach out. Thanks again for your contribution!

@github-actions github-actions Bot added action github action yml imporve Component labels Nov 19, 2026
@github-actions

Copy link
Copy Markdown

📌 Code Review Assignment

🏷️ Tag: components

Reviewers: @Maihuanyi

Changed Files (Click to expand)
  • components/dfs/dfs_v1/src/dfs.c
  • components/dfs/dfs_v1/src/dfs_posix.c
  • components/dfs/dfs_v2/src/dfs.c
  • components/dfs/dfs_v2/src/dfs_posix.c
  • components/dfs/utest/tc_posix_api.c

🏷️ Tag: workflow

Reviewers: @Rbb666 @kurisaW @supperthomas

Changed Files (Click to expand)
  • .github/utest/configs/components/dfs.cfg

📊 Current Review Status (Last Updated: 2026-11-19 08:55 CST)


📝 Review Instructions

  1. 维护者可以通过单击此处来刷新审查状态: 🔄 刷新状态
    Maintainers can refresh the review status by clicking here: 🔄 Refresh Status

  2. 确认审核通过后评论 LGTM/lgtm
    Comment LGTM/lgtm after confirming approval

  3. PR合并前需至少一位维护者确认
    PR must be confirmed by at least one maintainer before merging

ℹ️ 刷新CI状态操作需要具备仓库写入权限。
ℹ️ Refresh CI status operation requires repository Write permission.

@BernardXiong BernardXiong left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review / 审查 — 014db463

结论 / Conclusion: COMMENT — 未发现阻塞性问题。

open() 两条 DFS 路径的 errno 传递是一致的:fd_slot_expand()/_fdt_slot_expand() 现在返回 -EMFILE/-ENOMEM,fdt_fd_new() 在解锁后用 rt_set_errno(-idx) 发布正值,open() 在 dfs_file_open() 失败时用 rt_set_errno(-result);v2 的 fd_new() 失败不再返回 0(原先把 RT_NULL 当成功)。新增用例覆盖缺文件 ENOENT 与满表 EMFILE。

非阻塞 / Non-blocking

  1. 同一 API 族中仍有负值 errno 写入:v2 openat() 的 rt_set_errno(-EBADF)/(-ENOMEM)(dfs_posix.c:114、dfs_posix.c:127、dfs_posix.c:134),v1 openat() 同样(dfs_posix.c:100),以及 v2 dfs_dup()(dfs.c:786)。rt_set_errno() 原样保存,newlib 的 __errno() 直接返回 _rt_errno(),这些路径会让 errno 变成负值,与本 PR 建立的正值语义不一致,建议作为后续统一修正。
  2. dfs_dup()/dfs_dup_to() 在描述符分配失败时仍只返回 -1 而未设置 errno,POSIX dup() 无法区分 EMFILE/ENOMEM;可作为后续改进。

CI:作者为首次贡献者,已静态核对全部 6 个改动文件(未涉及 workflow、构建脚本、依赖或外部下载),并批准本 head 的 8 个 action_required 工作流;结果返回并通过前不给出 APPROVE。

@github-actions

Copy link
Copy Markdown

@Rbb666
Rbb666 merged commit dbdf2d3 into RT-Thread:master Nov 23, 2026
117 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action github action yml imporve Component

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants