Skip to content

Conversation

@ryanbreen
Copy link
Owner

@ryanbreen ryanbreen commented Jan 13, 2026

Summary

  • Add per-process current working directory (cwd) tracking with full POSIX-compliant getcwd and chdir syscalls
  • Enable shell navigation with cd and pwd commands
  • Fix ls to list current directory by default instead of root

Changes

Kernel

  • Add cwd field to Process struct (initialized to "/")
  • Implement sys_getcwd (syscall 79) - returns cwd in user buffer with POSIX pointer return
  • Implement sys_chdir (syscall 80) - validates path exists and is directory
  • Add relative path resolution to sys_open using process cwd
  • Fork inherits cwd from parent process
  • Handle devfs paths correctly (ENOTDIR for device files)

Shell

  • Add cd and pwd built-in commands to init_shell
  • Update ls_cmd to default to "." (cwd) instead of "/" (root)

Tests

  • New cwd_test.rs with 7 comprehensive tests
  • 8 new boot stages for CWD validation
  • Test coverage: initial cwd, chdir success, ENOENT, ENOTDIR, relative paths, fork inheritance, getcwd error handling

Test plan

  • All 210 boot stages pass
  • Interactive shell cd /test && ls works correctly
  • pwd shows correct directory after cd
  • Error handling validated (ENOENT, ENOTDIR, EINVAL, ERANGE)

🤖 Generated with Claude Code


Note

Introduces filesystem navigation capabilities and wires them through kernel, libc, shell, and tests.

  • Kernel: add Process.cwd, implement sys_getcwd (79) and sys_chdir (80), wire in dispatcher/handler, add ERANGE, make sys_open resolve relative paths via cwd with normalize_path, and ensure fork inherits cwd in all fork paths
  • Userspace/lib: add process::getcwd and process::chdir wrappers; shell adds built-ins cd and pwd; ls_cmd defaults to "." when no path is given
  • Tests/build: new cwd_test binary with 7 checks (initial /, chdir success/ENOENT/ENOTDIR, relative .., fork inheritance, getcwd errors) and 8 new boot markers; kernel runs test_cwd; build script and Cargo wired
  • Docs: add docs/planning/SHELL_AND_APPS_ROADMAP.md outlining roadmap for shell and third‑party apps

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

Add per-process current working directory (cwd) tracking with full
POSIX-compliant getcwd and chdir syscalls:

Kernel changes:
- Add cwd field to Process struct (initialized to "/")
- Implement sys_getcwd (syscall 79) with EINVAL/ERANGE error handling
- Implement sys_chdir (syscall 80) with ENOENT/ENOTDIR validation
- Add relative path resolution to sys_open using cwd
- Fork inherits cwd from parent process
- Add get_current_cwd() and normalize_path() helpers

Shell enhancements:
- Add cd and pwd built-in commands to init_shell
- Update ls_cmd to default to "." (cwd) instead of "/" (root)

Test coverage:
- New cwd_test.rs with 7 tests covering all requirements
- 8 boot stages for CWD validation
- Tests verify: initial cwd, chdir, ENOENT, ENOTDIR, relative paths,
  fork inheritance, getcwd error handling, return value pointer

All 210 boot stages pass.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@ryanbreen ryanbreen merged commit 6635fd5 into main Jan 13, 2026
2 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 is the final PR Bugbot will review for you during this billing cycle

Your free Bugbot reviews will reset on February 12

Details

Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.

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

alloc::format!("{}/{}", cwd, raw_path)
};
normalize_path(&absolute)
};
Copy link

Choose a reason for hiding this comment

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

Empty path in sys_open resolves to cwd instead of ENOENT

Medium Severity

The new relative path handling in sys_open lacks a check for empty paths. When open("") is called, the empty string doesn't start with '/', so it enters the relative path resolution branch. This causes an empty path to resolve to the current working directory (e.g., "/test/" normalizes to "/test"), whereas POSIX requires open("") to fail with ENOENT. The sys_chdir function correctly handles this case with an explicit empty path check, but sys_open is missing the equivalent validation.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants