From 9ac9e563c2cfd78bb6f3464ac3bbf77b84ea8d81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Sun, 4 Jan 2015 19:37:12 +0000 Subject: [PATCH] [FREELDR] Some more code reorg before real fixes happen. svn path=/trunk/; revision=65979 --- reactos/boot/freeldr/freeldr/disk/disk.c | 12 +- reactos/boot/freeldr/freeldr/fs/fs.c | 348 ++++++++++++----------- 2 files changed, 179 insertions(+), 181 deletions(-) diff --git a/reactos/boot/freeldr/freeldr/disk/disk.c b/reactos/boot/freeldr/freeldr/disk/disk.c index 6909b46387d..79c014d5f0f 100644 --- a/reactos/boot/freeldr/freeldr/disk/disk.c +++ b/reactos/boot/freeldr/freeldr/disk/disk.c @@ -133,10 +133,8 @@ DiskGetBootPath(char *BootPath, unsigned Size) strcpy(BootPath, Path); - strcat(BootPath, "fdisk"); - _itoa(FrldrBootDrive, Device, 10); - strcat(BootPath, "("); + strcat(BootPath, "fdisk("); strcat(BootPath, Device); strcat(BootPath, ")"); } @@ -163,10 +161,8 @@ DiskGetBootPath(char *BootPath, unsigned Size) strcpy(BootPath, Path); - strcat(BootPath, "rdisk"); - _itoa(FrldrBootDrive - 0x80, Device, 10); - strcat(BootPath, "("); + strcat(BootPath, "rdisk("); strcat(BootPath, Device); strcat(BootPath, ")"); @@ -186,10 +182,8 @@ DiskGetBootPath(char *BootPath, unsigned Size) strcpy(BootPath, Path); - strcat(BootPath, "cdrom"); - _itoa(FrldrBootDrive - 0x80, Device, 10); - strcat(BootPath, "("); + strcat(BootPath, "cdrom("); strcat(BootPath, Device); strcat(BootPath, ")"); } diff --git a/reactos/boot/freeldr/freeldr/fs/fs.c b/reactos/boot/freeldr/freeldr/fs/fs.c index 9792d17f0c9..f8fd57a6b01 100644 --- a/reactos/boot/freeldr/freeldr/fs/fs.c +++ b/reactos/boot/freeldr/freeldr/fs/fs.c @@ -18,6 +18,8 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +/* INCLUDES *******************************************************************/ + #include #define NDEBUG @@ -25,181 +27,11 @@ DBG_DEFAULT_CHANNEL(FILESYSTEM); +/* GLOBALS ********************************************************************/ + #define TAG_DEVICE_NAME 'NDsF' #define TAG_DEVICE 'vDsF' -///////////////////////////////////////////////////////////////////////////////////////////// -// FUNCTIONS -///////////////////////////////////////////////////////////////////////////////////////////// - -VOID FileSystemError(PCSTR ErrorString) -{ - ERR("%s\n", ErrorString); - - UiMessageBox(ErrorString); -} - -PFILE FsOpenFile(PCSTR FileName) -{ - CHAR FullPath[MAX_PATH]; - ULONG FileId; - LONG ret; - - // - // Print status message - // - TRACE("Opening file '%s'...\n", FileName); - - // - // 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 (PFILE)FileId; - else - return (PFILE)0; -} - -VOID FsCloseFile(PFILE FileHandle) -{ - ULONG FileId = (ULONG)FileHandle; - - // - // Close the handle - // - ArcClose(FileId); - - // - // Do not check for error; this function is - // supposed to always succeed - // -} - -/* - * ReadFile() - * returns number of bytes read or EOF - */ -BOOLEAN FsReadFile(PFILE 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 - // - return (ret == ESUCCESS); -} - -ULONG FsGetFileSize(PFILE 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 FsSetFilePointer(PFILE 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 - // -} - -/* - * FsGetNumPathParts() - * This function parses a path in the form of dir1\dir2\file1.ext - * and returns the number of parts it has (i.e. 3 - dir1,dir2,file1.ext) - */ -ULONG FsGetNumPathParts(PCSTR Path) -{ - size_t i; - ULONG num; - - for (i = 0, num = 0; i < strlen(Path); i++) - { - if ((Path[i] == '\\') || (Path[i] == '/')) - { - num++; - } - } - num++; - - TRACE("FsGetNumPathParts() Path = %s NumPathParts = %d\n", Path, num); - - return num; -} - -/* - * FsGetFirstNameFromPath() - * This function parses a path in the form of dir1\dir2\file1.ext - * and puts the first name of the path (e.g. "dir1") in buffer - * compatible with the MSDOS directory structure - */ -VOID FsGetFirstNameFromPath(PCHAR Buffer, PCSTR Path) -{ - size_t i; - - // Copy all the characters up to the end of the - // string or until we hit a '\' character - // and put them in Buffer - for (i = 0; i < strlen(Path); i++) - { - if ((Path[i] == '\\') || (Path[i] == '/')) - { - break; - } - else - { - Buffer[i] = Path[i]; - } - } - - Buffer[i] = 0; - - TRACE("FsGetFirstNameFromPath() Path = %s FirstName = %s\n", Path, Buffer); -} - typedef struct tagFILEDATA { ULONG DeviceId; @@ -221,6 +53,8 @@ typedef struct tagDEVICE static FILEDATA FileData[MAX_FDS]; static LIST_ENTRY DeviceListHead; +/* ARC FUNCTIONS **************************************************************/ + ARC_STATUS ArcClose(ULONG FileId) { LONG ret; @@ -419,6 +253,176 @@ ARC_STATUS ArcSeek(ULONG FileId, LARGE_INTEGER* Position, SEEKMODE SeekMode) return FileData[FileId].FuncTable->Seek(FileId, Position, SeekMode); } +/* FUNCTIONS ******************************************************************/ + +VOID FileSystemError(PCSTR ErrorString) +{ + ERR("%s\n", ErrorString); + + UiMessageBox(ErrorString); +} + +PFILE FsOpenFile(PCSTR FileName) +{ + CHAR FullPath[MAX_PATH]; + ULONG FileId; + LONG ret; + + // + // Print status message + // + TRACE("Opening file '%s'...\n", FileName); + + // + // 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 (PFILE)FileId; + else + return (PFILE)0; +} + +VOID FsCloseFile(PFILE FileHandle) +{ + ULONG FileId = (ULONG)FileHandle; + + // + // Close the handle + // + ArcClose(FileId); + + // + // Do not check for error; this function is + // supposed to always succeed + // +} + +/* + * ReadFile() + * returns number of bytes read or EOF + */ +BOOLEAN FsReadFile(PFILE 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 + // + return (ret == ESUCCESS); +} + +ULONG FsGetFileSize(PFILE 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 FsSetFilePointer(PFILE 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 + // +} + +/* + * FsGetNumPathParts() + * This function parses a path in the form of dir1\dir2\file1.ext + * and returns the number of parts it has (i.e. 3 - dir1,dir2,file1.ext) + */ +ULONG FsGetNumPathParts(PCSTR Path) +{ + size_t i; + ULONG num; + + for (i = 0, num = 0; i < strlen(Path); i++) + { + if ((Path[i] == '\\') || (Path[i] == '/')) + { + num++; + } + } + num++; + + TRACE("FsGetNumPathParts() Path = %s NumPathParts = %d\n", Path, num); + + return num; +} + +/* + * FsGetFirstNameFromPath() + * This function parses a path in the form of dir1\dir2\file1.ext + * and puts the first name of the path (e.g. "dir1") in buffer + * compatible with the MSDOS directory structure + */ +VOID FsGetFirstNameFromPath(PCHAR Buffer, PCSTR Path) +{ + size_t i; + + // Copy all the characters up to the end of the + // string or until we hit a '\' character + // and put them in Buffer + for (i = 0; i < strlen(Path); i++) + { + if ((Path[i] == '\\') || (Path[i] == '/')) + { + break; + } + else + { + Buffer[i] = Path[i]; + } + } + + Buffer[i] = 0; + + TRACE("FsGetFirstNameFromPath() Path = %s FirstName = %s\n", Path, Buffer); +} + VOID FsRegisterDevice(CHAR* Prefix, const DEVVTBL* FuncTable) { DEVICE* pNewEntry;