[fix][dfs] 增加文件系统操作的类型检查,防止类型不匹配导致数据结构不一致引发的异常 - #11612
Conversation
|
👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread! 为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。 🛠 操作步骤 | Steps
完成后,提交将自动更新至 如有问题欢迎联系我们,再次感谢您的贡献!💐 |
📌 Code Review Assignment🏷️ Tag: componentsReviewers: @Maihuanyi Changed Files (Click to expand)
📊 Current Review Status (Last Updated: 2026-07-27 23:08 CST)
📝 Review Instructions
|
|
There was a problem hiding this comment.
这个修改在 DFSV2 中 dfs_file_read() 会提前停止,dfs_file_write() 也存在类似问题
详见:
https://github.com/Unbear-Hz/rt-thread/blob/d25ebcd8e88ab3fb107d9be846ad75dfc5f8ccd1/components/dfs/dfs_v2/src/dfs_file.c#L974
目录不会进入这个后端检查,最终仍返回 -EBADF。建议把目录判断放到公共层,并且放在后端操作检查之前。
There was a problem hiding this comment.
这个存在相同的类似问题,-ENOTDIR 加在文件系统后端,但公共层在调用后端之前已经处理了不是目录的情况。
There was a problem hiding this comment.
fsync() 没有进行错误逻辑转换,会导致 DFS 内部错误码直接泄漏到 POSIX API。
调用链:
fsync(fd)
-> dfs_file_flush(file)
-> file->vnode->fops->flush(file)
-> dfs_elm_flush(file)
导致调用者会直接收到:fsync(dirfd) == -EISDIR
fsync() 的注释已经声明了正确约定:
@return 0 on successful completion.
Otherwise, -1 shall be returned and errno set to indicate the error.
拉取/合并请求描述:(PR description)
[
为什么提交这份PR (why to submit this PR)
部分文件系统操作不支持全部类型,传入不匹配的类型导致强转为不一致的数据结构,继而引发后续操作的异常
你的解决方案是什么 (what is your solution)
在这类文件系统操作的入口处新增类型检查,避免后续异常
请提供验证的bsp和config (provide the config and bsp)
BSP:
.config:
action:
]
当前拉取/合并请求的状态 Intent for your PR
必须选择一项 Choose one (Mandatory):
代码质量 Code Quality:
我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:
#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up