Author: hbelusca
Date: Fri May 15 23:13:40 2015
New Revision: 67750
URL:
http://svn.reactos.org/svn/reactos?rev=67750&view=rev
Log:
[NTVDM]
- Simplify CurrentDirectories array usage.
- We can directly use a pointer to a DOS_DATA structure stored in the guest memory.
- Use the DOS data structures for CurrentDrive (in DOS_DATA) and LastDrive (this is in
fact NumLocalDrives in the SYSVARS list).
- Use ANSI versions of GetLocaleInfo where applicable.
Modified:
trunk/reactos/subsystems/mvdm/ntvdm/dos/dem.c
trunk/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/bios.c
trunk/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/device.c
trunk/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/dos.c
trunk/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/dos.h
Modified: trunk/reactos/subsystems/mvdm/ntvdm/dos/dem.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/mvdm/ntvdm/dos/…
==============================================================================
--- trunk/reactos/subsystems/mvdm/ntvdm/dos/dem.c [iso-8859-1] (original)
+++ trunk/reactos/subsystems/mvdm/ntvdm/dos/dem.c [iso-8859-1] Fri May 15 23:13:40 2015
@@ -28,7 +28,7 @@
/* PRIVATE VARIABLES **********************************************************/
-/**/extern BYTE CurrentDrive;/**/
+extern PDOS_DATA DosData;
/* PRIVATE FUNCTIONS **********************************************************/
@@ -575,7 +575,7 @@
}
/* Fill the block */
- FindFileBlock->DriveLetter = CurrentDrive + 'A';
+ FindFileBlock->DriveLetter = DosData->Sda.CurrentDrive + 'A';
FindFileBlock->AttribMask = AttribMask;
FindFileBlock->SearchHandle = SearchHandle;
FindFileBlock->Attributes = LOBYTE(FindData.dwFileAttributes);
Modified: trunk/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/bios.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/mvdm/ntvdm/dos/…
==============================================================================
--- trunk/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/bios.c [iso-8859-1] (original)
+++ trunk/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/bios.c [iso-8859-1] Fri May 15
23:13:40 2015
@@ -74,7 +74,7 @@
PDOS_DEVICE_NODE Node = DosGetDriverNode(Descriptor->DevicePointer);
if (!Node->InputStatusRoutine) return FALSE;
-
+
Result = Node->InputStatusRoutine(Node);
return !(Result & DOS_DEVSTAT_BUSY);
}
@@ -199,7 +199,7 @@
}
/* Set the drive */
- CurrentDrive = DosDirectory[0] - 'A';
+ Sda->CurrentDrive = DosDirectory[0] - 'A';
/* Get the directory part of the path */
Path = strchr(DosDirectory, '\\');
@@ -212,7 +212,7 @@
/* Set the directory */
if (Path != NULL)
{
- strncpy(CurrentDirectories[CurrentDrive], Path, DOS_DIR_LENGTH);
+ strncpy(CurrentDirectories[Sda->CurrentDrive], Path, DOS_DIR_LENGTH);
}
/* Read CONFIG.SYS */
Modified: trunk/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/device.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/mvdm/ntvdm/dos/…
==============================================================================
--- trunk/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/device.c [iso-8859-1] (original)
+++ trunk/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/device.c [iso-8859-1] Fri May 15
23:13:40 2015
@@ -239,7 +239,7 @@
static VOID DosRemoveDriver(DWORD Driver)
{
- DWORD CurrentDriver = MAKELONG(FIELD_OFFSET(DOS_SYSVARS, NullDevice),
DOS_DATA_SEGMENT);
+ DWORD CurrentDriver = MAKELONG(DOS_DATA_OFFSET(SysVars.NullDevice),
DOS_DATA_SEGMENT);
while (LOWORD(CurrentDriver) != 0xFFFF)
{
@@ -325,7 +325,7 @@
PDOS_DEVICE_NODE DosGetDevice(LPCSTR DeviceName)
{
- DWORD CurrentDriver = MAKELONG(FIELD_OFFSET(DOS_SYSVARS, NullDevice),
DOS_DATA_SEGMENT);
+ DWORD CurrentDriver = MAKELONG(DOS_DATA_OFFSET(SysVars.NullDevice),
DOS_DATA_SEGMENT);
ANSI_STRING DeviceNameString;
RtlInitAnsiString(&DeviceNameString, DeviceName);
Modified: trunk/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/dos.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/mvdm/ntvdm/dos/…
==============================================================================
--- trunk/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/dos.c [iso-8859-1] (original)
+++ trunk/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/dos.c [iso-8859-1] Fri May 15
23:13:40 2015
@@ -36,12 +36,11 @@
CALLBACK16 DosContext;
-/*static*/ BYTE CurrentDrive = 0x00;
-static CHAR LastDrive = 'Z'; // The last drive can be redefined with the
LASTDRIVE command. At the moment, set the real maximum possible, 'Z'.
-static PCHAR CurrentDirectories;
-
/* PUBLIC VARIABLES ***********************************************************/
+/* Global DOS data area contained in guest memory */
+PDOS_DATA DosData;
+/* Easy accessors to useful DOS data area parts */
PDOS_SYSVARS SysVars;
PDOS_SDA Sda;
@@ -55,7 +54,7 @@
CHAR DirectoryPath[DOS_CMDLINE_LENGTH + 1];
/* Make sure the drive exists */
- if (Drive > (LastDrive - 'A')) return FALSE;
+ if (Drive >= SysVars->NumLocalDrives) return FALSE;
RtlZeroMemory(DirectoryPath, sizeof(DirectoryPath));
@@ -63,14 +62,14 @@
snprintf(DirectoryPath,
DOS_CMDLINE_LENGTH,
"%c:\\%s",
- Drive + 'A',
- &CurrentDirectories[Drive * DOS_DIR_LENGTH]);
+ 'A' + Drive,
+ DosData->CurrentDirectories[Drive]);
/* Change the current directory of the process */
if (!SetCurrentDirectoryA(DirectoryPath)) return FALSE;
/* Set the current drive */
- CurrentDrive = Drive;
+ Sda->CurrentDrive = Drive;
/* Return success */
return TRUE;
@@ -98,7 +97,7 @@
DriveNumber = RtlUpperChar(Directory[0]) - 'A';
/* Make sure the drive exists */
- if (DriveNumber > (LastDrive - 'A'))
+ if (DriveNumber >= SysVars->NumLocalDrives)
{
Sda->LastErrorCode = ERROR_PATH_NOT_FOUND;
return FALSE;
@@ -107,7 +106,7 @@
else
{
/* Keep the current drive number */
- DriveNumber = CurrentDrive;
+ DriveNumber = Sda->CurrentDrive;
}
/* Get the file attributes */
@@ -122,7 +121,7 @@
}
/* Check if this is the current drive */
- if (DriveNumber == CurrentDrive)
+ if (DriveNumber == Sda->CurrentDrive)
{
/* Change the directory */
if (!SetCurrentDirectoryA(Directory))
@@ -131,7 +130,7 @@
return FALSE;
}
}
-
+
/* Get the (possibly new) current directory (needed if we specified a relative
directory) */
if (!GetCurrentDirectoryA(sizeof(CurrentDirectory), CurrentDirectory))
{
@@ -157,11 +156,11 @@
/* Set the directory for the drive */
if (Path != NULL)
{
- strncpy(&CurrentDirectories[DriveNumber * DOS_DIR_LENGTH], Path,
DOS_DIR_LENGTH);
+ strncpy(DosData->CurrentDirectories[DriveNumber], Path, DOS_DIR_LENGTH);
}
else
{
- CurrentDirectories[DriveNumber * DOS_DIR_LENGTH] = '\0';
+ DosData->CurrentDirectories[DriveNumber][0] = '\0';
}
/* Return success */
@@ -198,8 +197,6 @@
SYSTEMTIME SystemTime;
PCHAR String;
PDOS_INPUT_BUFFER InputBuffer;
- PDOS_COUNTRY_CODE_BUFFER CountryCodeBuffer;
- INT Return;
Sda->InDos++;
@@ -487,7 +484,7 @@
case 0x0E:
{
DosChangeDrive(getDL());
- setAL(LastDrive - 'A' + 1);
+ setAL(SysVars->NumLocalDrives);
break;
}
@@ -510,7 +507,7 @@
/* Get Default Drive */
case 0x19:
{
- setAL(CurrentDrive);
+ setAL(Sda->CurrentDrive);
break;
}
@@ -582,8 +579,8 @@
PCHAR FileName = (PCHAR)SEG_OFF_TO_PTR(getDS(), getSI());
PDOS_FCB Fcb = (PDOS_FCB)SEG_OFF_TO_PTR(getES(), getDI());
BYTE Options = getAL();
- INT i;
CHAR FillChar = ' ';
+ UINT i;
if (FileName[1] == ':')
{
@@ -596,7 +593,7 @@
else
{
/* No drive number specified */
- if (Options & (1 << 1)) Fcb->DriveNumber = CurrentDrive +
1;
+ if (Options & (1 << 1)) Fcb->DriveNumber =
Sda->CurrentDrive + 1;
else Fcb->DriveNumber = 0;
}
@@ -811,13 +808,13 @@
/* Get Free Disk Space */
case 0x36:
{
- CHAR RootPath[3] = "?:\\";
+ CHAR RootPath[] = "?:\\";
DWORD SectorsPerCluster;
DWORD BytesPerSector;
DWORD NumberOfFreeClusters;
DWORD TotalNumberOfClusters;
- if (getDL() == 0) RootPath[0] = 'A' + CurrentDrive;
+ if (getDL() == 0x00) RootPath[0] = 'A' + Sda->CurrentDrive;
else RootPath[0] = 'A' + getDL() - 1;
if (GetDiskFreeSpaceA(RootPath,
@@ -898,14 +895,16 @@
/* Get/Set Country-dependent Information */
case 0x38:
{
- CountryCodeBuffer = (PDOS_COUNTRY_CODE_BUFFER)SEG_OFF_TO_PTR(getDS(),
getDX());
+ INT Return;
+ PDOS_COUNTRY_CODE_BUFFER CountryCodeBuffer =
+ (PDOS_COUNTRY_CODE_BUFFER)SEG_OFF_TO_PTR(getDS(), getDX());
if (getAL() == 0x00)
{
/* Get */
- Return = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_IDATE,
- &CountryCodeBuffer->TimeFormat,
- sizeof(CountryCodeBuffer->TimeFormat) /
sizeof(TCHAR));
+ Return = GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_IDATE,
+ &CountryCodeBuffer->TimeFormat,
+ sizeof(CountryCodeBuffer->TimeFormat));
if (Return == 0)
{
Stack[STACK_FLAGS] |= EMULATOR_FLAG_CF;
@@ -913,9 +912,9 @@
break;
}
- Return = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SCURRENCY,
- &CountryCodeBuffer->CurrencySymbol,
- sizeof(CountryCodeBuffer->CurrencySymbol) /
sizeof(TCHAR));
+ Return = GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_SCURRENCY,
+ &CountryCodeBuffer->CurrencySymbol,
+ sizeof(CountryCodeBuffer->CurrencySymbol));
if (Return == 0)
{
Stack[STACK_FLAGS] |= EMULATOR_FLAG_CF;
@@ -923,9 +922,9 @@
break;
}
- Return = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_STHOUSAND,
- &CountryCodeBuffer->ThousandSep,
- sizeof(CountryCodeBuffer->ThousandSep) /
sizeof(TCHAR));
+ Return = GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_STHOUSAND,
+ &CountryCodeBuffer->ThousandSep,
+ sizeof(CountryCodeBuffer->ThousandSep));
if (Return == 0)
{
Stack[STACK_FLAGS] |= EMULATOR_FLAG_CF;
@@ -933,9 +932,9 @@
break;
}
- Return = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL,
- &CountryCodeBuffer->DecimalSep,
- sizeof(CountryCodeBuffer->DecimalSep) /
sizeof(TCHAR));
+ Return = GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL,
+ &CountryCodeBuffer->DecimalSep,
+ sizeof(CountryCodeBuffer->DecimalSep));
if (Return == 0)
{
Stack[STACK_FLAGS] |= EMULATOR_FLAG_CF;
@@ -1278,7 +1277,7 @@
/* Get the real drive number */
if (DriveNumber == 0)
{
- DriveNumber = CurrentDrive;
+ DriveNumber = Sda->CurrentDrive;
}
else
{
@@ -1286,13 +1285,13 @@
DriveNumber--;
}
- if (DriveNumber <= LastDrive - 'A')
+ if (DriveNumber < SysVars->NumLocalDrives)
{
/*
* Copy the current directory into the target buffer.
* It doesn't contain the drive letter and the backslash.
*/
- strncpy(String, &CurrentDirectories[DriveNumber * DOS_DIR_LENGTH],
DOS_DIR_LENGTH);
+ strncpy(String, DosData->CurrentDirectories[DriveNumber],
DOS_DIR_LENGTH);
Stack[STACK_FLAGS] &= ~EMULATOR_FLAG_CF;
setAX(0x0100); // Undocumented, see Ralf Brown:
http://www.ctyme.com/intr/rb-2933.htm
}
@@ -1499,7 +1498,7 @@
/* Return the DOS "list of lists" in ES:BX */
setES(DOS_DATA_SEGMENT);
- setBX(FIELD_OFFSET(DOS_SYSVARS, FirstDpb));
+ setBX(DOS_DATA_OFFSET(SysVars.FirstDpb));
break;
}
@@ -1933,7 +1932,7 @@
break;
}
-
+
default:
{
DPRINT1("DOS Internal System Function INT 0x2F, AH = %xh, AL = %xh NOT
IMPLEMENTED!\n",
@@ -1969,62 +1968,19 @@
FILE *Stream;
WCHAR Buffer[256];
- /* Get a pointer to the current directory buffer */
- CurrentDirectories = (PCHAR)SEG_OFF_TO_PTR(DOS_DATA_SEGMENT,
- DOS_DATA_OFFSET(CurrentDirectories));
-
- /* Clear the current directory buffer */
- RtlZeroMemory(CurrentDirectories, NUM_DRIVES * DOS_DIR_LENGTH * sizeof(CHAR));
-
- /* Get the current directory */
- if (!GetCurrentDirectoryA(sizeof(CurrentDirectory), CurrentDirectory))
- {
- // TODO: Use some kind of default path?
- return FALSE;
- }
-
- /* Convert it to a DOS path */
- if (!GetShortPathNameA(CurrentDirectory, DosDirectory, sizeof(DosDirectory)))
- {
- // TODO: Use some kind of default path?
- return FALSE;
- }
-
- /* Set the drive */
- CurrentDrive = RtlUpperChar(DosDirectory[0]) - 'A';
-
- /* Get the directory part of the path */
- Path = strchr(DosDirectory, '\\');
- if (Path != NULL)
- {
- /* Skip the backslash */
- Path++;
- }
-
- /* Set the directory */
- if (Path != NULL)
- {
- strncpy(&CurrentDirectories[CurrentDrive * DOS_DIR_LENGTH], Path,
DOS_DIR_LENGTH);
- }
-
- /* Read CONFIG.SYS */
- Stream = _wfopen(DOS_CONFIG_PATH, L"r");
- if (Stream != NULL)
- {
- while (fgetws(Buffer, 256, Stream))
- {
- // TODO: Parse the line
- }
- fclose(Stream);
- }
+ /* Initialize the global DOS data area */
+ DosData = (PDOS_DATA)SEG_OFF_TO_PTR(DOS_DATA_SEGMENT, 0x0000);
+ RtlZeroMemory(DosData, sizeof(*DosData));
/* Initialize the list of lists */
- SysVars = (PDOS_SYSVARS)SEG_OFF_TO_PTR(DOS_DATA_SEGMENT, DOS_DATA_OFFSET(SysVars));
- RtlZeroMemory(SysVars, sizeof(DOS_SYSVARS));
+ SysVars = &DosData->SysVars;
+ RtlZeroMemory(SysVars, sizeof(*SysVars));
SysVars->FirstMcb = FIRST_MCB_SEGMENT;
SysVars->FirstSft = MAKELONG(DOS_DATA_OFFSET(Sft), DOS_DATA_SEGMENT);
SysVars->CurrentDirs = MAKELONG(DOS_DATA_OFFSET(CurrentDirectories),
DOS_DATA_SEGMENT);
+ /* The last drive can be redefined with the LASTDRIVE command. At the moment, set the
real maximum possible, 'Z'. */
+ SysVars->NumLocalDrives = 'Z' - 'A' + 1;
/* Initialize the NUL device driver */
SysVars->NullDevice.Link = 0xFFFFFFFF;
@@ -2040,8 +1996,39 @@
sizeof(NullDriverRoutine));
/* Initialize the swappable data area */
- Sda = (PDOS_SDA)SEG_OFF_TO_PTR(DOS_DATA_SEGMENT, DOS_DATA_OFFSET(Sda));
- RtlZeroMemory(Sda, sizeof(DOS_SDA));
+ Sda = &DosData->Sda;
+ RtlZeroMemory(Sda, sizeof(*Sda));
+
+ /* Get the current directory */
+ if (!GetCurrentDirectoryA(sizeof(CurrentDirectory), CurrentDirectory))
+ {
+ // TODO: Use some kind of default path?
+ return FALSE;
+ }
+
+ /* Convert it to a DOS path */
+ if (!GetShortPathNameA(CurrentDirectory, DosDirectory, sizeof(DosDirectory)))
+ {
+ // TODO: Use some kind of default path?
+ return FALSE;
+ }
+
+ /* Set the drive */
+ Sda->CurrentDrive = RtlUpperChar(DosDirectory[0]) - 'A';
+
+ /* Get the directory part of the path */
+ Path = strchr(DosDirectory, '\\');
+ if (Path != NULL)
+ {
+ /* Skip the backslash */
+ Path++;
+ }
+
+ /* Set the directory */
+ if (Path != NULL)
+ {
+ strncpy(DosData->CurrentDirectories[Sda->CurrentDrive], Path,
DOS_DIR_LENGTH);
+ }
/* Set the current PSP to the system PSP */
Sda->CurrentPsp = SYSTEM_PSP;
@@ -2058,6 +2045,17 @@
{
/* Clear the file descriptor entry */
RtlZeroMemory(&Sft->FileDescriptors[i], sizeof(DOS_FILE_DESCRIPTOR));
+ }
+
+ /* Read CONFIG.SYS */
+ Stream = _wfopen(DOS_CONFIG_PATH, L"r");
+ if (Stream != NULL)
+ {
+ while (fgetws(Buffer, 256, Stream))
+ {
+ // TODO: Parse the line
+ }
+ fclose(Stream);
}
#endif
Modified: trunk/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/dos.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/mvdm/ntvdm/dos/…
==============================================================================
--- trunk/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/dos.h [iso-8859-1] (original)
+++ trunk/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/dos.h [iso-8859-1] Fri May 15
23:13:40 2015
@@ -88,7 +88,7 @@
DWORD CurrentDirs;
BYTE Reserved1[6];
BYTE NumBlockDevices;
- BYTE NumLocalDrives;
+ BYTE NumLocalDrives; // Set by LASTDRIVE
DOS_DRIVER NullDevice;
BYTE NullDriverRoutine[7];
} DOS_SYSVARS, *PDOS_SYSVARS;
@@ -233,12 +233,11 @@
DWORD PrevCallFrame;
} DOS_SDA, *PDOS_SDA;
-/* This structure is only used for DOS_DATA_OFFSET calculations */
typedef struct _DOS_DATA
{
DOS_SYSVARS SysVars;
DOS_SDA Sda;
- CHAR CurrentDirectories[NUM_DRIVES * DOS_DIR_LENGTH];
+ CHAR CurrentDirectories[NUM_DRIVES][DOS_DIR_LENGTH];
BYTE Sft[ANYSIZE_ARRAY];
} DOS_DATA, *PDOS_DATA;