From 393853050866da5ab40a274c9799ff42e39fd165 Mon Sep 17 00:00:00 2001 From: Daniel Hammer Date: Fri, 17 Jul 2026 10:10:31 +0200 Subject: [PATCH] fix: ramdisk ReadDir reports nonexistent paths as errors ReadDirAt returned 0 (empty listing) for paths that do not exist at all, so the libc's stat()/access() - which probe directory-ness via SYS_READDIR - reported every nonexistent path as an existing directory. Harmless for two years of callers, fatal for GCC's driver: it access()-tests the optional specs file, got a false positive for 0:/sdk/lib/gcc/x86_64-montauk/14.2.0/specs, then died failing to read it. A path now has to have a directory entry or at least one child to list as a directory; everything else returns -1. Real empty directories (tar dir entries, runtime Mkdir) still list as empty. Co-Authored-By: Claude Fable 5 --- kernel/src/Api/BuildNo.hpp | 2 +- kernel/src/Fs/Ramdisk.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/kernel/src/Api/BuildNo.hpp b/kernel/src/Api/BuildNo.hpp index 8d0afdc..4a8b1ef 100644 --- a/kernel/src/Api/BuildNo.hpp +++ b/kernel/src/Api/BuildNo.hpp @@ -12,4 +12,4 @@ #pragma once -#define MONTAUK_BUILD_NUMBER 19 +#define MONTAUK_BUILD_NUMBER 20 diff --git a/kernel/src/Fs/Ramdisk.cpp b/kernel/src/Fs/Ramdisk.cpp index 2af8b67..2b15fd0 100644 --- a/kernel/src/Fs/Ramdisk.cpp +++ b/kernel/src/Fs/Ramdisk.cpp @@ -280,6 +280,14 @@ namespace Fs::Ramdisk { outNames[count++] = entryName; } + // A path with no directory entry and no children does not exist. + // Without this, ReadDir on a nonexistent path returned 0 (empty), + // which userspace stat()/access() misread as "directory exists" - + // fatal for GCC's driver, which access()-tests optional spec files. + if (count == 0 && seen == 0 && pathLen > 0 && selfIdx < 0) { + return -1; + } + return count; }