feat(vfs): implement fallocate syscall#1668
feat(vfs): implement fallocate syscall#1668fslongjin merged 14 commits intoDragonOS-Community:masterfrom
Conversation
实现 fallocate 系统调用 (syscall 285),用于为文件分配磁盘空间。 - 新增 sys_fallocate.rs 系统调用处理 - 支持 mode=0 的默认分配操作,通过 vfs_truncate 扩展文件 - 暂不支持 FALLOC_FL_KEEP_SIZE、FALLOC_FL_PUNCH_HOLE 等标志位
代码审查发现 4 个问题:
🤖 Generated with Claude Code - If this code review was useful, please react with 👍. Otherwise, react with 👎. |
代码审查 (更新)发现 1 个问题:
当前实现无条件地将文件截断到 ,但 Linux fallocate(mode=0) 应该只在 大于当前文件大小时才扩展文件,不应该缩小文件。缩小文件应该通过 ftruncate() 完成。 例如:如果文件当前大小为 1000 字节,调用 会错误地将文件截断到 500 字节,导致数据丢失。 DragonOS/kernel/src/filesystem/vfs/syscall/sys_fallocate.rs Lines 76 to 84 in 9827a98 🤖 Generated with Claude Code - If this code review was useful, please react with 👍. Otherwise, react with 👎. |
代码审查 (更新)发现 1 个问题:
当前实现无条件地将文件截断到 offset + len,但 Linux fallocate(mode=0) 应该只在 offset+len 大于当前文件大小时才扩展文件,不应该缩小文件。缩小文件应该通过 ftruncate() 完成。 例如:如果文件当前大小为 1000 字节,调用 fallocate(fd, 0, 0, 500) 会错误地将文件截断到 500 字节,导致数据丢失。 DragonOS/kernel/src/filesystem/vfs/syscall/sys_fallocate.rs Lines 76 to 84 in 9827a98 🤖 Generated with Claude Code - If this code review was useful, please react with 👍. Otherwise, react with 👎. |
According to Linux fallocate(2) semantics, mode=0 should only
extend the file size when offset+len exceeds the current file
size. It should never shrink the file.
|
@claude review |
|
Claude finished @fslongjin's task in 4m 40s —— View job Comprehensive Code ReviewI've reviewed the ✅ Issues Already Fixed
|
- 修正文档中的错误码描述(EOPNOTSUPP → EOPNOTSUPP_OR_ENOTSUP) - 修复溢出处理:使用 checked_add 替代 saturating_add,溢出时正确返回 EINVAL - 添加文件类型检查,只支持普通文件,与 ftruncate 行为保持一致
|
@claude review |
|
Claude finished @fslongjin's task in 5m 53s —— View job Comprehensive Code ReviewI've reviewed the ✅ Issues Already Fixed (from previous reviews)
|
- 添加nix对c_unitest的构建,会直接打包存放在bin下面
实现 fallocate 系统调用 (syscall 285),用于为文件分配磁盘空间。