Repository navigation
Conversation
|
👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread! 为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。 🛠 操作步骤 | Steps
完成后,提交将自动更新至 如有问题欢迎联系我们,再次感谢您的贡献!💐 |
|
#5073 |
📌 Code Review Assignment🏷️ Tag: componentsReviewers: @Maihuanyi Changed Files (Click to expand)
📊 Current Review Status (Last Updated: 2026-10-17 15:28 CST)
📝 Review Instructions
|
|
c8e5b4b to
105e2fe
Compare
| * struct pointer, so args != NULL means RT_DEVICE_CTRL_CONFIG. | ||
| * - F_SETFL (POSIX) carries the new flags, so args != NULL means F_SETFL. | ||
| * CLOSE needs no args, so args == NULL means RT_DEVICE_CTRL_CLOSE. | ||
| * The fall-through path (FT_SOCKET / FT_USER / ...) is unchanged. |
There was a problem hiding this comment.
如果是这样,是否把它们定义成不同的值,这样才不会冲突?从而从根本上解决这个问题。
There was a problem hiding this comment.
对于目前rtt通用的device_ctrl。
于dfs_v1中
#define RT_DEVICE_CTRL_CONFIG 0x03 /**< configure device */
#define RT_DEVICE_CTRL_CLOSE 0x04 /**< close device */
F_GETFL 3
F_SETFL 4于dfs_v2
#define RT_DEVICE_CTRL_RESUME 0x01 /**< resume device */
#define RT_DEVICE_CTRL_SUSPEND 0x02 /**< suspend device */
#define RT_DEVICE_CTRL_CONFIG 0x03 /**< configure device */
#define RT_DEVICE_CTRL_CLOSE 0x04 /**< close device */
F_DUPFD 0
F_GETFD 1
F_SETFD 2
F_GETFL 3
F_SETFL 4是会相撞的
F_GETFL (=3) numerically collides with RT_DEVICE_CTRL_CONFIG (=3), and
F_SETFL (=4) collides with RT_DEVICE_CTRL_CLOSE (=4). When POSIX fcntl
is routed through dfs_file_ioctl/dfs_file_fcntl/devfs wrapper, the cmd
can be misinterpreted by the driver side.
The two name spaces have inverse requirements on the `args` parameter,
which lets us disambiguate without changing any cmd encoding:
cmd POSIX cmd args shape RTT cmd args shape
3 F_GETFL (ignore) NULL/0 RT_DEVICE_CTRL_CONFIG non-NULL struct *
4 F_SETFL (set flags) non-NULL int RT_DEVICE_CTRL_CLOSE NULL
Three layers, each handles its own vnode types:
* dfs_v1/src/dfs_file.c::dfs_file_ioctl
- FT_REGULAR/FT_DEVICE vnode: when cmd is F_GETFL/F_SETFL, forward
to fops->ioctl on RTT-shaped args, otherwise handle POSIX locally.
* dfs_v2/src/dfs_file.c::dfs_file_fcntl
- Fallback path for FS vnodes (FT_REGULAR etc) when dfs_file_ioctl
returns -ENOSYS. Same args-nullness split for F_GETFL/F_SETFL.
- FT_SOCKET vnode still routes through fops->ioctl so the
sock->flags mirror is updated.
* dfs_v2/filesystems/devfs/devfs.c::dfs_devfs_ioctl
- Wrapper for all FT_DEVICE vnodes in dfs_v2 (vnode->fops is _dev_fops,
not driver->fops). Same args-nullness split applied here so
RT_DEVICE_CTRL_* reaches the driver and POSIX F_SETFL updates
file->flags in place.
Corner case: fcntl(fd, F_SETFL, 0) and rt_device_control(dev,
RT_DEVICE_CTRL_CLOSE, NULL) are bit-identical through variadic
protocol. Callers should avoid F_SETFL(0) and use
fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) & ~O_NONBLOCK) to clear flags.
… nullness
拉取/合并请求描述:(PR description)
[
为什么提交这份PR (why to submit this PR)
F_GETFL (=3)在数值上与RT_DEVICE_CTRL_CONFIG (=3)撞码,F_SETFL (=4)与RT_DEVICE_CTRL_CLOSE (=4)撞码。两套 cmd 共享同一个int参数,POSIX 路径下(fcntl→dfs_file_ioctl/dfs_file_fcntl→fops->ioctl)会被 driver 误解释。具体表现:
FT_REGULAR/FT_DEVICEvnode 在dfs_file_ioctl内已经拦截 F_GETFL/F_SETFL,但FT_SOCKET仍会 fall-through;dfs_v2 的dfs_file_ioctl是 fops 的纯 passthrough,没有任何拦截,串口等 driver 在 LWP 关闭时会把F_GETFL误当成RT_DEVICE_CTRL_CONFIG实际重配硬件。fcntl调用 RT-Thread device control cmd 时被静默截胡,无法到达 driver。你的解决方案是什么 (what is your solution)
利用 POSIX 与 RT-Thread 在两个 cmd 上对
args参数的互补要求做 disambiguator,无需改动 cmd 编码:args == NULL意为struct *改动文件:
components/dfs/dfs_v1/src/dfs_file.c::dfs_file_ioctlcase F_GETFL:args != NULL && fops->ioctl→ 转发 driver(RTT CONFIG);否则返回fd->flags(POSIX)。case F_SETFL:args == NULL && fops->ioctl→ 转发 driver(RTT CLOSE);否则改fd->flags(POSIX)。components/dfs/dfs_v2/src/dfs_file.c::dfs_file_fcntlF_GETFL/F_SETFL分支按相同镜像逻辑改造,保留原 socket 通知路径(FT_SOCKET 仍调fops->ioctl(file, F_SETFL, …)更新sock->flags)。角落场景:
fcntl(fd, F_SETFL, 0)与rt_device_control(dev, RT_DEVICE_CTRL_CLOSE, NULL)在 variadic 协议下位模式相同,无法稳定判别。文档建议避免F_SETFL(0),需要清非阻塞时用fcntl(fd, F_SETFL, fd->flags & ~O_NONBLOCK)。请提供验证的bsp和config (provide the config and bsp)
]
当前拉取/合并请求的状态 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