Skip to content

fix(vfs):修复 sys_mknodat 路径解析与 mode 处理,并修复 fatfs中mknod 相关死锁#1346

Merged
fslongjin merged 8 commits intoDragonOS-Community:masterfrom
kaleidoscope416:fix_sys_mknod
Nov 6, 2025
Merged

fix(vfs):修复 sys_mknodat 路径解析与 mode 处理,并修复 fatfs中mknod 相关死锁#1346
fslongjin merged 8 commits intoDragonOS-Community:masterfrom
kaleidoscope416:fix_sys_mknod

Conversation

@kaleidoscope416
Copy link
Contributor

@kaleidoscope416 kaleidoscope416 commented Nov 6, 2025

  • 处理空路径与 dirfd:当传入的路径名解析后为 "" 且给定的 dirfd 不是 AT_FDCWD 时,返回 ENOENT,避免把空字符串当成有效名在指定目录上进行创建
  • mode==0 视为常规文件:将 mode 位为 0 的情况当作 S_IFREG 处理,保持与用户态期望一致
  • 修正 AT_FDCWD 父目录查找逻辑:在解析父路径并查找父目录时正确处理 AT_FDCWD,避免错误地基于 AT_FDCWD 进行不当的父目录解析
  • 修复 mknod 相关死锁:修复fatfs中mknod获取锁后调用create再次获取锁所引发的死锁

Note

Fixes sys_mknodat path resolution and mode=0 handling, updates FAT mknod locking to avoid deadlock, and enables mknod tests with targeted blocklists.

  • VFS/sys_mknodat:
    • Properly resolve dirfd-relative paths via user_path_at, split with rsplit_path, and follow symlinks up to VFS_MAX_FOLLOW_SYMLINK_TIMES.
    • Treat mode == 0 as S_IFREG; validate modes via ModeType::from_bits.
    • Return ENOENT when name is empty and dirfd != AT_FDCWD.
    • Invoke mknod on the resolved parent inode instead of fd-table direct dir checks.
  • FAT filesystem (fs.rs):
    • Avoid self-deadlock in mknod by dropping the directory lock before calling create; re-lock only when creating special nodes.
    • Create FIFO special nodes with SpecialNodeData::Pipe and cache in children.
  • Tests:
    • Add mknod_test to gVisor whitelist; blocklist specific cases (RegularFilePermissions, MknodOnExistingPathFails, Socket).

Written by Cursor Bugbot for commit 7c255dc. This will update automatically on new commits. Configure here.

Copilot AI review requested due to automatic review settings November 6, 2025 09:18
@github-actions github-actions bot added the Bug fix A bug is fixed in this pull request label Nov 6, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enables and implements support for the mknod_test in the gvisor syscall test suite. The key changes refactor the sys_mknodat syscall implementation to use proper path resolution utilities and fix a lock scope issue in the FAT filesystem's mknod implementation.

  • Refactored sys_mknodat to use user_path_at and rsplit_path utilities for consistent path handling
  • Fixed lock scope in FAT filesystem mknod to prevent holding the lock during file creation
  • Added mknod_test to whitelist with a blocklist for unimplemented features

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
user/apps/tests/syscall/gvisor/whitelist.txt Enables mknod_test in the test suite
user/apps/tests/syscall/gvisor/blocklists/mknod_test Documents test cases blocked due to unimplemented features (umask, symlink, socket)
kernel/src/filesystem/vfs/syscall/sys_mknodat.rs Refactors path resolution to use standard utilities and fixes mode handling
kernel/src/filesystem/fat/fs.rs Fixes lock scope to avoid holding lock during create operation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

MknodTest.RegularFilePermissions
# symlink未实现
MknodTest.MknodOnExistingPathFails
# sys_socket对应功能为实现
Copy link

Copilot AI Nov 6, 2025

Choose a reason for hiding this comment

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

Corrected spelling of '为实现' to '未实现' (missing negation character).

Suggested change
# sys_socket对应功能为实现
# sys_socket对应功能未实现

Copilot uses AI. Check for mistakes.
kaleidoscope416 and others added 3 commits November 6, 2025 17:32
- 重构FAT文件系统目录检查逻辑,提前释放锁
- 改进mknod系统调用中空路径名检查方式
- 修正测试文件中的注释拼写错误

Signed-off-by: longjin <longjin@DragonOS.org>
@fslongjin fslongjin merged commit 71f867f into DragonOS-Community:master Nov 6, 2025
14 checks passed
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

This PR is being reviewed by Cursor Bugbot

Details

You are on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

file.inode().mknod(&path, mode, dev)?;
if name.is_empty() && dirfd != AtFlags::AT_FDCWD.bits() {
return Err(SystemError::ENOENT);
}
Copy link

Choose a reason for hiding this comment

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

Bug: Empty Path Handling in dirfd AT_FDCWD Bug

When dirfd equals AT_FDCWD and path is an empty string, the code fails to return ENOENT. Instead, after user_path_at prepends the current working directory (e.g., "/home/user/"), rsplit_path extracts the last component ("user") as the filename and parent path ("home"). This causes mknod to incorrectly attempt creating a node in an unintended location. The condition should check for empty path regardless of dirfd value, or verify that the original path (not just the final name component) was non-empty.

Fix in Cursor Fix in Web

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug fix A bug is fixed in this pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants