]> git.unchartedbackwaters.co.uk Git - francis/winuae.git/commitdiff
Check host file/directory state in action_lock
authorToni Wilen <twilen@winuae.net>
Fri, 6 Mar 2026 16:21:43 +0000 (18:21 +0200)
committerToni Wilen <twilen@winuae.net>
Fri, 6 Mar 2026 16:21:43 +0000 (18:21 +0200)
filesys.cpp
include/fsdb.h
od-win32/fsdb_mywin32.cpp

index d5b1a2a7b3ee19de56985dede57d75477e8ac310..4ebb8be45657be2ee45bd2016c1939199e1d9e5a 100644 (file)
@@ -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
index a5a037cace2786e667d196cdf5e5b94768ce3feb..59cf42a77286f18676835b99862a6fa76134eff7 100644 (file)
@@ -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);
index f62f75042cbef087ed0b87e7e31fa059d1b3ed71..4836161a26ea41f3bbac9f5d22a28d24ce7046d6 100644 (file)
@@ -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;