diff options
| author | Eero Tamminen <oak@helsinkinet.fi> | 2022-10-11 19:12:20 (GMT) |
|---|---|---|
| committer | Eero Tamminen <oak@helsinkinet.fi> | 2022-10-13 23:30:52 (GMT) |
| commit | 799020b84d0224a4bb38f2b892a8ecdd1c11bcc1 (patch) | |
| tree | cb4a09baebc5078701d7a9de16cbbc27a1e1c495 | |
| parent | 8dcc45f0a8c0c9e400eef4da05a67b6d19ff04b0 (diff) | |
| download | hatari-799020b84d0224a4bb38f2b.zip hatari-799020b84d0224a4bb38f2b.tar.gz | |
GEMDOS HD: allow writes to files opened as read-only
See: https://www.atari-forum.com/viewtopic.php?p=438987
| -rw-r--r-- | doc/release-notes.txt | 4 | ||||
| -rw-r--r-- | src/gemdos.c | 10 |
2 files changed, 11 insertions, 3 deletions
diff --git a/doc/release-notes.txt b/doc/release-notes.txt index eb87b40..9e69c9e 100644 --- a/doc/release-notes.txt +++ b/doc/release-notes.txt @@ -25,6 +25,10 @@ Emulator improvements: - The "--bpp" command line option and related code (i.e. the rendering functions for 16 bits-per-pixel host screens) have been removed since almost all recent hardware should support 32 bpp nowadays. +- GEMDOS HD: + - Similarly to TOS, allow programs to write to a file they have opened + as read-only (by opening all writable files as read/write). As this + could fail with real HW under MiNT/MagiC, show warning about it - Debugger: - Fix: free all debugger allocations before exit - Fix: invalid free on freeing loaded GNU debug symbols diff --git a/src/gemdos.c b/src/gemdos.c index 299b7e9..9be752a 100644 --- a/src/gemdos.c +++ b/src/gemdos.c @@ -133,6 +133,7 @@ static struct { typedef struct { bool bUsed; + bool bReadOnly; char szMode[4]; /* enough for all used fopen() modes: rb/rb+/wb+ */ uint32_t Basepage; FILE *FileHandle; @@ -2144,6 +2145,7 @@ static bool GemDOS_Open(uint32_t Params) FileHandles[Index].FileHandle = OverrideHandle; RealMode = "read-only"; ModeStr = "rb"; + Mode = 0; } else { @@ -2168,15 +2170,13 @@ static bool GemDOS_Open(uint32_t Params) * support write-only without truncating the file). * * Read-only status is used if: - * - requested by Atari program * - Hatari write protection is enabled * - File itself is read-only * Latter is done to help cases where application * needlessly requests write access, but file is * on read-only media (like CD/DVD). */ - if (Mode == 0 || - ConfigureParams.HardDisk.nWriteProtection == WRITEPROT_ON || + if (ConfigureParams.HardDisk.nWriteProtection == WRITEPROT_ON || (stat(szActualFileName, &FileStat) == 0 && !(FileStat.st_mode & S_IWUSR))) { ModeStr = "rb"; @@ -2194,6 +2194,7 @@ static bool GemDOS_Open(uint32_t Params) { /* Tag handle table entry as used in this process and return handle */ FileHandles[Index].bUsed = true; + FileHandles[Index].bReadOnly = (Mode == 0); strcpy(FileHandles[Index].szMode, ModeStr); FileHandles[Index].Basepage = STMemory_ReadLong(act_pd); snprintf(FileHandles[Index].szActualName, @@ -2436,6 +2437,9 @@ static bool GemDOS_Write(uint32_t Params) fflush(fp); Regs[REG_D0] = nBytesWritten; /* OK */ } + if (FileHandles[fh_idx].bReadOnly) + Log_Printf(LOG_WARN, "GEMDOS Fwrite() to a file opened as read-only: %s\n", + FileHandles[fh_idx].szActualName); return true; } |
