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
This commit is contained in:
+23
-1
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user