Improve ARC file infrastructure, by adding a compatibility layer from old to new...
authorHervé Poussineau <hpoussin@reactos.org>
Sat, 8 Aug 2009 17:04:53 +0000 (17:04 +0000)
committerHervé Poussineau <hpoussin@reactos.org>
Sat, 8 Aug 2009 17:04:53 +0000 (17:04 +0000)
i386: when reading sectors, use dedicated scratch area
Increase number of available open files to 60, because something seems to leak file descriptors

svn path=/trunk/; revision=42526

reactos/boot/freeldr/freeldr/arch/i386/hardware.c
reactos/boot/freeldr/freeldr/bootmgr.c
reactos/boot/freeldr/freeldr/fs/fs.c
reactos/boot/freeldr/freeldr/include/fs.h

index b6b693a..75f30cf 100644 (file)
@@ -449,19 +449,26 @@ static LONG DiskOpen(CHAR* Path, OPENMODE OpenMode, ULONG* FileId)
 static LONG DiskRead(ULONG FileId, VOID* Buffer, ULONG N, ULONG* Count)
 {
     DISKCONTEXT* Context = FsGetDeviceSpecific(FileId);
+    UCHAR* Ptr = (UCHAR*)Buffer;
+    ULONG i;
     BOOLEAN ret;
 
     *Count = 0;
     if (N & (Context->SectorSize - 1))
         return EINVAL;
 
-    ret = MachDiskReadLogicalSectors(
-        Context->DriveNumber,
-        Context->SectorNumber + Context->SectorOffset,
-        N / Context->SectorSize,
-        Buffer);
-    if (!ret)
-        return EIO;
+    for (i = 0; i < N / Context->SectorSize; i++)
+    {
+        ret = MachDiskReadLogicalSectors(
+            Context->DriveNumber,
+            Context->SectorNumber + Context->SectorOffset + i,
+            1,
+            (PVOID)DISKREADBUFFER);
+        if (!ret)
+            return EIO;
+        RtlCopyMemory(Ptr, (PVOID)DISKREADBUFFER, Context->SectorSize);
+        Ptr += Context->SectorSize;
+    }
 
     *Count = N;
     return ESUCCESS;
index ea86099..81dbd37 100644 (file)
@@ -37,6 +37,13 @@ VOID RunLoader(VOID)
                return;
        }
 
