Author: hbelusca
Date: Thu Feb 27 03:02:11 2014
New Revision: 62341
URL:
http://svn.reactos.org/svn/reactos?rev=62341&view=rev
Log:
[NTVDM]
Add some utility functions (only file-oriented for now :) ). Will be used in the next
commit.
Added:
branches/ntvdm/subsystems/ntvdm/utils.c (with props)
branches/ntvdm/subsystems/ntvdm/utils.h (with props)
Modified:
branches/ntvdm/subsystems/ntvdm/CMakeLists.txt
Modified: branches/ntvdm/subsystems/ntvdm/CMakeLists.txt
URL:
http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/ntvdm/CMakeLis…
==============================================================================
--- branches/ntvdm/subsystems/ntvdm/CMakeLists.txt [iso-8859-1] (original)
+++ branches/ntvdm/subsystems/ntvdm/CMakeLists.txt [iso-8859-1] Thu Feb 27 03:02:11 2014
@@ -26,6 +26,7 @@
emulator.c
io.c
registers.c
+ utils.c
vddsup.c
ntvdm.c
ntvdm.rc
Added: branches/ntvdm/subsystems/ntvdm/utils.c
URL:
http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/ntvdm/utils.c?…
==============================================================================
--- branches/ntvdm/subsystems/ntvdm/utils.c (added)
+++ branches/ntvdm/subsystems/ntvdm/utils.c [iso-8859-1] Thu Feb 27 03:02:11 2014
@@ -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(a)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 */
Propchange: branches/ntvdm/subsystems/ntvdm/utils.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: branches/ntvdm/subsystems/ntvdm/utils.h
URL:
http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/ntvdm/utils.h?…
==============================================================================
--- branches/ntvdm/subsystems/ntvdm/utils.h (added)
+++ branches/ntvdm/subsystems/ntvdm/utils.h [iso-8859-1] Thu Feb 27 03:02:11 2014
@@ -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(a)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 */
Propchange: branches/ntvdm/subsystems/ntvdm/utils.h
------------------------------------------------------------------------------
svn:eol-style = native