Implement
- userland build in nix, with cross platform support and
non-previleged disk gen
- qemu start command in nix
- nix develop envrionment for make kernel
- document build environment defined by nix
Next Steps
- 减小rootfs占用nix store的体积
- deb包的打包兼容用的函数
- 更加灵活的构建依赖注入
- 保留先前系统内修改的内容
- nix rootfs build与qemu启动适配 vnc模式
- 适配 riscv64 构建
- Arm MacOS上的开发兼容
* feat(filesystem): Enhance symlink handling and VFS behavior
- Updated tmpfs to require page cache for both regular files and symlinks to ensure proper read/write operations.
- Increased the maximum symlink follow count to 40, aligning with Linux 6.6 standards.
- Improved symlink handling in VFS to correctly follow symlinks based on path conditions and trailing slashes.
- Added validation for conflicting flags in vfs_statx to prevent invalid operations.
- Refined syscall implementations for symlink and lstat to adhere to Linux semantics, ensuring correct behavior for symlink creation and path resolution.
Signed-off-by: longjin <longjin@DragonOS.org>
* fix(vfs): 修正符号链接跟随次数的处理逻辑
- 将 VFS_MAX_FOLLOW_SYMLINK_TIMES 从 40 调整为 41,以保留 0 的禁用语义并实现最多
40 次跟随的 Linux 语义
- 重构路径解析逻辑,明确区分 max_follow_times 为
0(完全禁用跟随)、1(计数耗尽)及 >=2(允许继续跟随)三种情况
- 确保在计数耗尽(max_follow_times == 1)且需要跟随时正确返回 ELOOP 错误
Signed-off-by: longjin <longjin@DragonOS.org>
---------
Signed-off-by: longjin <longjin@DragonOS.org>
- Set default umask to 0022 for new filesystem instances
- Add apply_umask_for_create() and chmod_preserve_type() helper functions
- Implement proper permission checks for file creation and chmod operations
- Fix fchmod syscall to work correctly and reject O_PATH file descriptors
- Add open_create_test to gvisor test suite
Signed-off-by: longjin <longjin@DragonOS.org>
* feat(filesystem): Implement EventFd filesystem and enhance VFS inode capabilities
- Introduced EventFdFs as a new pseudo-filesystem to support eventfd file descriptors, including methods for root inode retrieval and filesystem information.
- Enhanced IndexNode trait with is_stream, supports_seek, supports_pread, and supports_pwrite methods to streamline file operation semantics for stream-like files.
- Updated file handling in VFS to utilize new inode capabilities, ensuring correct behavior for pread, pwrite, and lseek operations.
- Added eventfd_test to the syscall whitelist for testing purposes.
This implementation aligns with Linux semantics for eventfd and improves the overall VFS design by consolidating stream behavior checks.
Signed-off-by: longjin <longjin@DragonOS.org>
* fix(vfs): 修复pread/pwrite中O_PATH和流式对象的错误处理顺序
- 调整O_PATH文件描述符的错误处理顺序,确保优先返回EBADF
- 为流式对象(FMODE_STREAM)添加ESPIPE错误处理,避免权限检查导致的误报
- 分离权限检查逻辑,确保错误码符合Linux语义
Signed-off-by: longjin <longjin@DragonOS.org>
---------
Signed-off-by: longjin <longjin@DragonOS.org>
* feat(vfs): Implement append lock manager for file operations
- Introduced an `AppendLockManager` to ensure atomicity for append operations across filesystems, preventing data corruption in concurrent write scenarios.
- Updated file write methods to utilize the new append lock mechanism, ensuring that appending to files respects the latest end-of-file position.
- Enhanced `write_append` and `pwrite_append` methods to support forced append semantics, aligning with Linux behavior.
- Initialized the append lock manager during VFS initialization to ensure it is ready before any file write operations.
This addition improves the reliability of file operations in a multi-threaded environment, particularly for append scenarios.
Signed-off-by: longjin <longjin@DragonOS.org>
* feat(kernel): 添加jhash库并用于append_lock的哈希计算
Signed-off-by: longjin <longjin@DragonOS.org>
---------
Signed-off-by: longjin <longjin@DragonOS.org>
* feat(procfs): Add /proc/[pid]/mountinfo and /proc/[pid]/maps support
- Introduced new ProcFileType variants for /proc/[pid]/mountinfo and /proc/[pid]/maps.
- Implemented content generation for /proc/[pid]/mountinfo and /proc/[pid]/maps to align with Linux semantics.
- Updated ProcFS inode creation to include these new files for each process.
- Enhanced path handling in the VFS to ensure correct resolution based on process-specific root and current working directory.
This addition improves the process filesystem's functionality and compatibility with Linux behavior.
* feat(filesystem): Enhance page cache management in tmpfs
- Added an unevictable flag to the PageCache structure, allowing pages to be marked as unevictable to prevent reclamation.
- Updated the TmpfsInode structure to integrate page cache management, replacing direct data manipulation with page cache operations for read and write methods.
- Refactored truncate and resize methods to utilize the new page cache functionality, ensuring consistency and improved memory management.
* feat(filesystem): Enhance tmpfs functionality and VFS constraints
- Implemented support for readahead in tmpfs, allowing for optimized data retrieval.
- Added checks for filename length across various VFS operations to prevent errors related to excessively long names.
- Updated the tmpfs implementation to handle read and write operations directly through the page cache, improving memory management.
- Enhanced rename functionality to ensure type compatibility and empty directory checks during operations.
- Increased maximum path length and defined maximum single filename length for better filesystem compliance.
* refactor(fs): 重构tmpfs重命名逻辑并修复MountFSInode的move_to委托
- 将tmpfs跨目录移动逻辑提取为独立函数`tmpfs_move_entry_between_dirs`
- 优化锁顺序以避免死锁,按inode_id顺序锁定目录
- 修复MountFSInode::move_to中目标inode解包问题,确保正确委托给底层文件系统
Signed-off-by: longjin <longjin@DragonOS.org>
* feat(filesystem): Implement zero-page creation for tmpfs and enhance page fault handling
- Added `create_zero_pages` method to `InnerPageCache` for efficient zero-page creation, optimizing memory usage in tmpfs.
- Updated `Tmpfs` to utilize the new zero-page creation during read and write operations, ensuring seamless handling of page faults.
- Enhanced `PageFaultHandler` with `pagecache_fault_zero` to manage page faults specifically for tmpfs, allowing for direct page cache access without disk I/O.
This improves the performance and reliability of memory file systems by reducing unnecessary allocations and ensuring proper page management.
* refactor(syscall): Rename check_and_clone_cstr to vfs_check_and_clone_cstr for clarity
- Updated the user access module to introduce vfs_check_and_clone_cstr, enhancing clarity in its purpose for VFS operations.
- Refactored sys_openat and utimensat to utilize the new vfs_check_and_clone_cstr function, ensuring consistent handling of C string paths across the filesystem.
---------
Signed-off-by: longjin <longjin@DragonOS.org>
* fix(net): udp getsockname/getpeername
* feat(ci): add test whitelist for new available inet syscall
---------
Co-authored-by: longjin <longjin@DragonOS.org>
* feat(filesystem): Add tmpfs support and integrate with devfs
- Introduced a new tmpfs module for temporary file storage in memory.
- Updated devfs to mount /dev/shm as tmpfs, aligning with Linux semantics.
- Enhanced vfs module to include TMPFS_MAGIC for tmpfs identification.
- Added necessary methods and structures for tmpfs functionality, including inode management and file operations.
Signed-off-by: longjin <longjin@DragonOS.org>
* feat(filesystem): Implement atomic size management for tmpfs
- Added atomic operations to manage the current size of the tmpfs filesystem, including methods to increase and decrease size based on file operations.
- Integrated size management into inode operations, ensuring that size updates are thread-safe and adhere to specified limits.
- Enhanced the resize and truncate methods to adjust the filesystem size accordingly during file modifications.
Signed-off-by: longjin <longjin@DragonOS.org>
---------
Signed-off-by: longjin <longjin@DragonOS.org>
* feat(filesystem): Add pwritev2 syscall implementation
- Introduced the pwritev2 syscall, allowing vectorized writes with offset and flags, enhancing compatibility with Linux semantics.
- Implemented validation for file descriptors and offsets, ensuring robust error handling.
- Reused core logic from pwritev for the new syscall, maintaining consistency in file writing operations.
This addition improves the VFS layer's functionality and aligns with Linux behavior for vectorized writing operations.
Signed-off-by: longjin <longjin@DragonOS.org>
* fmt
---------
Signed-off-by: longjin <longjin@DragonOS.org>
- Added validation for pwrite and pwritev syscalls to ensure offset and length conform to Linux semantics, returning EINVAL for negative offsets and invalid ranges.
- Updated offset extraction in sys_pwrite64 and sys_pwritev to use i64 for better compatibility.
- Included a new test case for pwrite64 in the gvisor whitelist to ensure proper functionality.
This change improves the robustness of file writing operations in the VFS layer.
Signed-off-by: longjin <longjin@DragonOS.org>
* refactor(mm): 重构页缓存读写以解决死锁问题并改进错误处理
- 将页缓存读写拆分为两阶段以避免用户缺页时持有锁
- 改进文件系统缺页处理,返回SIGBUS而非panic
- 优化sys_read/sys_write的用户缓冲区访问检查
- 修复mprotect参数对齐检查
Signed-off-by: longjin <longjin@DragonOS.org>
* feat(devfs): 添加随机设备支持
- 新增随机设备模块random_dev,提供随机字节生成能力
- 在DevFS中注册/dev/random设备,确保系统能够访问随机数据
- 更新相关文件以支持新设备的集成
Signed-off-by: longjin <longjin@DragonOS.org>
* feat(filesystem): 添加mmap支持到多个文件系统节点
- 为LockedZeroInode、LockedExt4Inode、LockedFATInode和LockedRamFSInode实现mmap方法,允许内存映射操作。
- 更新相关文件以支持mmap功能,确保与用户空间的交互更加灵活。
Signed-off-by: longjin <longjin@DragonOS.org>
* fix(mm): Improve mmap error handling and validation
- Enhanced error handling in mmap implementation to return appropriate errors for unsupported operations.
- Added checks for MAP_PRIVATE and MAP_SHARED flags to ensure only one is set.
- Implemented page alignment validation for MAP_FIXED.
- Updated tests to reflect changes in mmap behavior.
Signed-off-by: longjin <longjin@DragonOS.org>
* fix(mm): Enhance memory protection handling and validation
- Updated the `init_xd_rsvd` function to ensure NX support is enabled and correctly handle hardware limitations.
- Improved alignment checks in `sys_mprotect` to prevent overflow and ensure proper memory area verification.
- Removed outdated tests from `mmap_test` to streamline the test suite.
Signed-off-by: longjin <longjin@DragonOS.org>
* feat(procfs): Add support for /proc/[pid]/statm file
- Introduced the ProcStatm file type to the ProcFileType enum.
- Implemented the open_statm function to return a placeholder response for the statm file.
- Updated the ProcFS inode creation to include the statm file for each process.
- Enhanced the IndexNode implementation to handle the new ProcStatm file type.
Signed-off-by: longjin <longjin@DragonOS.org>
* fix(mmap): 增强mmap系统调用的偏移量检查和内存分配逻辑
* fix(procfs): 优化statm文件打开逻辑,增加虚拟内存页数计算
* fix(syscall): 处理len为0的情况,确保read和write系统调用遵循POSIX标准
* refactor(mm): Optimize page reclamation process to prevent deadlocks
- Separated the page reclamation into two phases to avoid holding the reclaimer lock for extended periods, reducing the risk of lock order inversion with page_manager/page_cache.
- Updated the `shrink_list` method to handle victim page eviction without holding the reclaimer lock, ensuring safer memory management.
- Improved the `drain_lru` method to efficiently retrieve victim pages for reclamation.
Signed-off-by: longjin <longjin@DragonOS.org>
---------
Signed-off-by: longjin <longjin@DragonOS.org>
- Adjusted the link count for directories to ensure it starts at 2, accounting for the self-reference and parent directory link.
- Updated the logic for incrementing and decrementing link counts when creating and deleting directories.
- Enhanced the dynamic calculation of directory link counts in the VFS layer to ensure accuracy when metadata is unreliable.
This change improves the consistency of link count management across different filesystem implementations.
Signed-off-by: longjin <longjin@DragonOS.org>