Author: hpoussin
Date: Sat Aug 8 23:23:23 2009
New Revision: 42539
URL:
http://svn.reactos.org/svn/reactos?rev=42539&view=rev
Log:
Use Arc* infrastructure to read the .inf file
Modified:
trunk/reactos/boot/freeldr/freeldr/inffile/inffile.c
Modified: trunk/reactos/boot/freeldr/freeldr/inffile/inffile.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/inffi…
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/inffile/inffile.c [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/freeldr/inffile/inffile.c [iso-8859-1] Sat Aug 8 23:23:23
2009
@@ -873,91 +873,107 @@
PCSTR FileName,
PULONG ErrorLine)
{
- PFILE FileHandle;
- PCHAR FileBuffer;
- ULONG FileSize;
- PINFCACHE Cache;
- BOOLEAN Success;
-
-
- *InfHandle = NULL;
- *ErrorLine = (ULONG)-1;
-
-
- /* Open the inf file */
- FileHandle = FsOpenFile (FileName);
- if (FileHandle == NULL)
- {
-// DPRINT("NtOpenFile() failed (Status %lx)\n", Status);
- return FALSE;
- }
-
-// DPRINT("NtOpenFile() successful\n");
-
- /* Query file size */
- FileSize = FsGetFileSize (FileHandle);
- if (FileSize == 0)
- {
-// DPRINT("NtQueryInformationFile() failed (Status %lx)\n", Status);
- FsCloseFile (FileHandle);
- return FALSE;
- }
-
-// DPRINT("File size: %lu\n", FileLength);
-
- /* Allocate file buffer */
- FileBuffer = MmHeapAlloc (FileSize + 1);
- if (FileBuffer == NULL)
- {
-// DPRINT1("RtlAllocateHeap() failed\n");
- FsCloseFile (FileHandle);
- return FALSE;
- }
-
- /* Read file */
- Success = FsReadFile(FileHandle, FileSize, NULL, FileBuffer);
-
- FsCloseFile (FileHandle);
- if (!Success)
- {
-// DPRINT("FsReadFile() failed\n");
- MmHeapFree (FileBuffer);
- return FALSE;
- }
-
- /* Append string terminator */
- FileBuffer[FileSize] = 0;
-
- /* Allocate infcache header */
- Cache = (PINFCACHE)MmHeapAlloc (sizeof(INFCACHE));
- if (Cache == NULL)
- {
-// DPRINT("RtlAllocateHeap() failed\n");
- MmHeapFree (FileBuffer);
- return FALSE;
- }
-
- /* Initialize inicache header */
- RtlZeroMemory(Cache,
- sizeof(INFCACHE));
-
- /* Parse the inf buffer */
- Success = InfpParseBuffer (Cache,
- FileBuffer,
- FileBuffer + FileSize,
- ErrorLine);
- if (!Success)
- {
- MmHeapFree (Cache);
- Cache = NULL;
- }
-
- /* Free file buffer */
- MmHeapFree (FileBuffer);
-
- *InfHandle = (HINF)Cache;
-
- return Success;
+ FILEINFORMATION Information;
+ ULONG FileId;
+ PCHAR FileBuffer;
+ ULONG FileSize, Count;
+ PINFCACHE Cache;
+ BOOLEAN Success;
+ LONG ret;
+
+ *InfHandle = NULL;
+ *ErrorLine = (ULONG)-1;
+
+ //
+ // Open the .inf file
+ //
+ FileId = FsOpenFile(FileName);
+ if (!FileId)
+ {
+ return FALSE;
+ }
+
+ //
+ // Query file size
+ //
+ ret = ArcGetFileInformation(FileId, &Information);
+ if (ret != ESUCCESS || Information.EndingAddress.HighPart != 0)
+ {
+ ArcClose(FileId);
+ return FALSE;
+ }
+ FileSize = Information.EndingAddress.LowPart;
+
+ //
+ // Allocate buffer to cache the file
+ //
+ FileBuffer = MmHeapAlloc(FileSize + 1);
+ if (!FileBuffer)
+ {
+ ArcClose(FileId);
+ return FALSE;
+ }
+
+ //
+ // Read file into memory
+ //
+ ret = ArcRead(FileId, FileBuffer, FileSize, &Count);
+ if (ret != ESUCCESS || Count != FileSize)
+ {
+ ArcClose(FileId);
+ MmHeapFree(FileBuffer);
+ return FALSE;
+ }
+
+ //
+ // We don't need the file anymore. Close it
+ //
+ ArcClose(FileId);
+
+ //
+ // Append string terminator
+ //
+ FileBuffer[FileSize] = 0;
+
+ //
+ // Allocate infcache header
+ //
+ Cache = (PINFCACHE)MmHeapAlloc(sizeof(INFCACHE));
+ if (!Cache)
+ {
+ MmHeapFree (FileBuffer);
+ return FALSE;
+ }
+
+ //
+ // Initialize inicache header
+ //
+ RtlZeroMemory(Cache, sizeof(INFCACHE));
+
+ //
+ // Parse the inf buffer
+ //
+ Success = InfpParseBuffer(Cache,
+ FileBuffer,
+ FileBuffer + FileSize,
+ ErrorLine);
+ if (!Success)
+ {
+ MmHeapFree(Cache);
+ Cache = NULL;
+ }
+
+ //
+ // Free file buffer, as it has been parsed
+ //
+ MmHeapFree(FileBuffer);
+
+ //
+ // Return .inf parsed contents
+ //
+ *InfHandle = (HINF)Cache;
+
+ return Success;
}