Re: [hatari-devel] Fwrite warnings

[ Thread Index | Date Index | More lists.tuxfamily.org/hatari-devel Archives ]


Hi Uwe,

On 27.10.2022 0.39, Eero Tamminen wrote:
On 26.10.2022 15.16, Uwe Seimet wrote:
with the latest sources I get tons of warnings when, for instance, I compile
with Pure C. I have never seen these warnings before.

WARN : GEMDOS Fwrite() to 'ROOT.O' file, opened as read-only

This is from following commit:
https://git.tuxfamily.org/hatari/hatari.git/commit/?id=799020b84d0224a4bb38f2b892a8ecdd1c11bcc1


Is this a bug or can these warnings be switched off? There are so many of
them that it's hard to see the actually relevant messages.
 >
 > I just noticed that I also get these warnings
 > for files definitely opened for writing, i.e.
 > opened with fopen(FILENAME, "w") with Pure C.

Can you provide GEMDOS trace around that warning?

Only case where I can see this happening:
* Fwrite() done for a FD from Fcreate(), not Fopen(), and
* That FD number being reused from an earlier, already Fclose()d, read-only Fopen() call


Attached patch should fix that.  Does it help?


	- Eero
diff --git a/src/gemdos.c b/src/gemdos.c
index 1c3e4010..5067ac54 100644
--- a/src/gemdos.c
+++ b/src/gemdos.c
@@ -896,6 +896,8 @@ static void restore_file_handle_info(int i, FILE_HANDLE *handle)
 		fclose(fp);
 		return;
 	}
+	/* used only for warnings, ignore those after restore */
+	handle->bReadOnly = false;
 	handle->FileHandle = fp;
 }
 
@@ -2021,8 +2023,11 @@ static bool GemDOS_Create(uint32_t Params)
 		 * - GEMDOS_FILE_ATTRIB_WRITECLOSE   (FA_ARCHIVE)
 		 *   (set automatically by GemDOS >= 0.15)
 		 */
+		FileHandles[Index].bReadOnly = false;
 		if (Mode & GEMDOS_FILE_ATTRIB_READONLY)
 		{
+			/* enable write warnings */
+			FileHandles[Index].bReadOnly = true;
 			/* after closing, file should be read-only */
 			if (chmod(szActualFileName, S_IRUSR|S_IRGRP|S_IROTH))
 			{
@@ -3883,8 +3888,9 @@ void GemDOS_Info(FILE *fp, uint32_t bShowOpcodes)
 	{
 		if (!FileHandles[i].bUsed)
 			continue;
-		fprintf(fp, "- %d (0x%x): %s\n", i + BASE_FILEHANDLE,
-			FileHandles[i].Basepage, FileHandles[i].szActualName);
+		fprintf(fp, "- %d (0x%x): %s (%s)\n", i + BASE_FILEHANDLE,
+			FileHandles[i].Basepage, FileHandles[i].szActualName,
+			FileHandles[i].bReadOnly ? "ro" : "rw");
 		used++;
 	}
 	if (!used)


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/