From: Hermès Bélusca-Maïto Date: Sat, 10 Aug 2019 11:44:33 +0000 (+0200) Subject: [FREELDR] Diverse enhancements. X-Git-Tag: 0.4.14-dev~403 X-Git-Url: https://git.reactos.org/?p=reactos.git;a=commitdiff_plain;h=8d94b2a68ddaf93c3dfcbded456053b6e209430b;hp=4a230d8341b9e6dd0966ee5c080cd28d2669aebb [FREELDR] Diverse enhancements. - Get rid of the FsCloseFile(), FsReadFile(), FsGetFileInformation(), FsGetFileSize() and FsSetFilePointer() wrappers and use the ARC functions directly instead. Make FsOpenFile() return an ARC file descriptor ID of the correct type. Get rid of unused FS_* defines. - Use TRACEs in the ***Mount() filesystem functions for diagnostics purposes. - Remove a leak in FatGetFatEntry(). Assign stuff via QuadPart where possible in FatMount(). Remove an unused member in FAT_FILE_INFO. - Reduce code indentation in BtrFsMount() and remove a leak there. - Disable reading the "BootPath" parameter in the linux loader since we don't use this parameter (yet??) --- diff --git a/boot/freeldr/freeldr/arch/powerpc/mboot.c b/boot/freeldr/freeldr/arch/powerpc/mboot.c index d08e5efecec..aa57f0693cd 100644 --- a/boot/freeldr/freeldr/arch/powerpc/mboot.c +++ b/boot/freeldr/freeldr/arch/powerpc/mboot.c @@ -431,6 +431,7 @@ FrLdrMapModule(FILE *KernelImage, PCHAR ImageName, PCHAR MemLoadAddr, ULONG Kern PCHAR sptr; Elf32_Ehdr ehdr; Elf32_Shdr *shdr; + LARGE_INTEGER Position; LPSTR TempName; TempName = strrchr(ImageName, '\\'); @@ -451,7 +452,7 @@ FrLdrMapModule(FILE *KernelImage, PCHAR ImageName, PCHAR MemLoadAddr, ULONG Kern //printf("Loading file (elf at %x)\n", KernelAddr); /* Load the first 1024 bytes of the kernel image so we can read the PE header */ - if (!FsReadFile(KernelImage, sizeof(ehdr), NULL, &ehdr)) { + if (ArcRead(KernelImage, &ehdr, sizeof(ehdr), NULL) != ESUCCESS) { /* Fail if we couldn't read */ printf("Couldn't read the elf header\n"); @@ -466,8 +467,9 @@ FrLdrMapModule(FILE *KernelImage, PCHAR ImageName, PCHAR MemLoadAddr, ULONG Kern sptr = (PCHAR)FrLdrTempAlloc(shnum * shsize, TAG_MBOOT); /* Read section headers */ - FsSetFilePointer(KernelImage, ehdr.e_shoff); - FsReadFile(KernelImage, shsize * shnum, NULL, sptr); + Position.QuadPart = ehdr.e_shoff; + ArcSeek(KernelImage, &Position, SeekAbsolute); + ArcRead(KernelImage, sptr, shsize * shnum, NULL); /* Now we'll get the PE Header */ for( i = 0; i < shnum; i++ ) @@ -478,8 +480,9 @@ FrLdrMapModule(FILE *KernelImage, PCHAR ImageName, PCHAR MemLoadAddr, ULONG Kern /* Find the PE Header */ if (shdr->sh_type == TYPE_PEHEADER) { - FsSetFilePointer(KernelImage, shdr->sh_offset); - FsReadFile(KernelImage, shdr->sh_size, NULL, MemLoadAddr); + Position.QuadPart = shdr->sh_offset; + ArcSeek(KernelImage, &Position, SeekAbsolute); + ArcRead(KernelImage, MemLoadAddr, shdr->sh_size, NULL); ImageHeader = (PIMAGE_DOS_HEADER)MemLoadAddr; NtHeader = (PIMAGE_NT_HEADERS)((PCHAR)MemLoadAddr + SWAPD(ImageHeader->e_lfanew)); #if 0 @@ -527,8 +530,9 @@ FrLdrMapModule(FILE *KernelImage, PCHAR ImageName, PCHAR MemLoadAddr, ULONG Kern { /* Content area */ printf("Loading section %d at %x (real: %x:%d)\n", i, KernelAddr + SectionAddr, MemLoadAddr+SectionAddr, shdr->sh_size); - FsSetFilePointer(KernelImage, shdr->sh_offset); - FsReadFile(KernelImage, shdr->sh_size, NULL, MemLoadAddr + SectionAddr); + Position.QuadPart = shdr->sh_offset; + ArcSeek(KernelImage, &Position, SeekAbsolute); + ArcRead(KernelImage, MemLoadAddr + SectionAddr, shdr->sh_size, NULL); } else { @@ -565,15 +569,17 @@ FrLdrMapModule(FILE *KernelImage, PCHAR ImageName, PCHAR MemLoadAddr, ULONG Kern if (!ELF_SECTION(targetSection)->sh_addr) continue; RelocSection = FrLdrTempAlloc(shdr->sh_size, TAG_MBOOT); - FsSetFilePointer(KernelImage, relstart); - FsReadFile(KernelImage, shdr->sh_size, NULL, RelocSection); + Position.QuadPart = relstart; + ArcSeek(KernelImage, &Position, SeekAbsolute); + ArcRead(KernelImage, RelocSection, shdr->sh_size, NULL); /* Get the symbol section */ shdr = ELF_SECTION(shdr->sh_link); SymbolSection = FrLdrTempAlloc(shdr->sh_size, TAG_MBOOT); - FsSetFilePointer(KernelImage, shdr->sh_offset); - FsReadFile(KernelImage, shdr->sh_size, NULL, SymbolSection); + Position.QuadPart = shdr->sh_offset; + ArcSeek(KernelImage, &Position, SeekAbsolute); + ArcRead(KernelImage, SymbolSection, shdr->sh_size, NULL); for(j = 0; j < numreloc; j++) { @@ -705,6 +711,8 @@ FrLdrLoadModule(FILE *ModuleImage, LPCSTR ModuleName, PULONG ModuleSize) { + ARC_STATUS Status; + FILEINFORMATION FileInfo; ULONG LocalModuleSize; ULONG_PTR ThisModuleBase = NextModuleBase; PLOADER_MODULE ModuleData; @@ -726,9 +734,12 @@ FrLdrLoadModule(FILE *ModuleImage, } while(TempName); NameBuffer = reactos_module_strings[LoaderBlock.ModsCount]; - /* Get Module Size */ - LocalModuleSize = FsGetFileSize(ModuleImage); + Status = ArcGetFileInformation(ModuleImage, &FileInfo); + if (Status != ESUCCESS || FileInfo.EndingAddress.HighPart != 0) + LocalModuleSize = 0; + else + LocalModuleSize = FileInfo.EndingAddress.LowPart; /* Fill out Module Data Structure */ ModuleData->ModStart = NextModuleBase; @@ -739,7 +750,7 @@ FrLdrLoadModule(FILE *ModuleImage, ModuleData->String = (ULONG_PTR)NameBuffer; /* Load the file image */ - FsReadFile(ModuleImage, LocalModuleSize, NULL, (PVOID)NextModuleBase); + ArcRead(ModuleImage, (PVOID)NextModuleBase, LocalModuleSize, NULL); /* Move to next memory block and increase Module Count */ NextModuleBase = ROUND_UP(ModuleData->ModEnd, PAGE_SIZE); diff --git a/boot/freeldr/freeldr/disk/ramdisk.c b/boot/freeldr/freeldr/disk/ramdisk.c index b1a6f09dfd1..c9a096399e4 100644 --- a/boot/freeldr/freeldr/disk/ramdisk.c +++ b/boot/freeldr/freeldr/disk/ramdisk.c @@ -120,7 +120,7 @@ BOOLEAN NTAPI RamDiskLoadVirtualFile(IN PCHAR FileName) { - PFILE RamFile; + ULONG RamFileId; ULONG TotalRead, ChunkSize, Count; PCHAR MsgBuffer = "Loading RamDisk..."; ULONG PercentPerChunk, Percent; @@ -137,17 +137,17 @@ RamDiskLoadVirtualFile(IN PCHAR FileName) // // Try opening the ramdisk file // - RamFile = FsOpenFile(FileName); - if (!RamFile) + RamFileId = FsOpenFile(FileName); + if (!RamFileId) return FALSE; // // Get the file size // - Status = ArcGetFileInformation(RamFile, &Information); + Status = ArcGetFileInformation(RamFileId, &Information); if (Status != ESUCCESS) { - FsCloseFile(RamFile); + ArcClose(RamFileId); return FALSE; } @@ -157,7 +157,7 @@ RamDiskLoadVirtualFile(IN PCHAR FileName) if (Information.EndingAddress.HighPart != 0) { UiMessageBox("RAM disk too big."); - FsCloseFile(RamFile); + ArcClose(RamFileId); return FALSE; } gRamDiskSize = Information.EndingAddress.LowPart; @@ -174,7 +174,7 @@ RamDiskLoadVirtualFile(IN PCHAR FileName) if (!gRamDiskBase) { UiMessageBox("Failed to allocate memory for RAM disk."); - FsCloseFile(RamFile); + ArcClose(RamFileId); return FALSE; } @@ -205,10 +205,10 @@ RamDiskLoadVirtualFile(IN PCHAR FileName) // Position.HighPart = 0; Position.LowPart = TotalRead; - Status = ArcSeek(RamFile, &Position, SeekAbsolute); + Status = ArcSeek(RamFileId, &Position, SeekAbsolute); if (Status == ESUCCESS) { - Status = ArcRead(RamFile, + Status = ArcRead(RamFileId, (PVOID)((ULONG_PTR)gRamDiskBase + TotalRead), ChunkSize, &Count); @@ -222,13 +222,13 @@ RamDiskLoadVirtualFile(IN PCHAR FileName) MmFreeMemory(gRamDiskBase); gRamDiskBase = NULL; gRamDiskSize = 0; - FsCloseFile(RamFile); + ArcClose(RamFileId); UiMessageBox("Failed to read RAM disk."); return FALSE; } } - FsCloseFile(RamFile); + ArcClose(RamFileId); /* Setup the RAMDISK device */ RamDiskInitialize(); diff --git a/boot/freeldr/freeldr/include/fs.h b/boot/freeldr/freeldr/include/fs.h index 261a3413f14..fc5ad1e22f0 100644 --- a/boot/freeldr/freeldr/include/fs.h +++ b/boot/freeldr/freeldr/include/fs.h @@ -29,12 +29,7 @@ typedef struct tagDEVVTBL LPCWSTR ServiceName; } DEVVTBL; -#define FS_FAT 1 -#define FS_NTFS 2 -#define FS_EXT2 3 -#define FS_ISO9660 5 - -#define PFILE ULONG +#define MAX_FDS 60 ARC_STATUS ArcOpen(CHAR* Path, OPENMODE OpenMode, ULONG* FileId); ARC_STATUS ArcClose(ULONG FileId); @@ -43,12 +38,7 @@ ARC_STATUS ArcSeek(ULONG FileId, LARGE_INTEGER* Position, SEEKMODE SeekMode); ARC_STATUS ArcGetFileInformation(ULONG FileId, FILEINFORMATION* Information); VOID FileSystemError(PCSTR ErrorString); -PFILE FsOpenFile(PCSTR FileName); -VOID FsCloseFile(PFILE FileHandle); -BOOLEAN FsReadFile(PFILE FileHandle, ULONG BytesToRead, ULONG* BytesRead, PVOID Buffer); -BOOLEAN FsGetFileInformation(PFILE FileHandle, FILEINFORMATION* Information); -ULONG FsGetFileSize(PFILE FileHandle); -VOID FsSetFilePointer(PFILE FileHandle, ULONG NewFilePointer); +ULONG FsOpenFile(PCSTR FileName); ULONG FsGetNumPathParts(PCSTR Path); VOID FsGetFirstNameFromPath(PCHAR Buffer, PCSTR Path); @@ -58,5 +48,3 @@ VOID FsSetDeviceSpecific(ULONG FileId, VOID* Specific); VOID* FsGetDeviceSpecific(ULONG FileId); ULONG FsGetDeviceId(ULONG FileId); VOID FsInit(VOID); - -#define MAX_FDS 60 diff --git a/boot/freeldr/freeldr/include/fs/fat.h b/boot/freeldr/freeldr/include/fs/fat.h index 42943ce158b..7117cb2bad8 100644 --- a/boot/freeldr/freeldr/include/fs/fat.h +++ b/boot/freeldr/freeldr/include/fs/fat.h @@ -151,7 +151,6 @@ typedef struct ULONG FileSize; /* File size */ ULONG FilePointer; /* File pointer */ ULONG* FileFatChain; /* File fat chain array */ - ULONG DriveNumber; PFAT_VOLUME_INFO Volume; } FAT_FILE_INFO, * PFAT_FILE_INFO; diff --git a/boot/freeldr/freeldr/include/linux.h b/boot/freeldr/freeldr/include/linux.h index 3d5c7896f5a..72043f8ef27 100644 --- a/boot/freeldr/freeldr/include/linux.h +++ b/boot/freeldr/freeldr/include/linux.h @@ -142,11 +142,11 @@ LinuxParseIniSection( IN ULONG Argc, IN PCHAR Argv[]); -BOOLEAN LinuxReadBootSector(PFILE LinuxKernelFile); -BOOLEAN LinuxReadSetupSector(PFILE LinuxKernelFile); -BOOLEAN LinuxReadKernel(PFILE LinuxKernelFile); -BOOLEAN LinuxCheckKernelVersion(VOID); -BOOLEAN LinuxReadInitrd(PFILE LinuxInitrdFile); +BOOLEAN LinuxReadBootSector(ULONG LinuxKernelFile); +BOOLEAN LinuxReadSetupSector(ULONG LinuxKernelFile); +BOOLEAN LinuxReadKernel(ULONG LinuxKernelFile); +BOOLEAN LinuxCheckKernelVersion(VOID); +BOOLEAN LinuxReadInitrd(ULONG LinuxInitrdFile); #endif // _M_IX86 diff --git a/boot/freeldr/freeldr/lib/fs/btrfs.c b/boot/freeldr/freeldr/lib/fs/btrfs.c index 1258454db60..0912471b29c 100644 --- a/boot/freeldr/freeldr/lib/fs/btrfs.c +++ b/boot/freeldr/freeldr/lib/fs/btrfs.c @@ -1229,7 +1229,7 @@ const DEVVTBL *BtrFsMount(ULONG DeviceId) struct btrfs_path path; struct btrfs_root_item fs_root_item; - TRACE("Enter BtrFsMount(), sizeof %d %d\n", sizeof(struct BTRFS_INFO), sizeof(struct btrfs_super_block)); + TRACE("Enter BtrFsMount(%lu)\n", DeviceId); BtrFsInfo = FrLdrTempAlloc(sizeof(struct BTRFS_INFO), TAG_BTRFS_INFO); if (!BtrFsInfo) @@ -1244,38 +1244,36 @@ const DEVVTBL *BtrFsMount(ULONG DeviceId) } /* Check if SuperBlock is valid. If yes, return BTRFS function table */ - if (BtrFsInfo->SuperBlock.magic == BTRFS_MAGIC_N) + if (BtrFsInfo->SuperBlock.magic != BTRFS_MAGIC_N) { - BtrFsInfo->DeviceId = DeviceId; - TRACE("BtrFsMount() superblock magic ok\n"); - - btrfs_init_crc32c(); - - btrfs_read_sys_chunk_array(); - btrfs_read_chunk_tree(); - - /* setup roots */ - fs_root_item.bytenr = BtrFsInfo->SuperBlock.root; - fs_root_item.level = BtrFsInfo->SuperBlock.root_level; + FrLdrTempFree(BtrFsInfo, TAG_BTRFS_INFO); + return NULL; + } - init_path(&path); - if (!BtrFsSearchTreeType(&fs_root_item, BTRFS_FS_TREE_OBJECTID, BTRFS_ROOT_ITEM_KEY, &path)) - { - FrLdrTempFree(BtrFsInfo, TAG_BTRFS_INFO); - free_path(&path); - return NULL; - } + BtrFsInfo->DeviceId = DeviceId; + TRACE("BtrFsMount(%lu) superblock magic ok\n", DeviceId); - BtrFsInfo->FsRoot = *(struct btrfs_root_item *) path_current_data(&path); + btrfs_init_crc32c(); - free_path(&path); + btrfs_read_sys_chunk_array(); + btrfs_read_chunk_tree(); - TRACE("BtrFsMount success\n"); + /* setup roots */ + fs_root_item.bytenr = BtrFsInfo->SuperBlock.root; + fs_root_item.level = BtrFsInfo->SuperBlock.root_level; - return &BtrFsFuncTable; - } - else + init_path(&path); + if (!BtrFsSearchTreeType(&fs_root_item, BTRFS_FS_TREE_OBJECTID, BTRFS_ROOT_ITEM_KEY, &path)) { + FrLdrTempFree(BtrFsInfo, TAG_BTRFS_INFO); + free_path(&path); return NULL; } + + BtrFsInfo->FsRoot = *(struct btrfs_root_item *) path_current_data(&path); + + free_path(&path); + + TRACE("BtrFsMount(%lu) success\n", DeviceId); + return &BtrFsFuncTable; } diff --git a/boot/freeldr/freeldr/lib/fs/ext2.c b/boot/freeldr/freeldr/lib/fs/ext2.c index 30ec019508e..e0f2bc077d8 100644 --- a/boot/freeldr/freeldr/lib/fs/ext2.c +++ b/boot/freeldr/freeldr/lib/fs/ext2.c @@ -1302,6 +1302,8 @@ const DEVVTBL* Ext2Mount(ULONG DeviceId) ULONG Count; ARC_STATUS Status; + TRACE("Enter Ext2Mount(%lu)\n", DeviceId); + // // Read the SuperBlock // @@ -1329,6 +1331,9 @@ const DEVVTBL* Ext2Mount(ULONG DeviceId) if (!DiskGetBootVolume(&DriveNumber, &StartSector, &SectorCount, &Type)) return NULL; Ext2OpenVolume(DriveNumber, StartSector, SectorCount); + + /* Return success */ + TRACE("Ext2Mount(%lu) success\n", DeviceId); return &Ext2FuncTable; } else @@ -1336,4 +1341,3 @@ const DEVVTBL* Ext2Mount(ULONG DeviceId) } #endif - diff --git a/boot/freeldr/freeldr/lib/fs/fat.c b/boot/freeldr/freeldr/lib/fs/fat.c index 17f341c87ec..b2a91e3500c 100644 --- a/boot/freeldr/freeldr/lib/fs/fat.c +++ b/boot/freeldr/freeldr/lib/fs/fat.c @@ -27,7 +27,7 @@ DBG_DEFAULT_CHANNEL(FILESYSTEM); ULONG FatDetermineFatType(PFAT_BOOTSECTOR FatBootSector, ULONGLONG PartitionSectorCount); PVOID FatBufferDirectory(PFAT_VOLUME_INFO Volume, ULONG DirectoryStartCluster, ULONG* EntryCountPointer, BOOLEAN RootDirectory); BOOLEAN FatSearchDirectoryBufferForFile(PFAT_VOLUME_INFO Volume, PVOID DirectoryBuffer, ULONG EntryCount, PCHAR FileName, PFAT_FILE_INFO FatFileInfoPointer); -ARC_STATUS FatLookupFile(PFAT_VOLUME_INFO Volume, PCSTR FileName, ULONG DeviceId, PFAT_FILE_INFO FatFileInfoPointer); +ARC_STATUS FatLookupFile(PFAT_VOLUME_INFO Volume, PCSTR FileName, PFAT_FILE_INFO FatFileInfoPointer); void FatParseShortFileName(PCHAR Buffer, PDIRENTRY DirEntry); BOOLEAN FatGetFatEntry(PFAT_VOLUME_INFO Volume, ULONG Cluster, ULONG* ClusterPointer); ULONG FatCountClustersInChain(PFAT_VOLUME_INFO Volume, ULONG StartCluster); @@ -762,7 +762,7 @@ static BOOLEAN FatXSearchDirectoryBufferForFile(PFAT_VOLUME_INFO Volume, PVOID D * specified filename and fills in an FAT_FILE_INFO structure * with info describing the file, etc. returns ARC error code */ -ARC_STATUS FatLookupFile(PFAT_VOLUME_INFO Volume, PCSTR FileName, ULONG DeviceId, PFAT_FILE_INFO FatFileInfoPointer) +ARC_STATUS FatLookupFile(PFAT_VOLUME_INFO Volume, PCSTR FileName, PFAT_FILE_INFO FatFileInfoPointer) { UINT32 i; ULONG NumberOfPathParts; @@ -986,7 +986,8 @@ BOOLEAN FatGetFatEntry(PFAT_VOLUME_INFO Volume, ULONG Cluster, ULONG* ClusterPoi if (!FatReadVolumeSectors(Volume, ThisFatSecNum, 1, ReadBuffer)) { - return FALSE; + Success = FALSE; + break; } // Get the fat entry @@ -1439,7 +1440,7 @@ ARC_STATUS FatOpen(CHAR* Path, OPENMODE OpenMode, ULONG* FileId) TRACE("FatOpen() FileName = %s\n", Path); RtlZeroMemory(&TempFileInfo, sizeof(TempFileInfo)); - Status = FatLookupFile(FatVolume, Path, DeviceId, &TempFileInfo); + Status = FatLookupFile(FatVolume, Path, &TempFileInfo); if (Status != ESUCCESS) return ENOENT; @@ -1522,6 +1523,8 @@ const DEVVTBL* FatMount(ULONG DeviceId) ULARGE_INTEGER SectorCount; ARC_STATUS Status; + TRACE("Enter FatMount(%lu)\n", DeviceId); + // // Allocate data for volume information // @@ -1533,8 +1536,7 @@ const DEVVTBL* FatMount(ULONG DeviceId) // // Read the BootSector // - Position.HighPart = 0; - Position.LowPart = 0; + Position.QuadPart = 0; Status = ArcSeek(DeviceId, &Position, SeekAbsolute); if (Status != ESUCCESS) { @@ -1569,8 +1571,7 @@ const DEVVTBL* FatMount(ULONG DeviceId) FrLdrTempFree(Volume, TAG_FAT_VOLUME); return NULL; } - SectorCount.HighPart = FileInformation.EndingAddress.HighPart; - SectorCount.LowPart = FileInformation.EndingAddress.LowPart; + SectorCount.QuadPart = FileInformation.EndingAddress.QuadPart; SectorCount.QuadPart /= SECTOR_SIZE; // @@ -1595,5 +1596,6 @@ const DEVVTBL* FatMount(ULONG DeviceId) // // Return success // + TRACE("FatMount(%lu) success\n", DeviceId); return &FatFuncTable; } diff --git a/boot/freeldr/freeldr/lib/fs/fs.c b/boot/freeldr/freeldr/lib/fs/fs.c index b1de1603fd5..b4e3113feca 100644 --- a/boot/freeldr/freeldr/lib/fs/fs.c +++ b/boot/freeldr/freeldr/lib/fs/fs.c @@ -263,7 +263,7 @@ VOID FileSystemError(PCSTR ErrorString) UiMessageBox(ErrorString); } -PFILE FsOpenFile(PCSTR FileName) +ULONG FsOpenFile(PCSTR FileName) { CHAR FullPath[MAX_PATH] = ""; ULONG FileId; @@ -301,81 +301,9 @@ PFILE FsOpenFile(PCSTR FileName) // Check for success // if (Status == ESUCCESS) - return (PFILE)FileId; + return FileId; else - return (PFILE)0; -} - -VOID FsCloseFile(PFILE FileHandle) -{ - ULONG FileId = (ULONG)FileHandle; - - // - // Close the handle. Do not check for error, - // this function is supposed to always succeed. - // - ArcClose(FileId); -} - -/* - * ReadFile() - * returns number of bytes read or EOF - */ -BOOLEAN FsReadFile(PFILE FileHandle, ULONG BytesToRead, ULONG* BytesRead, PVOID Buffer) -{ - ULONG FileId = (ULONG)FileHandle; - - // - // Read the file - // - return (ArcRead(FileId, Buffer, BytesToRead, BytesRead) == ESUCCESS); -} - -BOOLEAN FsGetFileInformation(PFILE FileHandle, FILEINFORMATION* Information) -{ - ULONG FileId = (ULONG)FileHandle; - - // - // Get file information - // - return (ArcGetFileInformation(FileId, Information) == ESUCCESS); -} - -ULONG FsGetFileSize(PFILE FileHandle) -{ - ULONG FileId = (ULONG)FileHandle; - FILEINFORMATION Information; - ARC_STATUS Status; - - // - // Query file informations - // - Status = ArcGetFileInformation(FileId, &Information); - - // - // Check for error - // - if (Status != 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. Do not check for error, - // this function is supposed to always succeed. - // - Position.HighPart = 0; - Position.LowPart = NewFilePointer; - ArcSeek(FileId, &Position, SeekAbsolute); } /* diff --git a/boot/freeldr/freeldr/lib/fs/iso.c b/boot/freeldr/freeldr/lib/fs/iso.c index cdf0281a563..4c6a3e1dab4 100644 --- a/boot/freeldr/freeldr/lib/fs/iso.c +++ b/boot/freeldr/freeldr/lib/fs/iso.c @@ -496,6 +496,8 @@ const DEVVTBL* IsoMount(ULONG DeviceId) ULONG Count; ARC_STATUS Status; + TRACE("Enter IsoMount(%lu)\n", DeviceId); + // // Read The Primary Volume Descriptor // @@ -512,10 +514,12 @@ const DEVVTBL* IsoMount(ULONG DeviceId) // Check if PVD is valid. If yes, return ISO9660 function table // if (Pvd->VdType == 1 && RtlEqualMemory(Pvd->StandardId, "CD001", 5)) + { + TRACE("IsoMount(%lu) success\n", DeviceId); return &Iso9660FuncTable; - else - return NULL; + } + + return NULL; } #endif - diff --git a/boot/freeldr/freeldr/lib/fs/ntfs.c b/boot/freeldr/freeldr/lib/fs/ntfs.c index 359bebc2ea4..e68e4044977 100644 --- a/boot/freeldr/freeldr/lib/fs/ntfs.c +++ b/boot/freeldr/freeldr/lib/fs/ntfs.c @@ -877,6 +877,8 @@ const DEVVTBL* NtfsMount(ULONG DeviceId) ULONG Count; ARC_STATUS Status; + TRACE("Enter NtfsMount(%lu)\n", DeviceId); + // // Allocate data for volume information // @@ -888,8 +890,7 @@ const DEVVTBL* NtfsMount(ULONG DeviceId) // // Read the BootSector // - Position.HighPart = 0; - Position.LowPart = 0; + Position.QuadPart = 0; Status = ArcSeek(DeviceId, &Position, SeekAbsolute); if (Status != ESUCCESS) { @@ -997,6 +998,7 @@ const DEVVTBL* NtfsMount(ULONG DeviceId) // // Return success // + TRACE("NtfsMount(%lu) success\n", DeviceId); return &NtfsFuncTable; } diff --git a/boot/freeldr/freeldr/lib/mm/mm.c b/boot/freeldr/freeldr/lib/mm/mm.c index a2b49b3f9f0..7153c70f62f 100644 --- a/boot/freeldr/freeldr/lib/mm/mm.c +++ b/boot/freeldr/freeldr/lib/mm/mm.c @@ -243,7 +243,7 @@ VOID DumpMemoryAllocMap(VOID) DbgPrint("*"); break; case LoaderBad: - DbgPrint( "-"); + DbgPrint("-"); break; case LoaderLoadedProgram: DbgPrint("O"); @@ -252,7 +252,7 @@ VOID DumpMemoryAllocMap(VOID) DbgPrint("T"); break; case LoaderFirmwarePermanent: - DbgPrint( "P"); + DbgPrint("P"); break; case LoaderOsloaderHeap: DbgPrint("H"); diff --git a/boot/freeldr/freeldr/linuxboot.c b/boot/freeldr/freeldr/linuxboot.c index b1378df2fc0..9f0a53ef9b7 100644 --- a/boot/freeldr/freeldr/linuxboot.c +++ b/boot/freeldr/freeldr/linuxboot.c @@ -17,6 +17,11 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +/* + * The x86 Linux Boot Protocol is explained at: + * https://www.kernel.org/doc/Documentation/x86/boot.txt + */ + #ifndef _M_ARM #ifdef _M_IX86 @@ -81,8 +86,10 @@ LoadAndBootLinux( IN PCHAR Envp[]) { PCSTR Description; - PFILE LinuxKernel = 0; - PFILE LinuxInitrdFile = 0; + ULONG LinuxKernel = 0; + ULONG LinuxInitrdFile = 0; + ARC_STATUS Status; + FILEINFORMATION FileInfo; Description = GetArgumentValue(Argc, Argv, "LoadIdentifier"); if (Description) @@ -129,10 +136,22 @@ LoadAndBootLinux( goto LinuxBootFailed; /* Calc kernel size */ - LinuxKernelSize = FsGetFileSize(LinuxKernel) - (512 + SetupSectorSize); + Status = ArcGetFileInformation(LinuxKernel, &FileInfo); + if (Status != ESUCCESS || FileInfo.EndingAddress.HighPart != 0) + LinuxKernelSize = 0; + else + LinuxKernelSize = FileInfo.EndingAddress.LowPart - (512 + SetupSectorSize); - /* Get the file size */ - LinuxInitrdSize = FsGetFileSize(LinuxInitrdFile); + /* Get the initrd file image (if necessary) */ + LinuxInitrdSize = 0; + if (LinuxInitrdName) + { + Status = ArcGetFileInformation(LinuxInitrdFile, &FileInfo); + if (Status != ESUCCESS || FileInfo.EndingAddress.HighPart != 0) + LinuxInitrdSize = 0; + else + LinuxInitrdSize = FileInfo.EndingAddress.LowPart; + } /* Read the kernel */ if (!LinuxReadKernel(LinuxKernel)) @@ -184,10 +203,10 @@ LoadAndBootLinux( LinuxBootFailed: if (LinuxKernel) - FsCloseFile(LinuxKernel); + ArcClose(LinuxKernel); if (LinuxInitrdFile) - FsCloseFile(LinuxInitrdFile); + ArcClose(LinuxInitrdFile); if (LinuxBootSector != NULL) MmFreeMemory(LinuxBootSector); @@ -224,12 +243,14 @@ LinuxParseIniSection( IN ULONG Argc, IN PCHAR Argv[]) { +#if 0 LinuxBootPath = GetArgumentValue(Argc, Argv, "BootPath"); if (!LinuxBootPath) { UiMessageBox("Boot path not specified for selected OS!"); return FALSE; } +#endif /* Get the kernel name */ LinuxKernelName = GetArgumentValue(Argc, Argv, "Kernel"); @@ -255,16 +276,20 @@ LinuxParseIniSection( return TRUE; } -BOOLEAN LinuxReadBootSector(PFILE LinuxKernelFile) +BOOLEAN LinuxReadBootSector(ULONG LinuxKernelFile) { + LARGE_INTEGER Position; + /* Allocate memory for boot sector */ LinuxBootSector = MmAllocateMemoryWithType(512, LoaderSystemCode); if (LinuxBootSector == NULL) return FALSE; /* Read linux boot sector */ - FsSetFilePointer(LinuxKernelFile, 0); - if (!FsReadFile(LinuxKernelFile, 512, NULL, LinuxBootSector)) + Position.QuadPart = 0; + if (ArcSeek(LinuxKernelFile, &Position, SeekAbsolute) != ESUCCESS) + return FALSE; + if (ArcRead(LinuxKernelFile, LinuxBootSector, 512, NULL) != ESUCCESS) return FALSE; /* Check for validity */ @@ -288,13 +313,16 @@ BOOLEAN LinuxReadBootSector(PFILE LinuxKernelFile) return TRUE; } -BOOLEAN LinuxReadSetupSector(PFILE LinuxKernelFile) +BOOLEAN LinuxReadSetupSector(ULONG LinuxKernelFile) { + LARGE_INTEGER Position; UCHAR TempLinuxSetupSector[512]; /* Read first linux setup sector */ - FsSetFilePointer(LinuxKernelFile, 512); - if (!FsReadFile(LinuxKernelFile, 512, NULL, TempLinuxSetupSector)) + Position.QuadPart = 512; + if (ArcSeek(LinuxKernelFile, &Position, SeekAbsolute) != ESUCCESS) + return FALSE; + if (ArcRead(LinuxKernelFile, TempLinuxSetupSector, 512, NULL) != ESUCCESS) return FALSE; /* Check the kernel version */ @@ -316,8 +344,10 @@ BOOLEAN LinuxReadSetupSector(PFILE LinuxKernelFile) RtlCopyMemory(LinuxSetupSector, TempLinuxSetupSector, 512); /* Read in the rest of the linux setup sectors */ - FsSetFilePointer(LinuxKernelFile, 1024); - if (!FsReadFile(LinuxKernelFile, SetupSectorSize - 512, NULL, (PVOID)((ULONG_PTR)LinuxSetupSector + 512))) + Position.QuadPart = 1024; + if (ArcSeek(LinuxKernelFile, &Position, SeekAbsolute) != ESUCCESS) + return FALSE; + if (ArcRead(LinuxKernelFile, (PVOID)((ULONG_PTR)LinuxSetupSector + 512), SetupSectorSize - 512, NULL) != ESUCCESS) return FALSE; // DbgDumpBuffer(DPRINT_LINUX, LinuxSetupSector, SetupSectorSize); @@ -341,11 +371,12 @@ BOOLEAN LinuxReadSetupSector(PFILE LinuxKernelFile) return TRUE; } -BOOLEAN LinuxReadKernel(PFILE LinuxKernelFile) +BOOLEAN LinuxReadKernel(ULONG LinuxKernelFile) { + PVOID LoadAddress; + LARGE_INTEGER Position; ULONG BytesLoaded; CHAR StatusText[260]; - PVOID LoadAddress; RtlStringCbPrintfA(StatusText, sizeof(StatusText), "Loading %s", LinuxKernelName); UiDrawStatusText(StatusText); @@ -360,10 +391,12 @@ BOOLEAN LinuxReadKernel(PFILE LinuxKernelFile) LoadAddress = LinuxKernelLoadAddress; /* Read linux kernel to 0x100000 (1mb) */ - FsSetFilePointer(LinuxKernelFile, 512 + SetupSectorSize); + Position.QuadPart = 512 + SetupSectorSize; + if (ArcSeek(LinuxKernelFile, &Position, SeekAbsolute) != ESUCCESS) + return FALSE; for (BytesLoaded=0; BytesLoaded