feat: Implement fchdir syscall #622
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds support for the
fchdir(2)syscall, which changes the current working directory to the directory referred to by a file descriptor.Changes
litebox_common_linux
Fchdir { fd: i32 }variant toSyscallRequestenumSysno::fchdirsyscall parsinglitebox_shim_linux
DirectoryPathmetadata type for storing directory pathscwdfield toFsStatefor per-process CWD trackingcompute_absolute_path()helper methodsys_open()to store directory paths as entry metadatasys_getcwd()to return actual CWD from FsState (was returning hardcoded "/")sys_fchdir()to change CWD based on directory fdFchdirindo_syscallError Handling
The implementation correctly handles:
EBADF: Invalid or negative file descriptorENOTDIR: File descriptor refers to a non-directory (regular file, socket, pipe, etc.)Tests Added
test_fchdir_basic: Basic fchdir functionalitytest_fchdir_ebadf: Invalid fd handling (returns EBADF)test_fchdir_enotdir: Non-directory fd handling (returns ENOTDIR)test_fchdir_to_root: Changing back to root directoryTesting
All existing tests pass. New tests verify the basic functionality and error handling.