diff --git a/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/dosfiles.c b/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/dosfiles.c index 6cef5e76e62..30644b56ab6 100644 --- a/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/dosfiles.c +++ b/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/dosfiles.c @@ -23,6 +23,45 @@ #include "bios/bios.h" +/* PRIVATE FUNCTIONS **********************************************************/ + +static VOID StoreNameInSft(LPCSTR FilePath, PDOS_FILE_DESCRIPTOR Descriptor) +{ + CHAR ShortPath[MAX_PATH]; + PCHAR Name; + PCHAR Extension; + + /* Try to get the short path */ + if (!GetShortPathNameA(FilePath, ShortPath, sizeof(ShortPath))) + { + /* If it failed, just use the uppercase long path */ + strncpy(ShortPath, FilePath, sizeof(ShortPath) - 1); + _strupr(ShortPath); + } + + /* Get the name part */ + Name = strrchr(ShortPath, '\\'); + if (Name == NULL) Name = ShortPath; + + /* Find the extension */ + Extension = strchr(Name, '.'); + + if (Extension) + { + /* Terminate the name string, and move the pointer to after the dot */ + *Extension++ = 0; + } + + /* Copy the name into the SFT descriptor */ + RtlCopyMemory(Descriptor->FileName, Name, min(strlen(Name), 8)); + + if (Extension) + { + /* Copy the extension too */ + RtlCopyMemory(&Descriptor->FileName[8], Extension, min(strlen(Extension), 3)); + } +} + /* PUBLIC FUNCTIONS ***********************************************************/ BYTE DosFindFreeDescriptor(VOID) @@ -365,21 +404,25 @@ WORD DosCreateFileEx(LPWORD Handle, /* Set up the new descriptor */ Descriptor = DosGetFileDescriptor(DescriptorId); RtlZeroMemory(Descriptor, sizeof(*Descriptor)); + RtlFillMemory(Descriptor->FileName, sizeof(Descriptor->FileName), ' '); if (Node != NULL) { Descriptor->DevicePointer = Node->Driver; Descriptor->DeviceInfo = Node->DeviceAttributes | FILE_INFO_DEVICE; + RtlCopyMemory(Descriptor->FileName, Node->Name.Buffer, Node->Name.Length); } else { Descriptor->OpenMode = AccessShareModes; Descriptor->Attributes = LOBYTE(GetFileAttributesA(FilePath)); Descriptor->Size = GetFileSize(FileHandle, NULL); - Descriptor->OwnerPsp = Sda->CurrentPsp; Descriptor->Win32Handle = FileHandle; + StoreNameInSft(FilePath, Descriptor); } + Descriptor->OwnerPsp = Sda->CurrentPsp; + /* Open the DOS handle */ DosHandle = DosOpenHandle(DescriptorId); if (DosHandle == INVALID_DOS_HANDLE) @@ -441,20 +484,24 @@ WORD DosCreateFile(LPWORD Handle, /* Set up the new descriptor */ Descriptor = DosGetFileDescriptor(DescriptorId); RtlZeroMemory(Descriptor, sizeof(*Descriptor)); + RtlFillMemory(Descriptor->FileName, sizeof(Descriptor->FileName), ' '); if (Node != NULL) { Descriptor->DevicePointer = Node->Driver; Descriptor->DeviceInfo = Node->DeviceAttributes | FILE_INFO_DEVICE; + RtlCopyMemory(Descriptor->FileName, Node->Name.Buffer, Node->Name.Length); } else { Descriptor->Attributes = LOBYTE(GetFileAttributesA(FilePath)); Descriptor->Size = GetFileSize(FileHandle, NULL); - Descriptor->OwnerPsp = Sda->CurrentPsp; Descriptor->Win32Handle = FileHandle; + StoreNameInSft(FilePath, Descriptor); } + Descriptor->OwnerPsp = Sda->CurrentPsp; + /* Open the DOS handle */ DosHandle = DosOpenHandle(DescriptorId); if (DosHandle == INVALID_DOS_HANDLE) @@ -589,21 +636,25 @@ WORD DosOpenFile(LPWORD Handle, /* Set up the new descriptor */ Descriptor = DosGetFileDescriptor(DescriptorId); RtlZeroMemory(Descriptor, sizeof(*Descriptor)); + RtlFillMemory(Descriptor->FileName, sizeof(Descriptor->FileName), ' '); if (Node != NULL) { Descriptor->DevicePointer = Node->Driver; Descriptor->DeviceInfo = Node->DeviceAttributes | FILE_INFO_DEVICE; + RtlCopyMemory(Descriptor->FileName, Node->Name.Buffer, Node->Name.Length); } else { Descriptor->OpenMode = AccessShareModes; Descriptor->Attributes = LOBYTE(GetFileAttributesA(FilePath)); Descriptor->Size = GetFileSize(FileHandle, NULL); - Descriptor->OwnerPsp = Sda->CurrentPsp; Descriptor->Win32Handle = FileHandle; + StoreNameInSft(FilePath, Descriptor); } + Descriptor->OwnerPsp = Sda->CurrentPsp; + /* Open the DOS handle */ DosHandle = DosOpenHandle(DescriptorId); if (DosHandle == INVALID_DOS_HANDLE) diff --git a/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/dosfiles.h b/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/dosfiles.h index da0a2422ad4..3cc7a935805 100644 --- a/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/dosfiles.h +++ b/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/dosfiles.h @@ -26,7 +26,8 @@ typedef struct _DOS_FILE_DESCRIPTOR DWORD Reserved; WORD OwnerPsp; HANDLE Win32Handle; - BYTE Padding[0x1E - sizeof(HANDLE)]; + CHAR FileName[11]; + BYTE Padding[0x13 - sizeof(HANDLE)]; } DOS_FILE_DESCRIPTOR, *PDOS_FILE_DESCRIPTOR; C_ASSERT(sizeof(DOS_FILE_DESCRIPTOR) == 0x3B); diff --git a/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/handle.c b/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/handle.c index 4798b25eea2..2e3ce8e7108 100644 --- a/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/handle.c +++ b/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/handle.c @@ -105,6 +105,8 @@ VOID DosCopyHandleTable(LPBYTE DestinationTable) Descriptor->DeviceInfo = Node->DeviceAttributes | FILE_INFO_DEVICE; Descriptor->DevicePointer = SysVars->ActiveCon; + RtlFillMemory(Descriptor->FileName, sizeof(Descriptor->FileName), ' '); + RtlCopyMemory(Descriptor->FileName, Node->Name.Buffer, Node->Name.Length); /* Call the open routine */ if (Node->OpenRoutine) Node->OpenRoutine(Node);