Skip to content

feat(dfs_lfs): Add RT_FIOFTRUNCATE functionality#31

Merged
Rbb666 merged 1 commit intoRT-Thread-packages:masterfrom
wdfk-prog:RT_FIOFTRUNCATE
Jan 26, 2026
Merged

feat(dfs_lfs): Add RT_FIOFTRUNCATE functionality#31
Rbb666 merged 1 commit intoRT-Thread-packages:masterfrom
wdfk-prog:RT_FIOFTRUNCATE

Conversation

@wdfk-prog
Copy link
Collaborator

@wdfk-prog wdfk-prog commented Jan 26, 2026

Summary by CodeRabbit

  • New Features
    • Added file truncation support allowing files to be resized to specified lengths. Includes input validation, protection against truncating directories, and automatic updates to file metadata and position tracking. Operations on read-only configurations are blocked and return appropriate error responses.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 26, 2026

Walkthrough

Adds an RT_FIOFTRUNCATE IOCTL case in dfs_lfs.c that validates input, rejects directory targets, delegates truncation to the LFS layer via lfs_file_truncate, updates in-memory file position and vnode size, and maps/returns appropriate DFS error codes (returns -EROFS when built read-only).

Changes

Cohort / File(s) Summary
File truncation IOCTL handler
dfs_lfs.c
Adds handling for RT_FIOFTRUNCATE: input validation (null/invalid), directory rejection, call to lfs_file_truncate, in-memory updates (file position and vnode size), and read-only mode (-EROFS) / error mapping.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • Rbb666
🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(dfs_lfs): Add RT_FIOFTRUNCATE functionality' directly and clearly describes the main change: adding support for the RT_FIOFTRUNCATE IOCTL command to the dfs_lfs module.

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

✨ Finishing touches
  • 📝 Generate docstrings

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.

@wdfk-prog
Copy link
Collaborator Author

@Rbb666

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@dfs_lfs.c`:
- Around line 744-753: The code casts length (off_t) directly to lfs_off_t when
calling lfs_file_truncate (using dfs_lfs_fd->lfs and dfs_lfs_fd->u.file), which
can wrap on platforms where off_t is wider than lfs_off_t; before calling
lfs_file_truncate, validate that length is within the lfs_off_t range
(non-negative and <= the maximum representable value for lfs_off_t, e.g.
(lfs_off_t)UINT32_MAX or an LFS-provided max) and return -EINVAL if out of
range, then perform the cast only after the check.
- Around line 731-752: The handler currently calls lfs_file_truncate without
checking the open mode; add an access-control check on the incoming file before
calling lfs_file_truncate: inspect file->flags (the same flags used when the
descriptor was opened) to ensure the descriptor was opened for writing (e.g.,
O_WRONLY or O_RDWR / RT_FOPEN_FLAG_WRONLY/RT_FOPEN_FLAG_RDWR), and if not return
an appropriate error (e.g., -EACCES or -EBADF) instead of calling
lfs_file_truncate on dfs_lfs_fd_t->u.file.

@Rbb666 Rbb666 merged commit 194556b into RT-Thread-packages:master Jan 26, 2026
2 of 19 checks passed
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