Author: hpoussin Date: Sat Aug 8 19:04:53 2009 New Revision: 42526
URL: http://svn.reactos.org/svn/reactos?rev=42526&view=rev Log: Improve ARC file infrastructure, by adding a compatibility layer from old to new system (new to old already exists) i386: when reading sectors, use dedicated scratch area Increase number of available open files to 60, because something seems to leak file descriptors
Modified: trunk/reactos/boot/freeldr/freeldr/arch/i386/hardware.c trunk/reactos/boot/freeldr/freeldr/bootmgr.c trunk/reactos/boot/freeldr/freeldr/fs/fs.c trunk/reactos/boot/freeldr/freeldr/include/fs.h
Modified: trunk/reactos/boot/freeldr/freeldr/arch/i386/hardware.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/arch/i... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/arch/i386/hardware.c [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/arch/i386/hardware.c [iso-8859-1] Sat Aug 8 19:04:53 2009 @@ -449,19 +449,26 @@ 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;
Modified: trunk/reactos/boot/freeldr/freeldr/bootmgr.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/bootmg... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/bootmgr.c [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/bootmgr.c [iso-8859-1] Sat Aug 8 19:04:53 2009 @@ -37,6 +37,13 @@ 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");
Modified: trunk/reactos/boot/freeldr/freeldr/fs/fs.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/fs/fs.... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/fs/fs.c [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/fs/fs.c [iso-8859-1] Sat Aug 8 19:04:53 2009 @@ -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 @@ // 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 @@ CompatFsSeek, };
-#define MAX_FDS 20 +#define MAX_FDS 60 typedef struct tagFILEDATA { ULONG DeviceId; @@ -420,6 +549,7 @@ { FileData[FileId].FuncTable = NULL; FileData[FileId].Specific = NULL; + FileData[FileId].DeviceId = -1; } return ret; } @@ -443,6 +573,9 @@ ULONG dwCount, dwLength; OPENMODE DeviceOpenMode; ULONG DeviceId; + + /* Print status message */ + DPRINTM(DPRINT_FILESYSTEM, "Opening file '%s'...\n", Path);
*FileId = MAX_FDS;
@@ -535,6 +668,7 @@
/* 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 @@ 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); }
Modified: trunk/reactos/boot/freeldr/freeldr/include/fs.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/includ... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/include/fs.h [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/include/fs.h [iso-8859-1] Sat Aug 8 19:04:53 2009 @@ -29,14 +29,10 @@ 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 @@ 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);