Skip to content

fix[DFS][littlefs]: align lseek callback signature with off_t#37

Merged
Rbb666 merged 1 commit into
RT-Thread-packages:masterfrom
wdfk-prog:fix_off_t
Jun 22, 2026
Merged

fix[DFS][littlefs]: align lseek callback signature with off_t#37
Rbb666 merged 1 commit into
RT-Thread-packages:masterfrom
wdfk-prog:fix_off_t

Conversation

@wdfk-prog

@wdfk-prog wdfk-prog commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

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

[

为什么提交这份PR (why to submit this PR)

RT-Thread PR #11486 中反馈,最新版 littlefs 在 Keil 编译场景下会出现 DFS lseek 回调函数指针类型不兼容问题:DFS 文件操作表期望 off_t (*)(struct dfs_file *, off_t),但 littlefs 适配层当前非 DFS_V2 分支的 _dfs_lfs_lseek 参数通过 DFS_LFS_LSEEK_PARAMS 展开为 rt_off_t offset

虽然 rt_off_t 在 RT-Thread 中确实存在,并定义为 rt_base_t,但它不等价于 DFS lseek 接口签名要求中的 off_t。在部分工具链/配置下,rt_off_t 的底层类型可能是 signed int,而 off_t 的底层类型可能是 signed long,从而导致函数指针签名不兼容。

我这里使用 GCC + DFS_V1 没有出现 warning。分析原因是该构建使用了 newlib,并定义了 RT_USING_LIBC;通过工具查看最终链路可见该 GCC 工具链中 __INT32_TYPE__long int,因此 rt_off_t 最终也会落到 long,未触发类型不兼容问题。

littlefs 当前 CI 编译使用 bsp/qemu-vexpress-a9,该路径没有暴露问题;由于没有很好的方案在 CI 中模拟 Keil/IAR 的具体 typedef 实现,这一类兼容性仍需要实际 Keil/IAR 工程验证。

你的解决方案是什么 (what is your solution)

  1. 将非 DFS_V2 分支中的 DFS_LFS_LSEEK_PARAMSrt_off_t offset 改为 off_t offset,使 _dfs_lfs_lseek 的函数签名与 RT-Thread DFS lseek 回调原型保持一致。
  2. 将 littlefs 文件位置回写处统一按 DFS 文件结构字段类型处理:文件当前位置使用 off_t,文件大小使用 size_t
  3. 加入参数接口签名检查,使 RT-Thread 5.0.2 及之后的 DFS_V1 配置在编译期确认 _dfs_lfs_lseek 与 DFS 期望的 lseek 签名一致:
#if !defined(RT_USING_DFS_V2) && defined(RT_VERSION_CHECK) && (RTTHREAD_VERSION >= RT_VERSION_CHECK(5, 0, 2))
typedef off_t (*dfs_lfs_lseek_expected_t)(struct dfs_file *file, off_t offset);
static dfs_lfs_lseek_expected_t dfs_lfs_lseek_type_check = _dfs_lfs_lseek;
#endif /* !defined(RT_USING_DFS_V2) && defined(RT_VERSION_CHECK) && (RTTHREAD_VERSION >= RT_VERSION_CHECK(5, 0, 2)) */

这里检查变量绑定到实际的静态函数 _dfs_lfs_lseek,避免仅修改函数实现但没有覆盖到 DFS 回调签名的问题。

请提供验证的bsp和config (provide the config and bsp)

  • BSP:

bsp/qemu-vexpress-a9,用于 littlefs 现有 GCC CI 路径验证。Keil/IAR 兼容性问题来源于 RT-Thread PR #11486 中的实际工程反馈,仍建议在受影响的 Keil/IAR 工程中做最终验证。

  • .config:

无需新增配置项。相关验证配置包括:

RT_USING_DFS_V1
PKG_USING_LITTLEFS

GCC 未复现 warning 的路径还包含 RT_USING_LIBC / newlib 的类型定义影响。

  • action:

not provided yet. 现有 littlefs CI 使用 bsp/qemu-vexpress-a9,不能覆盖 Keil/IAR 的 typedef 差异;Keil/IAR 仍需实际工程验证。

]

当前拉取/合并请求的状态 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
  • 已经使用formatting 等源码格式化工具确保格式符合RT-Thread代码规范 This PR complies with RT-Thread code specification
  • 如果是新增bsp, 已经添加ci检查到.github/ALL_BSP_COMPILE.json 详细请参考链接BSP自查

Summary by CodeRabbit

Bug Fixes

  • Improved file truncation and position handling in LittleFS operations for better compatibility across different RT-Thread versions and build configurations.

align non-DFS_V2 lseek parameter macros with DFS file operation prototypes
write back file positions and sizes using off_t and size_t respectively
add a compile-time DFS_V1 lseek signature check for RT-Thread 5.0.2+
document the GCC/newlib validation gap versus Keil/IAR type models
@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 441c0fab-7bdc-43de-9eb8-905fce3f4bfa

📥 Commits

Reviewing files that changed from the base of the PR and between beab78f and c441163.

📒 Files selected for processing (1)
  • dfs_lfs.c

Walkthrough

The PR replaces rt_off_t with POSIX off_t in the DFS_LFS_LSEEK_PARAMS and DFS_LFS_STORE_FILE_POS seek ABI macros across all four conditional build branches in dfs_lfs.c, and similarly updates the post-truncation metadata casts in the RT_FIOFTRUNCATE ioctl path.

Changes

rt_off_t → off_t type correction in seek ABI and truncate ioctl

Layer / File(s) Summary
Seek ABI macros across all build variants
dfs_lfs.c
DFS_LFS_LSEEK_PARAMS offset type and DFS_LFS_STORE_FILE_POS cast changed from rt_off_t to off_t in all four conditional branches: RT 5.0.2+ non-DFS-v2 (line 88–91), DFS v1 split (line 117–120), RT 5.0.0 transition (line 145–148), and RT 4.x legacy (line 173–176).
RT_FIOFTRUNCATE ioctl metadata casts
dfs_lfs.c
Post-truncate metadata in the DFS v2 RT_FIOFTRUNCATE path updated to assign DFS_LFS_FILE_POS via (off_t)pos and DFS_LFS_FILE_SIZE via (size_t)pos, replacing the prior rt_off_t-based position cast.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • RT-Thread-packages/littlefs#30: Modifies _dfs_lfs_lseek directory offset↔pos conversions in dfs_lfs.c, overlapping with the lseek ABI and file position bookkeeping changed here.
  • RT-Thread-packages/littlefs#31: Also modifies the DFS v2 RT_FIOFTRUNCATE path's post-truncation file position/size metadata, including switching casts to off_t/size_t.

Suggested reviewers

  • Rbb666
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: aligning lseek callback signature with off_t type in littlefs DFS module.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Rbb666 Rbb666 merged commit bf5beae into RT-Thread-packages:master Jun 22, 2026
10 checks passed
@wdfk-prog wdfk-prog deleted the fix_off_t branch June 23, 2026 00:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants