[NTVDM] Allow opening files with write access on CDROM
authorPierre Schweitzer <pierre@reactos.org>
Sat, 20 Oct 2018 10:53:52 +0000 (12:53 +0200)
committerPierre Schweitzer <pierre@reactos.org>
Sat, 20 Oct 2018 15:27:53 +0000 (17:27 +0200)
Some applications, run on a CDROM, may attempt to open
a file with write access. CDFS driver will deny such
request in ReactOS (but also in Windows NT). Then, to
restore that behavior from old Windows (9X), our ntvdm,
as Microsoft ntvdm will attempt to reopen the file only
with read access, if opening failed because of denied access
and if the file is on a CDROM.

CORE-15211

subsystems/mvdm/ntvdm/dos/dos32krnl/dos.c

index d5b01ce..641ab62 100644 (file)
@@ -161,6 +161,21 @@ static BOOLEAN DosChangeDirectory(LPSTR Directory)
     return TRUE;
 }
 
     return TRUE;
 }
 
+static BOOLEAN DosIsFileOnCdRom(VOID)
+{
+    UINT DriveType;
+    CHAR RootPathName[4];
+
+    /* Construct a simple <letter>:\ string to get drive type */
+    RootPathName[0] = Sda->CurrentDrive + 'A';
+    RootPathName[1] = ':';
+    RootPathName[2] = '\\';
+    RootPathName[3] = ANSI_NULL;
+
+    DriveType = GetDriveTypeA(RootPathName);
+    return (DriveType == DRIVE_CDROM);
+}
+
 /* PUBLIC FUNCTIONS ***********************************************************/
 
 BOOLEAN DosControlBreak(VOID)
 /* PUBLIC FUNCTIONS ***********************************************************/
 
 BOOLEAN DosControlBreak(VOID)
@@ -950,8 +965,19 @@ VOID WINAPI DosInt21h(LPWORD Stack)
         case 0x3D:
         {
             WORD FileHandle;
         case 0x3D:
         {
             WORD FileHandle;
+            BYTE AccessShareModes = getAL();
             LPCSTR FileName = (LPCSTR)SEG_OFF_TO_PTR(getDS(), getDX());
             LPCSTR FileName = (LPCSTR)SEG_OFF_TO_PTR(getDS(), getDX());
-            WORD ErrorCode = DosOpenFile(&FileHandle, FileName, getAL());
+            WORD ErrorCode = DosOpenFile(&FileHandle, FileName, AccessShareModes);
+
+            /*
+             * Check if we failed because we attempted to open a file for write
+             * on a CDROM drive. In that situation, attempt to reopen for read
+             */
+            if (ErrorCode == ERROR_ACCESS_DENIED &&
+                (AccessShareModes & 0x03) != 0 && DosIsFileOnCdRom())
+            {
+                ErrorCode = DosOpenFile(&FileHandle, FileName, 0);
+            }
 
             if (ErrorCode == ERROR_SUCCESS)
             {
 
             if (ErrorCode == ERROR_SUCCESS)
             {