Skip to content

VFS: proper .. (parent directory) tracking #239

@sysheap

Description

@sysheap

Currently the VFS layer does not track parent directories. .. is silently skipped in walk_with_depth() and resolve_path_nofollow() falls back to resolve_path() when encountering ... This means:

  • cd /tmp/foo/.. resolves to /tmp/foo instead of /tmp
  • stat("/tmp/..") returns the stat of /tmp instead of /
  • Paths like /a/b/../c resolve to /a/b/c instead of /a/c

Proposed approach

Track the parent node during path resolution. Options:

  1. Walk-time parent stack: Maintain a stack of parent nodes during walk_with_depth(). When encountering .., pop the stack. This is the simplest approach and doesn't require storing parent refs on nodes.

  2. Per-node parent ref: Store a Weak<dyn VfsNode> parent reference on each TmpfsDir/TmpfsFile. Set on creation. More complex but enables getcwd() to walk up the tree.

Option 1 is likely sufficient — Linux also resolves .. during path walk, not via stored parent pointers.

Files involved

  • kernel/src/fs/vfs.rswalk_with_depth(), resolve_path_nofollow(), resolve_parent()
  • kernel/src/syscalls/fs_ops.rsresolve_stat_node() dirfd-relative .. handling

Current workaround (commit 42eb6f6)

.. is skipped in walk_with_depth and treated as . in resolve_path_nofollow / resolve_stat_node. This unblocks ls -alh but is semantically incorrect for programs that rely on .. for navigation.


Created by Claude Code

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions