Skip to content

Bug: ls /tmp shows mount points (/dev, /proc, /tmp) instead of its contents #417

Description

@pbalduino

Bug Description

When running ls /tmp, the output incorrectly shows mount points (/dev, /proc, and /tmp itself) instead of the actual contents of the /tmp directory.

Expected Behavior

ls /tmp should show the files and directories contained within /tmp, not the global filesystem mount points.

Actual Behavior

$ ls /tmp
/dev
/proc
/tmp

The listing shows mount points that belong at the root level, not the contents of /tmp.

Root Cause

The issue is in the VFS layer's vfs_list() function. The "mountpoint injection" step runs for any filesystem root (when relative == "/"), not just the global root.

When you list /tmp:

  1. The code resolves to the tmpfs root (which is / relative to that filesystem)
  2. The mount iteration loop replays every mount including the one being listed
  3. Result: /tmp shows all mount points instead of its own contents

Technical Analysis

The mountpoint injection logic in vfs_list() should:

  • Only append mount points when listing the global root (/)
  • Skip mount points when listing subdirectory roots of mounted filesystems

Current behavior:

// Simplified pseudocode
if (relative == "/") {
    // This runs for ANY filesystem root, not just global root!
    for (mount in all_mounts) {
        append_mount_to_results(mount);
    }
}

Proposed Fix

Tighten the mountpoint injection logic with one of these approaches:

Option 1: Check if path is global root

// Only inject mounts when listing the actual global root
if (strcmp(resolved_path, "/") == 0 && relative == "/") {
    for (mount in all_mounts) {
        append_mount_to_results(mount);
    }
}

Option 2: Skip current mount

if (relative == "/") {
    for (mount in all_mounts) {
        // Skip the mount we're currently listing
        if (strcmp(mount->path, current_listing_path) == 0) {
            continue;
        }
        append_mount_to_results(mount);
    }
}

Impact

  • Severity: Medium - breaks basic filesystem navigation expectations
  • User Experience: Confusing for users expecting standard Unix behavior
  • Workaround: None - incorrect behavior on every tmpfs listing
  • Affected: All mounted filesystems when listing their root directories

Files Affected

  • src/kernel/fs/vfs/vfs.c - vfs_list() function
  • Mountpoint injection logic

Reproduction

# This should show /tmp contents but shows mount points instead
$ ls /tmp

# Compare with expected behavior:
$ ls /        # Should show mount points (correct)
$ ls /proc    # Should show proc contents, not mount points (currently broken)
$ ls /dev     # Should show dev contents, not mount points (currently broken)

Testing Requirements

After fix:

  • ls / shows mount points: /dev, /proc, /tmp, etc. ✓
  • ls /tmp shows tmpfs contents only (no mount points)
  • ls /proc shows procfs contents only (no mount points)
  • ls /dev shows devfs contents only (no mount points)
  • Nested mounts work correctly

Priority

Medium - Functional bug affecting filesystem navigation, but workaround exists (use full paths or navigate into subdirectories).

Related Issues

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingkernelKernel-level implementation

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions