From: Toni Wilen Date: Fri, 6 Mar 2026 16:21:43 +0000 (+0200) Subject: Check host file/directory state in action_lock X-Git-Url: https://git.unchartedbackwaters.co.uk/w/?a=commitdiff_plain;h=85af3bf38fa316cfeb60c4c7720d8b6559fccc66;p=francis%2Fwinuae.git Check host file/directory state in action_lock --- diff --git a/filesys.cpp b/filesys.cpp index d5b1a2a7..4ebb8be4 100644 --- a/filesys.cpp +++ b/filesys.cpp @@ -3603,6 +3603,20 @@ static Key *new_key (Unit *unit) return k; } +static bool filedir_exists(Unit *unit, a_inode *aino) +{ + struct mystat statbuf; + bool ok = true; + if (unit->volflags & MYVOLUMEINFO_ARCHIVE) + ok = zfile_stat_archive(aino->nname, &statbuf) != 0; + else if (unit->volflags & MYVOLUMEINFO_CDFS) + ok = isofs_stat(unit->ui.cdfs_superblock, aino->uniq_external, &statbuf); + else { + ok = my_existsfiledir(aino->nname); + } + return ok; +} + #if TRACING_ENABLED static void dumplock(TrapContext *ctx, Unit *unit, uaecptr lock) { @@ -3896,12 +3910,19 @@ static void action_lock(TrapContext *ctx, Unit *unit, dpacket *packet) if (err == 0 && (a->elock || (mode != SHARED_LOCK && a->shlock > 0))) { err = ERROR_OBJECT_IN_USE; } + if (err == 0) { + if (!filedir_exists(unit, a)) { + delete_aino(unit, a); + err = ERROR_OBJECT_NOT_AROUND; + } + } /* Lock() doesn't do access checks. */ if (err != 0) { PUT_PCK_RES1 (packet, DOS_FALSE); PUT_PCK_RES2 (packet, err); return; } + if (mode == SHARED_LOCK) a->shlock++; else diff --git a/include/fsdb.h b/include/fsdb.h index a5a037ca..59cf42a7 100644 --- a/include/fsdb.h +++ b/include/fsdb.h @@ -185,6 +185,7 @@ extern bool my_issamepath(const TCHAR *path1, const TCHAR *path2); extern bool my_createsoftlink(const TCHAR *path, const TCHAR *target); extern bool my_createshortcut(const TCHAR *source, const TCHAR *target, const TCHAR *description); extern void makesafefilename(TCHAR*, bool); +extern bool my_existsfiledir(const TCHAR *name); extern a_inode *custom_fsdb_lookup_aino_aname (a_inode *base, const TCHAR *aname); extern a_inode *custom_fsdb_lookup_aino_nname (a_inode *base, const TCHAR *nname); diff --git a/od-win32/fsdb_mywin32.cpp b/od-win32/fsdb_mywin32.cpp index f62f7504..4836161a 100644 --- a/od-win32/fsdb_mywin32.cpp +++ b/od-win32/fsdb_mywin32.cpp @@ -331,6 +331,18 @@ DWORD GetFileAttributesSafe (const TCHAR *name) return attr; } +bool my_existsfiledir(const TCHAR *name) +{ + DWORD attr = GetFileAttributesSafe(name); + if (attr != INVALID_FILE_ATTRIBUTES) + return true; + DWORD err = GetLastError(); + if (err == ERROR_FILE_NOT_FOUND || err == ERROR_PATH_NOT_FOUND) { + return false; + } + return true; +} + int my_existsfile (const TCHAR *name) { DWORD attr;