From 60dfe2068dec3df34963de0753c0c789660092f2 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Feb 2026 15:32:33 +0000 Subject: [PATCH] Implement mock_access() for simulation file existence checks mock_access() uses mockfs_open(RDONLY) to probe whether a path exists in the mock filesystem, then immediately closes the handle. Directories are detected via the MOCKFS_ERRNO_ISDIR return from mockfs_open. This prevents the simulation from falling back to file_open(O_CREAT), which would create empty files as a side effect and corrupt chunk data. https://claude.ai/code/session_01YJnNDYw8JVb4HPSMf9rpuS --- quakey/src/quakey.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/quakey/src/quakey.c b/quakey/src/quakey.c index 10906aa..b142336 100644 --- a/quakey/src/quakey.c +++ b/quakey/src/quakey.c @@ -3249,7 +3249,29 @@ int mock_close(int fd) // data for chunks they don't actually have). int mock_access(const char *path, int mode) { - assert(0); // TODO + (void) mode; // No permission bits in mockfs; all checks reduce to existence + + Host *host = host___; + if (host == NULL) + abort_("Call to mock_access() with no node scheduled\n"); + + if (!host_is_linux(host)) + abort_("Call to mock_access() not from Linux\n"); + + MockFS_OpenFile open_file; + int ret = mockfs_open(host->mfs, (char *) path, strlen(path), MOCKFS_O_RDONLY, &open_file); + if (ret == MOCKFS_ERRNO_ISDIR) { + // Path exists and is a directory + return 0; + } + if (ret < 0) { + *host_errno_ptr(host) = ENOENT; + return -1; + } + + // File exists; close it immediately + mockfs_close_file(&open_file); + return 0; } static int convert_addr(void *addr, size_t addr_len,