mirror of
https://github.com/reactos/reactos.git
synced 2025-02-22 08:25:03 +00:00
[NTVDM]
Add some utility functions (only file-oriented for now :) ). Will be used in the next commit. svn path=/branches/ntvdm/; revision=62341
This commit is contained in:
parent
ae22dab753
commit
7c73e239b0
3 changed files with 121 additions and 0 deletions
|
@ -26,6 +26,7 @@ list(APPEND SOURCE
|
|||
emulator.c
|
||||
io.c
|
||||
registers.c
|
||||
utils.c
|
||||
vddsup.c
|
||||
ntvdm.c
|
||||
ntvdm.rc
|
||||
|
|
87
subsystems/ntvdm/utils.c
Normal file
87
subsystems/ntvdm/utils.c
Normal file
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
* COPYRIGHT: GPL - See COPYING in the top level directory
|
||||
* PROJECT: ReactOS Virtual DOS Machine
|
||||
* FILE: utils.c
|
||||
* PURPOSE: Utility Functions
|
||||
* PROGRAMMERS: Hermes Belusca-Maito (hermes.belusca@sfr.fr)
|
||||
*/
|
||||
|
||||
/* INCLUDES *******************************************************************/
|
||||
|
||||
#define NDEBUG
|
||||
|
||||
#include "emulator.h"
|
||||
|
||||
/* PRIVATE FUNCTIONS **********************************************************/
|
||||
|
||||
/* PUBLIC FUNCTIONS ***********************************************************/
|
||||
|
||||
VOID
|
||||
FileClose(IN HANDLE FileHandle)
|
||||
{
|
||||
CloseHandle(FileHandle);
|
||||
}
|
||||
|
||||
HANDLE
|
||||
FileOpen(IN PCSTR FileName,
|
||||
OUT PULONG FileSize OPTIONAL)
|
||||
{
|
||||
HANDLE hFile;
|
||||
ULONG ulFileSize;
|
||||
|
||||
/* Open the file */
|
||||
SetLastError(0); // For debugging purposes
|
||||
hFile = CreateFileA(FileName,
|
||||
GENERIC_READ,
|
||||
FILE_SHARE_READ,
|
||||
NULL,
|
||||
OPEN_EXISTING,
|
||||
FILE_ATTRIBUTE_NORMAL,
|
||||
NULL);
|
||||
DPRINT1("File '%s' opening %s ; GetLastError() = %u\n",
|
||||
FileName, hFile != INVALID_HANDLE_VALUE ? "succeeded" : "failed", GetLastError());
|
||||
|
||||
/* If we failed, bail out */
|
||||
if (hFile == INVALID_HANDLE_VALUE) return NULL;
|
||||
|
||||
/* OK, we have a handle to the file */
|
||||
|
||||
/*
|
||||
* Retrieve the size of the file. In NTVDM we will handle files
|
||||
* of maximum 1Mb so we can largely use GetFileSize only.
|
||||
*/
|
||||
ulFileSize = GetFileSize(hFile, NULL);
|
||||
if (ulFileSize == INVALID_FILE_SIZE && GetLastError() != ERROR_SUCCESS)
|
||||
{
|
||||
/* We failed, bail out */
|
||||
DPRINT1("Error when retrieving file size, or size too large (%d)\n", ulFileSize);
|
||||
FileClose(hFile);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Success, return file handle and size if needed */
|
||||
if (FileSize) *FileSize = ulFileSize;
|
||||
return hFile;
|
||||
}
|
||||
|
||||
BOOLEAN
|
||||
FileLoadByHandle(IN HANDLE FileHandle,
|
||||
IN PVOID Location,
|
||||
IN ULONG FileSize,
|
||||
OUT PULONG BytesRead)
|
||||
{
|
||||
BOOLEAN Success;
|
||||
|
||||
/* Attempt to load the file into memory */
|
||||
SetLastError(0); // For debugging purposes
|
||||
Success = !!ReadFile(FileHandle,
|
||||
Location, // REAL_TO_PHYS(LocationRealPtr),
|
||||
FileSize,
|
||||
BytesRead,
|
||||
NULL);
|
||||
DPRINT1("File loading %s ; GetLastError() = %u\n", Success ? "succeeded" : "failed", GetLastError());
|
||||
|
||||
return Success;
|
||||
}
|
||||
|
||||
/* EOF */
|
33
subsystems/ntvdm/utils.h
Normal file
33
subsystems/ntvdm/utils.h
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* COPYRIGHT: GPL - See COPYING in the top level directory
|
||||
* PROJECT: ReactOS Virtual DOS Machine
|
||||
* FILE: utils.h
|
||||
* PURPOSE: Utility Functions
|
||||
* PROGRAMMERS: Hermes Belusca-Maito (hermes.belusca@sfr.fr)
|
||||
*/
|
||||
|
||||
#ifndef _UTILS_H_
|
||||
#define _UTILS_H_
|
||||
|
||||
/* INCLUDES *******************************************************************/
|
||||
|
||||
#include "ntvdm.h"
|
||||
|
||||
/* FUNCTIONS ******************************************************************/
|
||||
|
||||
VOID
|
||||
FileClose(IN HANDLE FileHandle);
|
||||
|
||||
HANDLE
|
||||
FileOpen(IN PCSTR FileName,
|
||||
OUT PULONG FileSize OPTIONAL);
|
||||
|
||||
BOOLEAN
|
||||
FileLoadByHandle(IN HANDLE FileHandle,
|
||||
IN PVOID Location,
|
||||
IN ULONG FileSize,
|
||||
OUT PULONG BytesRead);
|
||||
|
||||
#endif // _UTILS_H_
|
||||
|
||||
/* EOF */
|
Loading…
Reference in a new issue