ReactOS 0.4.15-dev-5672-gf73ac17
utils.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: GPL - See COPYING in the top level directory
3 * PROJECT: ReactOS Virtual DOS Machine
4 * FILE: subsystems/mvdm/ntvdm/utils.c
5 * PURPOSE: Utility Functions
6 * PROGRAMMERS: Hermes Belusca-Maito (hermes.belusca@sfr.fr)
7 */
8
9/* INCLUDES *******************************************************************/
10
11#include "ntvdm.h"
12
13#define NDEBUG
14#include <debug.h>
15
16/* PRIVATE FUNCTIONS **********************************************************/
17
18/* PUBLIC FUNCTIONS ***********************************************************/
19
20VOID
22{
24}
25
29{
31 ULONG ulFileSize;
32
33 /* Open the file */
34 SetLastError(0); // For debugging purposes
38 NULL,
41 NULL);
42 DPRINT1("File '%s' opening %s ; GetLastError() = %u\n",
43 FileName, hFile != INVALID_HANDLE_VALUE ? "succeeded" : "failed", GetLastError());
44
45 /* If we failed, bail out */
46 if (hFile == INVALID_HANDLE_VALUE) return NULL;
47
48 /* OK, we have a handle to the file */
49
50 /*
51 * Retrieve the size of the file. In NTVDM we will handle files
52 * of maximum 1Mb so we can largely use GetFileSize only.
53 */
54 ulFileSize = GetFileSize(hFile, NULL);
55 if (ulFileSize == INVALID_FILE_SIZE && GetLastError() != ERROR_SUCCESS)
56 {
57 /* We failed, bail out */
58 DPRINT1("Error when retrieving file size, or size too large (%d)\n", ulFileSize);
60 return NULL;
61 }
62
63 /* Success, return file handle and size if needed */
64 if (FileSize) *FileSize = ulFileSize;
65 return hFile;
66}
67
70 IN PVOID Location,
73{
75
76 /* Attempt to load the file into memory */
77 SetLastError(0); // For debugging purposes
79 Location, // REAL_TO_PHYS(LocationRealPtr),
82 NULL);
83 DPRINT1("File loading %s ; GetLastError() = %u\n", Success ? "succeeded" : "failed", GetLastError());
84
85 return Success;
86}
87
88/* EOF */
unsigned char BOOLEAN
#define DPRINT1
Definition: precomp.h:8
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define CloseHandle
Definition: compat.h:739
#define OPEN_EXISTING
Definition: compat.h:775
#define ReadFile(a, b, c, d, e)
Definition: compat.h:742
#define SetLastError(x)
Definition: compat.h:752
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:740
#define GENERIC_READ
Definition: compat.h:135
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
#define FILE_SHARE_READ
Definition: compat.h:136
DWORD WINAPI GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh)
Definition: fileinfo.c:331
@ Success
Definition: eventcreate.c:712
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE FileHandle
Definition: fltkernel.h:1231
_Must_inspect_result_ _Out_ PLARGE_INTEGER FileSize
Definition: fsrtlfuncs.h:108
_In_ HANDLE hFile
Definition: mswsock.h:90
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68
HANDLE FileOpen(IN PCSTR FileName, OUT PULONG FileSize OPTIONAL)
Definition: utils.c:27
VOID FileClose(IN HANDLE FileHandle)
Definition: utils.c:21
BOOLEAN FileLoadByHandle(IN HANDLE FileHandle, IN PVOID Location, IN ULONG FileSize, OUT PULONG BytesRead)
Definition: utils.c:69
uint32_t * PULONG
Definition: typedefs.h:59
const char * PCSTR
Definition: typedefs.h:52
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PLONGLONG _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_opt_ PULONG_PTR BytesRead
Definition: wdfiotarget.h:870
DWORD WINAPI GetLastError(void)
Definition: except.c:1040
#define INVALID_FILE_SIZE
Definition: winbase.h:548