Skip to content

Conversation

@wdcui
Copy link
Member

@wdcui wdcui commented Feb 1, 2026

Summary

This PR adds support for the symlink(2) and symlinkat(2) Linux syscalls.

Changes

Syscall Parsing (litebox_common_linux)

  • Added Symlinkat variant to SyscallRequest enum
  • Added syscall number parsing for Sysno::symlink and Sysno::symlinkat
  • Added From<SymlinkError> and From<ReadlinkError> for Errno conversions

Filesystem Layer (litebox/src/fs)

  • Added SymlinkError and ReadlinkError error types in errors.rs
  • Added FileType::SymbolicLink variant to FileType enum
  • Added symlink() and readlink() methods to FileSystem trait
  • Implemented in all filesystems:
    • in_mem.rs: Full implementation with Entry::Symlink and SymlinkX types
    • layered.rs: Delegates to upper/lower layers appropriately
    • tar_ro.rs: Returns ReadOnlyFileSystem for symlink, simplified readlink
    • devices.rs: Returns error (devices don't support symlinks)

Syscall Handler (litebox_shim_linux)

  • Added sys_symlink() and sys_symlinkat() methods to Task
  • Updated do_readlink() to check filesystem for symlinks
  • Added SyscallRequest::Symlinkat dispatch case in main handler

Testing

  • Added 7 unit tests for symlink functionality
  • All 182 local tests pass

Design Notes

Following POSIX/Linux semantics, symlink targets do NOT need to exist at creation time. The target path is validated only when the symlink is followed, not when it's created.

This commit adds support for the symlink(2) and symlinkat(2) Linux syscalls.

Changes:
- Add SymlinkError and ReadlinkError types to fs/errors.rs
- Add FileType::SymbolicLink variant
- Add symlink() and readlink() methods to FileSystem trait with full documentation
- Implement symlink support in in_mem, layered, tar_ro, devices filesystems
- Add sys_symlink and sys_symlinkat syscall handlers
- Update do_readlink to check filesystem for symlinks
- Add 7 unit tests for symlink functionality
- Add #[non_exhaustive] to TruncateError for API consistency

Error handling improvements:
- Empty linkpath/pathname returns ENOENT (matches Linux)
- Target path >= PATH_MAX returns ENAMETOOLONG
- Empty target returns ENOENT

The implementation follows POSIX/Linux semantics where symlink targets
do not need to exist at creation time.
@wdcui wdcui force-pushed the wdcui/symlink-syscall branch from adc01fb to 0c0ba4d Compare February 1, 2026 23:39
@github-actions
Copy link

github-actions bot commented Feb 1, 2026

🤖 SemverChecks 🤖 ⚠️ Potential breaking API changes detected ⚠️

Click for details
--- failure enum_marked_non_exhaustive: enum marked #[non_exhaustive] ---

Description:
A public enum has been marked #[non_exhaustive]. Pattern-matching on it outside of its crate must now include a wildcard pattern like `_`, or it will fail to compile.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#attr-adding-non-exhaustive
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.46.0/src/lints/enum_marked_non_exhaustive.ron

Failed in:
  enum TruncateError in /home/runner/work/litebox/litebox/litebox/src/fs/errors.rs:78

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