+       // FIXME: if possible, only detect and register ARC devices...
+       if (!MachHwDetect())
+       {
+               UiMessageBoxCritical("Error when detecting hardware");
+               return;
+       }
+
        if (!IniFileInitialize())
        {
                UiMessageBoxCritical("Error initializing .ini file");
index fdd095b..3617c28 100644 (file)
@@ -1,6 +1,7 @@
 /*
  *  FreeLoader
  *  Copyright (C) 1998-2003  Brian Palmer  <brianp@sginet.com>
+ *  Copyright (C) 2008-2009  Hervé Poussineau  <hpoussin@reactos.org>
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -33,6 +34,134 @@ PVOID FsStaticBufferDisk = 0, FsStaticBufferData = 0;
 // FUNCTIONS
 /////////////////////////////////////////////////////////////////////////////////////////////
 
+static BOOLEAN CompatArcOpenVolume(UCHAR DriveNumber, ULONGLONG VolumeStartSector, ULONGLONG PartitionSectorCount)
+{
+       //
+       // Always return success
+       //
+       return TRUE;
+}
+
+static FILE* CompatArcOpenFile(PCSTR FileName)
+{
+       CHAR FullPath[MAX_PATH];
+       ULONG FileId;
+       LONG ret;
+
+       //
+       // Create full file name
+       //
+       MachDiskGetBootPath(FullPath, sizeof(FullPath));
+       strcat(FullPath, FileName);
+
+       //
+       // Open the file
+       //
+       ret = ArcOpen(FullPath, OpenReadOnly, &FileId);
+
+       //
+       // Check for success
+       //
+       if (ret == ESUCCESS)
+               return (FILE*)FileId;
+       else
+               return NULL;
+}
+
+static BOOLEAN CompatArcReadFile(FILE *FileHandle, ULONG BytesToRead, ULONG* BytesRead, PVOID Buffer)
+{
+       ULONG FileId = (ULONG)FileHandle;
+       LONG ret;
+
+       //
+       // Read the file
+       //
+       ret = ArcRead(FileId, Buffer, BytesToRead, BytesRead);
+
+       //
+       // Check for success
+       //
+       if (ret == ESUCCESS)
+               return TRUE;
+       else
+               return FALSE;
+}
+
+ULONG CompatArcGetFileSize(FILE *FileHandle)
+{
+       ULONG FileId = (ULONG)FileHandle;
+       FILEINFORMATION Information;
+       LONG ret;
+
+       //
+       // Query file informations
+       //
+       ret = ArcGetFileInformation(FileId, &Information);
+
+       //
+       // Check for error
+       //
+       if (ret != ESUCCESS || Information.EndingAddress.HighPart != 0)
+               return 0;
+
+       //
+       // Return file size
+       //
+       return Information.EndingAddress.LowPart;
+}
+
+VOID CompatArcSetFilePointer(FILE *FileHandle, ULONG NewFilePointer)
+{
+       ULONG FileId = (ULONG)FileHandle;
+       LARGE_INTEGER Position;
+
+       //
+       // Set file position
+       //
+       Position.HighPart = 0;
+       Position.LowPart = NewFilePointer;
+       ArcSeek(FileId, &Position, SeekAbsolute);
+
+       //
+       // Do not check for error; this function is
+       // supposed to always succeed
+       //
+}
+
+ULONG CompatArcGetFilePointer(FILE *FileHandle)
+{
+       ULONG FileId = (ULONG)FileHandle;
+       FILEINFORMATION Information;
+       LONG ret;
+
+       //
+       // Query file informations
+       //
+       ret = ArcGetFileInformation(FileId, &Information);
+
+       //
+       // Check for error
+       //
+       if (ret != ESUCCESS || Information.CurrentAddress.HighPart != 0)
+               return 0;
+
+       //
+       // Return file pointer position
+       //
+       return Information.CurrentAddress.LowPart;
+}
+
+static const FS_VTBL CompatArcVtbl =
+{
+       CompatArcOpenVolume,
+       CompatArcOpenFile,
+       NULL,
+       CompatArcReadFile,
+       CompatArcGetFileSize,
+       CompatArcSetFilePointer,
+       CompatArcGetFilePointer,
+};
+
 VOID FileSystemError(PCSTR ErrorString)
 {
        DPRINTM(DPRINT_FILESYSTEM, "%s\n", ErrorString);
@@ -385,7 +514,7 @@ const DEVVTBL CompatFsFuncTable = {
     CompatFsSeek,
 };
 
-#define MAX_FDS 20
+#define MAX_FDS 60
 typedef struct tagFILEDATA
 {
     ULONG DeviceId;
@@ -420,6 +549,7 @@ LONG ArcClose(ULONG FileId)
     {
         FileData[FileId].FuncTable = NULL;
         FileData[FileId].Specific = NULL;
+        FileData[FileId].DeviceId = -1;
     }
     return ret;
 }
@@ -444,6 +574,9 @@ LONG ArcOpen(CHAR* Path, OPENMODE OpenMode, ULONG* FileId)
     OPENMODE DeviceOpenMode;
     ULONG DeviceId;
 
+    /* Print status message */
+    DPRINTM(DPRINT_FILESYSTEM, "Opening file '%s'...\n", Path);
+
     *FileId = MAX_FDS;
 
     /* Search last ')', which delimits device and path */
@@ -535,6 +668,7 @@ LONG ArcOpen(CHAR* Path, OPENMODE OpenMode, ULONG* FileId)
 
     /* Open the file */
     FileData[i].FuncTable = FileData[DeviceId].FileFuncTable;
+    FileData[i].DeviceId = DeviceId;
     *FileId = i;
     ret = FileData[i].FuncTable->Open(FileName, OpenMode, FileId);
     if (ret != ESUCCESS)
@@ -590,8 +724,20 @@ VOID* FsGetDeviceSpecific(ULONG FileId)
     return FileData[FileId].Specific;
 }
 
+ULONG FsGetDeviceId(ULONG FileId)
+{
+    if (FileId >= MAX_FDS)
+        return (ULONG)-1;
+    return FileData[FileId].DeviceId;
+}
+
 VOID FsInit(VOID)
 {
-    memset(FileData, 0, sizeof(FileData));
+    ULONG i;
+
+    RtlZeroMemory(FileData, sizeof(FileData));
+    for (i = 0; i < MAX_FDS; i++)
+        FileData[i].DeviceId = (ULONG)-1;
+
     InitializeListHead(&DeviceListHead);
 }
index cc2add6..2d6ab45 100644 (file)
@@ -29,14 +29,10 @@ typedef struct tagDEVVTBL
   ARC_SEEK Seek;
 } DEVVTBL;
 
-//#define      EOF                             -1
-
 #define        FS_FAT                  1
 #define        FS_NTFS                 2
 #define        FS_EXT2                 3
-#define FS_REISER              4
 #define FS_ISO9660             5
-#define FS_PXE                 6
 
 #define FILE                   VOID
 #define PFILE                  FILE *
@@ -44,6 +40,7 @@ typedef struct tagDEVVTBL
 VOID FsRegisterDevice(CHAR* Prefix, const DEVVTBL* FuncTable);
 VOID FsSetDeviceSpecific(ULONG FileId, VOID* Specific);
 VOID* FsGetDeviceSpecific(ULONG FileId);
+ULONG FsGetDeviceId(ULONG FileId);
 VOID FsInit(VOID);
 
 LONG ArcClose(ULONG FileId);