[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??)
This commit is contained in:
Hermès Bélusca-Maïto 2019-08-10 13:44:33 +02:00
parent 4a230d8341
commit 8d94b2a68d
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
14 changed files with 162 additions and 192 deletions

View file

@ -431,6 +431,7 @@ FrLdrMapModule(FILE *KernelImage, PCHAR ImageName, PCHAR MemLoadAddr, ULONG Kern
PCHAR sptr; PCHAR sptr;
Elf32_Ehdr ehdr; Elf32_Ehdr ehdr;
Elf32_Shdr *shdr; Elf32_Shdr *shdr;
LARGE_INTEGER Position;
LPSTR TempName; LPSTR TempName;
TempName = strrchr(ImageName, '\\'); TempName = strrchr(ImageName, '\\');
@ -451,7 +452,7 @@ FrLdrMapModule(FILE *KernelImage, PCHAR ImageName, PCHAR MemLoadAddr, ULONG Kern
//printf("Loading file (elf at %x)\n", KernelAddr); //printf("Loading file (elf at %x)\n", KernelAddr);
/* Load the first 1024 bytes of the kernel image so we can read the PE header */ /* 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 */ /* Fail if we couldn't read */
printf("Couldn't read the elf header\n"); 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); sptr = (PCHAR)FrLdrTempAlloc(shnum * shsize, TAG_MBOOT);
/* Read section headers */ /* Read section headers */
FsSetFilePointer(KernelImage, ehdr.e_shoff); Position.QuadPart = ehdr.e_shoff;
FsReadFile(KernelImage, shsize * shnum, NULL, sptr); ArcSeek(KernelImage, &Position, SeekAbsolute);
ArcRead(KernelImage, sptr, shsize * shnum, NULL);
/* Now we'll get the PE Header */ /* Now we'll get the PE Header */
for( i = 0; i < shnum; i++ ) for( i = 0; i < shnum; i++ )
@ -478,8 +480,9 @@ FrLdrMapModule(FILE *KernelImage, PCHAR ImageName, PCHAR MemLoadAddr, ULONG Kern
/* Find the PE Header */ /* Find the PE Header */
if (shdr->sh_type == TYPE_PEHEADER) if (shdr->sh_type == TYPE_PEHEADER)
{ {
FsSetFilePointer(KernelImage, shdr->sh_offset); Position.QuadPart = shdr->sh_offset;
FsReadFile(KernelImage, shdr->sh_size, NULL, MemLoadAddr); ArcSeek(KernelImage, &Position, SeekAbsolute);
ArcRead(KernelImage, MemLoadAddr, shdr->sh_size, NULL);
ImageHeader = (PIMAGE_DOS_HEADER)MemLoadAddr; ImageHeader = (PIMAGE_DOS_HEADER)MemLoadAddr;
NtHeader = (PIMAGE_NT_HEADERS)((PCHAR)MemLoadAddr + SWAPD(ImageHeader->e_lfanew)); NtHeader = (PIMAGE_NT_HEADERS)((PCHAR)MemLoadAddr + SWAPD(ImageHeader->e_lfanew));
#if 0 #if 0
@ -527,8 +530,9 @@ FrLdrMapModule(FILE *KernelImage, PCHAR ImageName, PCHAR MemLoadAddr, ULONG Kern
{ {
/* Content area */ /* Content area */
printf("Loading section %d at %x (real: %x:%d)\n", i, KernelAddr + SectionAddr, MemLoadAddr+SectionAddr, shdr->sh_size); printf("Loading section %d at %x (real: %x:%d)\n", i, KernelAddr + SectionAddr, MemLoadAddr+SectionAddr, shdr->sh_size);
FsSetFilePointer(KernelImage, shdr->sh_offset); Position.QuadPart = shdr->sh_offset;
FsReadFile(KernelImage, shdr->sh_size, NULL, MemLoadAddr + SectionAddr); ArcSeek(KernelImage, &Position, SeekAbsolute);
ArcRead(KernelImage, MemLoadAddr + SectionAddr, shdr->sh_size, NULL);
} }
else else
{ {
@ -565,15 +569,17 @@ FrLdrMapModule(FILE *KernelImage, PCHAR ImageName, PCHAR MemLoadAddr, ULONG Kern
if (!ELF_SECTION(targetSection)->sh_addr) continue; if (!ELF_SECTION(targetSection)->sh_addr) continue;
RelocSection = FrLdrTempAlloc(shdr->sh_size, TAG_MBOOT); RelocSection = FrLdrTempAlloc(shdr->sh_size, TAG_MBOOT);
FsSetFilePointer(KernelImage, relstart); Position.QuadPart = relstart;
FsReadFile(KernelImage, shdr->sh_size, NULL, RelocSection); ArcSeek(KernelImage, &Position, SeekAbsolute);
ArcRead(KernelImage, RelocSection, shdr->sh_size, NULL);
/* Get the symbol section */ /* Get the symbol section */
shdr = ELF_SECTION(shdr->sh_link); shdr = ELF_SECTION(shdr->sh_link);
SymbolSection = FrLdrTempAlloc(shdr->sh_size, TAG_MBOOT); SymbolSection = FrLdrTempAlloc(shdr->sh_size, TAG_MBOOT);
FsSetFilePointer(KernelImage, shdr->sh_offset); Position.QuadPart = shdr->sh_offset;
FsReadFile(KernelImage, shdr->sh_size, NULL, SymbolSection); ArcSeek(KernelImage, &Position, SeekAbsolute);
ArcRead(KernelImage, SymbolSection, shdr->sh_size, NULL);
for(j = 0; j < numreloc; j++) for(j = 0; j < numreloc; j++)
{ {
@ -705,6 +711,8 @@ FrLdrLoadModule(FILE *ModuleImage,
LPCSTR ModuleName, LPCSTR ModuleName,
PULONG ModuleSize) PULONG ModuleSize)
{ {
ARC_STATUS Status;
FILEINFORMATION FileInfo;
ULONG LocalModuleSize; ULONG LocalModuleSize;
ULONG_PTR ThisModuleBase = NextModuleBase; ULONG_PTR ThisModuleBase = NextModuleBase;
PLOADER_MODULE ModuleData; PLOADER_MODULE ModuleData;
@ -726,9 +734,12 @@ FrLdrLoadModule(FILE *ModuleImage,
} while(TempName); } while(TempName);
NameBuffer = reactos_module_strings[LoaderBlock.ModsCount]; NameBuffer = reactos_module_strings[LoaderBlock.ModsCount];
/* Get Module Size */ /* 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 */ /* Fill out Module Data Structure */
ModuleData->ModStart = NextModuleBase; ModuleData->ModStart = NextModuleBase;
@ -739,7 +750,7 @@ FrLdrLoadModule(FILE *ModuleImage,
ModuleData->String = (ULONG_PTR)NameBuffer; ModuleData->String = (ULONG_PTR)NameBuffer;
/* Load the file image */ /* 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 */ /* Move to next memory block and increase Module Count */
NextModuleBase = ROUND_UP(ModuleData->ModEnd, PAGE_SIZE); NextModuleBase = ROUND_UP(ModuleData->ModEnd, PAGE_SIZE);

View file

@ -120,7 +120,7 @@ BOOLEAN
NTAPI NTAPI
RamDiskLoadVirtualFile(IN PCHAR FileName) RamDiskLoadVirtualFile(IN PCHAR FileName)
{ {
PFILE RamFile; ULONG RamFileId;
ULONG TotalRead, ChunkSize, Count; ULONG TotalRead, ChunkSize, Count;
PCHAR MsgBuffer = "Loading RamDisk..."; PCHAR MsgBuffer = "Loading RamDisk...";
ULONG PercentPerChunk, Percent; ULONG PercentPerChunk, Percent;
@ -137,17 +137,17 @@ RamDiskLoadVirtualFile(IN PCHAR FileName)
// //
// Try opening the ramdisk file // Try opening the ramdisk file
// //
RamFile = FsOpenFile(FileName); RamFileId = FsOpenFile(FileName);
if (!RamFile) if (!RamFileId)
return FALSE; return FALSE;
// //
// Get the file size // Get the file size
// //
Status = ArcGetFileInformation(RamFile, &Information); Status = ArcGetFileInformation(RamFileId, &Information);
if (Status != ESUCCESS) if (Status != ESUCCESS)
{ {
FsCloseFile(RamFile); ArcClose(RamFileId);
return FALSE; return FALSE;
} }
@ -157,7 +157,7 @@ RamDiskLoadVirtualFile(IN PCHAR FileName)
if (Information.EndingAddress.HighPart != 0) if (Information.EndingAddress.HighPart != 0)
{ {
UiMessageBox("RAM disk too big."); UiMessageBox("RAM disk too big.");
FsCloseFile(RamFile); ArcClose(RamFileId);
return FALSE; return FALSE;
} }
gRamDiskSize = Information.EndingAddress.LowPart; gRamDiskSize = Information.EndingAddress.LowPart;
@ -174,7 +174,7 @@ RamDiskLoadVirtualFile(IN PCHAR FileName)
if (!gRamDiskBase) if (!gRamDiskBase)
{ {
UiMessageBox("Failed to allocate memory for RAM disk."); UiMessageBox("Failed to allocate memory for RAM disk.");
FsCloseFile(RamFile); ArcClose(RamFileId);
return FALSE; return FALSE;
} }
@ -205,10 +205,10 @@ RamDiskLoadVirtualFile(IN PCHAR FileName)
// //
Position.HighPart = 0; Position.HighPart = 0;
Position.LowPart = TotalRead; Position.LowPart = TotalRead;
Status = ArcSeek(RamFile, &Position, SeekAbsolute); Status = ArcSeek(RamFileId, &Position, SeekAbsolute);
if (Status == ESUCCESS) if (Status == ESUCCESS)
{ {
Status = ArcRead(RamFile, Status = ArcRead(RamFileId,
(PVOID)((ULONG_PTR)gRamDiskBase + TotalRead), (PVOID)((ULONG_PTR)gRamDiskBase + TotalRead),
ChunkSize, ChunkSize,
&Count); &Count);
@ -222,13 +222,13 @@ RamDiskLoadVirtualFile(IN PCHAR FileName)
MmFreeMemory(gRamDiskBase); MmFreeMemory(gRamDiskBase);
gRamDiskBase = NULL; gRamDiskBase = NULL;
gRamDiskSize = 0; gRamDiskSize = 0;
FsCloseFile(RamFile); ArcClose(RamFileId);
UiMessageBox("Failed to read RAM disk."); UiMessageBox("Failed to read RAM disk.");
return FALSE; return FALSE;
} }
} }
FsCloseFile(RamFile); ArcClose(RamFileId);
/* Setup the RAMDISK device */ /* Setup the RAMDISK device */
RamDiskInitialize(); RamDiskInitialize();

View file

@ -29,12 +29,7 @@ typedef struct tagDEVVTBL
LPCWSTR ServiceName; LPCWSTR ServiceName;
} DEVVTBL; } DEVVTBL;
#define FS_FAT 1 #define MAX_FDS 60
#define FS_NTFS 2
#define FS_EXT2 3
#define FS_ISO9660 5
#define PFILE ULONG
ARC_STATUS ArcOpen(CHAR* Path, OPENMODE OpenMode, ULONG* FileId); ARC_STATUS ArcOpen(CHAR* Path, OPENMODE OpenMode, ULONG* FileId);
ARC_STATUS ArcClose(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); ARC_STATUS ArcGetFileInformation(ULONG FileId, FILEINFORMATION* Information);
VOID FileSystemError(PCSTR ErrorString); VOID FileSystemError(PCSTR ErrorString);
PFILE FsOpenFile(PCSTR FileName); ULONG 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 FsGetNumPathParts(PCSTR Path); ULONG FsGetNumPathParts(PCSTR Path);
VOID FsGetFirstNameFromPath(PCHAR Buffer, PCSTR Path); VOID FsGetFirstNameFromPath(PCHAR Buffer, PCSTR Path);
@ -58,5 +48,3 @@ VOID FsSetDeviceSpecific(ULONG FileId, VOID* Specific);
VOID* FsGetDeviceSpecific(ULONG FileId); VOID* FsGetDeviceSpecific(ULONG FileId);
ULONG FsGetDeviceId(ULONG FileId); ULONG FsGetDeviceId(ULONG FileId);
VOID FsInit(VOID); VOID FsInit(VOID);
#define MAX_FDS 60

View file

@ -151,7 +151,6 @@ typedef struct
ULONG FileSize; /* File size */ ULONG FileSize; /* File size */
ULONG FilePointer; /* File pointer */ ULONG FilePointer; /* File pointer */
ULONG* FileFatChain; /* File fat chain array */ ULONG* FileFatChain; /* File fat chain array */
ULONG DriveNumber;
PFAT_VOLUME_INFO Volume; PFAT_VOLUME_INFO Volume;
} FAT_FILE_INFO, * PFAT_FILE_INFO; } FAT_FILE_INFO, * PFAT_FILE_INFO;

View file

@ -142,11 +142,11 @@ LinuxParseIniSection(
IN ULONG Argc, IN ULONG Argc,
IN PCHAR Argv[]); IN PCHAR Argv[]);
BOOLEAN LinuxReadBootSector(PFILE LinuxKernelFile); BOOLEAN LinuxReadBootSector(ULONG LinuxKernelFile);
BOOLEAN LinuxReadSetupSector(PFILE LinuxKernelFile); BOOLEAN LinuxReadSetupSector(ULONG LinuxKernelFile);
BOOLEAN LinuxReadKernel(PFILE LinuxKernelFile); BOOLEAN LinuxReadKernel(ULONG LinuxKernelFile);
BOOLEAN LinuxCheckKernelVersion(VOID); BOOLEAN LinuxCheckKernelVersion(VOID);
BOOLEAN LinuxReadInitrd(PFILE LinuxInitrdFile); BOOLEAN LinuxReadInitrd(ULONG LinuxInitrdFile);
#endif // _M_IX86 #endif // _M_IX86

View file

@ -1229,7 +1229,7 @@ const DEVVTBL *BtrFsMount(ULONG DeviceId)
struct btrfs_path path; struct btrfs_path path;
struct btrfs_root_item fs_root_item; 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); BtrFsInfo = FrLdrTempAlloc(sizeof(struct BTRFS_INFO), TAG_BTRFS_INFO);
if (!BtrFsInfo) if (!BtrFsInfo)
@ -1244,38 +1244,36 @@ const DEVVTBL *BtrFsMount(ULONG DeviceId)
} }
/* Check if SuperBlock is valid. If yes, return BTRFS function table */ /* 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;
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 success\n");
return &BtrFsFuncTable;
}
else
{ {
FrLdrTempFree(BtrFsInfo, TAG_BTRFS_INFO);
return NULL; return NULL;
} }
BtrFsInfo->DeviceId = DeviceId;
TRACE("BtrFsMount(%lu) superblock magic ok\n", DeviceId);
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;
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;
} }

View file

@ -1302,6 +1302,8 @@ const DEVVTBL* Ext2Mount(ULONG DeviceId)
ULONG Count; ULONG Count;
ARC_STATUS Status; ARC_STATUS Status;
TRACE("Enter Ext2Mount(%lu)\n", DeviceId);
// //
// Read the SuperBlock // Read the SuperBlock
// //
@ -1329,6 +1331,9 @@ const DEVVTBL* Ext2Mount(ULONG DeviceId)
if (!DiskGetBootVolume(&DriveNumber, &StartSector, &SectorCount, &Type)) if (!DiskGetBootVolume(&DriveNumber, &StartSector, &SectorCount, &Type))
return NULL; return NULL;
Ext2OpenVolume(DriveNumber, StartSector, SectorCount); Ext2OpenVolume(DriveNumber, StartSector, SectorCount);
/* Return success */
TRACE("Ext2Mount(%lu) success\n", DeviceId);
return &Ext2FuncTable; return &Ext2FuncTable;
} }
else else
@ -1336,4 +1341,3 @@ const DEVVTBL* Ext2Mount(ULONG DeviceId)
} }
#endif #endif

View file

@ -27,7 +27,7 @@ DBG_DEFAULT_CHANNEL(FILESYSTEM);
ULONG FatDetermineFatType(PFAT_BOOTSECTOR FatBootSector, ULONGLONG PartitionSectorCount); ULONG FatDetermineFatType(PFAT_BOOTSECTOR FatBootSector, ULONGLONG PartitionSectorCount);
PVOID FatBufferDirectory(PFAT_VOLUME_INFO Volume, ULONG DirectoryStartCluster, ULONG* EntryCountPointer, BOOLEAN RootDirectory); 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); 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); void FatParseShortFileName(PCHAR Buffer, PDIRENTRY DirEntry);
BOOLEAN FatGetFatEntry(PFAT_VOLUME_INFO Volume, ULONG Cluster, ULONG* ClusterPointer); BOOLEAN FatGetFatEntry(PFAT_VOLUME_INFO Volume, ULONG Cluster, ULONG* ClusterPointer);
ULONG FatCountClustersInChain(PFAT_VOLUME_INFO Volume, ULONG StartCluster); 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 * specified filename and fills in an FAT_FILE_INFO structure
* with info describing the file, etc. returns ARC error code * 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; UINT32 i;
ULONG NumberOfPathParts; ULONG NumberOfPathParts;
@ -986,7 +986,8 @@ BOOLEAN FatGetFatEntry(PFAT_VOLUME_INFO Volume, ULONG Cluster, ULONG* ClusterPoi
if (!FatReadVolumeSectors(Volume, ThisFatSecNum, 1, ReadBuffer)) if (!FatReadVolumeSectors(Volume, ThisFatSecNum, 1, ReadBuffer))
{ {
return FALSE; Success = FALSE;
break;
} }
// Get the fat entry // Get the fat entry
@ -1439,7 +1440,7 @@ ARC_STATUS FatOpen(CHAR* Path, OPENMODE OpenMode, ULONG* FileId)
TRACE("FatOpen() FileName = %s\n", Path); TRACE("FatOpen() FileName = %s\n", Path);
RtlZeroMemory(&TempFileInfo, sizeof(TempFileInfo)); RtlZeroMemory(&TempFileInfo, sizeof(TempFileInfo));
Status = FatLookupFile(FatVolume, Path, DeviceId, &TempFileInfo); Status = FatLookupFile(FatVolume, Path, &TempFileInfo);
if (Status != ESUCCESS) if (Status != ESUCCESS)
return ENOENT; return ENOENT;
@ -1522,6 +1523,8 @@ const DEVVTBL* FatMount(ULONG DeviceId)
ULARGE_INTEGER SectorCount; ULARGE_INTEGER SectorCount;
ARC_STATUS Status; ARC_STATUS Status;
TRACE("Enter FatMount(%lu)\n", DeviceId);
// //
// Allocate data for volume information // Allocate data for volume information
// //
@ -1533,8 +1536,7 @@ const DEVVTBL* FatMount(ULONG DeviceId)
// //
// Read the BootSector // Read the BootSector
// //
Position.HighPart = 0; Position.QuadPart = 0;
Position.LowPart = 0;
Status = ArcSeek(DeviceId, &Position, SeekAbsolute); Status = ArcSeek(DeviceId, &Position, SeekAbsolute);
if (Status != ESUCCESS) if (Status != ESUCCESS)
{ {
@ -1569,8 +1571,7 @@ const DEVVTBL* FatMount(ULONG DeviceId)
FrLdrTempFree(Volume, TAG_FAT_VOLUME); FrLdrTempFree(Volume, TAG_FAT_VOLUME);
return NULL; return NULL;
} }
SectorCount.HighPart = FileInformation.EndingAddress.HighPart; SectorCount.QuadPart = FileInformation.EndingAddress.QuadPart;
SectorCount.LowPart = FileInformation.EndingAddress.LowPart;
SectorCount.QuadPart /= SECTOR_SIZE; SectorCount.QuadPart /= SECTOR_SIZE;
// //
@ -1595,5 +1596,6 @@ const DEVVTBL* FatMount(ULONG DeviceId)
// //
// Return success // Return success
// //
TRACE("FatMount(%lu) success\n", DeviceId);
return &FatFuncTable; return &FatFuncTable;
} }

View file

@ -263,7 +263,7 @@ VOID FileSystemError(PCSTR ErrorString)
UiMessageBox(ErrorString); UiMessageBox(ErrorString);
} }
PFILE FsOpenFile(PCSTR FileName) ULONG FsOpenFile(PCSTR FileName)
{ {
CHAR FullPath[MAX_PATH] = ""; CHAR FullPath[MAX_PATH] = "";
ULONG FileId; ULONG FileId;
@ -301,81 +301,9 @@ PFILE FsOpenFile(PCSTR FileName)
// Check for success // Check for success
// //
if (Status == ESUCCESS) if (Status == ESUCCESS)
return (PFILE)FileId; return FileId;
else 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 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);
} }
/* /*

View file

@ -496,6 +496,8 @@ const DEVVTBL* IsoMount(ULONG DeviceId)
ULONG Count; ULONG Count;
ARC_STATUS Status; ARC_STATUS Status;
TRACE("Enter IsoMount(%lu)\n", DeviceId);
// //
// Read The Primary Volume Descriptor // 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 // Check if PVD is valid. If yes, return ISO9660 function table
// //
if (Pvd->VdType == 1 && RtlEqualMemory(Pvd->StandardId, "CD001", 5)) if (Pvd->VdType == 1 && RtlEqualMemory(Pvd->StandardId, "CD001", 5))
{
TRACE("IsoMount(%lu) success\n", DeviceId);
return &Iso9660FuncTable; return &Iso9660FuncTable;
else }
return NULL;
return NULL;
} }
#endif #endif

View file

@ -877,6 +877,8 @@ const DEVVTBL* NtfsMount(ULONG DeviceId)
ULONG Count; ULONG Count;
ARC_STATUS Status; ARC_STATUS Status;
TRACE("Enter NtfsMount(%lu)\n", DeviceId);
// //
// Allocate data for volume information // Allocate data for volume information
// //
@ -888,8 +890,7 @@ const DEVVTBL* NtfsMount(ULONG DeviceId)
// //
// Read the BootSector // Read the BootSector
// //
Position.HighPart = 0; Position.QuadPart = 0;
Position.LowPart = 0;
Status = ArcSeek(DeviceId, &Position, SeekAbsolute); Status = ArcSeek(DeviceId, &Position, SeekAbsolute);
if (Status != ESUCCESS) if (Status != ESUCCESS)
{ {
@ -997,6 +998,7 @@ const DEVVTBL* NtfsMount(ULONG DeviceId)
// //
// Return success // Return success
// //
TRACE("NtfsMount(%lu) success\n", DeviceId);
return &NtfsFuncTable; return &NtfsFuncTable;
} }

View file

@ -243,7 +243,7 @@ VOID DumpMemoryAllocMap(VOID)
DbgPrint("*"); DbgPrint("*");
break; break;
case LoaderBad: case LoaderBad:
DbgPrint( "-"); DbgPrint("-");
break; break;
case LoaderLoadedProgram: case LoaderLoadedProgram:
DbgPrint("O"); DbgPrint("O");
@ -252,7 +252,7 @@ VOID DumpMemoryAllocMap(VOID)
DbgPrint("T"); DbgPrint("T");
break; break;
case LoaderFirmwarePermanent: case LoaderFirmwarePermanent:
DbgPrint( "P"); DbgPrint("P");
break; break;
case LoaderOsloaderHeap: case LoaderOsloaderHeap:
DbgPrint("H"); DbgPrint("H");

View file

@ -17,6 +17,11 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 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 #ifndef _M_ARM
#ifdef _M_IX86 #ifdef _M_IX86
@ -81,8 +86,10 @@ LoadAndBootLinux(
IN PCHAR Envp[]) IN PCHAR Envp[])
{ {
PCSTR Description; PCSTR Description;
PFILE LinuxKernel = 0; ULONG LinuxKernel = 0;
PFILE LinuxInitrdFile = 0; ULONG LinuxInitrdFile = 0;
ARC_STATUS Status;
FILEINFORMATION FileInfo;
Description = GetArgumentValue(Argc, Argv, "LoadIdentifier"); Description = GetArgumentValue(Argc, Argv, "LoadIdentifier");
if (Description) if (Description)
@ -129,10 +136,22 @@ LoadAndBootLinux(
goto LinuxBootFailed; goto LinuxBootFailed;
/* Calc kernel size */ /* 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 */ /* Get the initrd file image (if necessary) */
LinuxInitrdSize = FsGetFileSize(LinuxInitrdFile); 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 */ /* Read the kernel */
if (!LinuxReadKernel(LinuxKernel)) if (!LinuxReadKernel(LinuxKernel))
@ -184,10 +203,10 @@ LoadAndBootLinux(
LinuxBootFailed: LinuxBootFailed:
if (LinuxKernel) if (LinuxKernel)
FsCloseFile(LinuxKernel); ArcClose(LinuxKernel);
if (LinuxInitrdFile) if (LinuxInitrdFile)
FsCloseFile(LinuxInitrdFile); ArcClose(LinuxInitrdFile);
if (LinuxBootSector != NULL) if (LinuxBootSector != NULL)
MmFreeMemory(LinuxBootSector); MmFreeMemory(LinuxBootSector);
@ -224,12 +243,14 @@ LinuxParseIniSection(
IN ULONG Argc, IN ULONG Argc,
IN PCHAR Argv[]) IN PCHAR Argv[])
{ {
#if 0
LinuxBootPath = GetArgumentValue(Argc, Argv, "BootPath"); LinuxBootPath = GetArgumentValue(Argc, Argv, "BootPath");
if (!LinuxBootPath) if (!LinuxBootPath)
{ {
UiMessageBox("Boot path not specified for selected OS!"); UiMessageBox("Boot path not specified for selected OS!");
return FALSE; return FALSE;
} }
#endif
/* Get the kernel name */ /* Get the kernel name */
LinuxKernelName = GetArgumentValue(Argc, Argv, "Kernel"); LinuxKernelName = GetArgumentValue(Argc, Argv, "Kernel");
@ -255,16 +276,20 @@ LinuxParseIniSection(
return TRUE; return TRUE;
} }
BOOLEAN LinuxReadBootSector(PFILE LinuxKernelFile) BOOLEAN LinuxReadBootSector(ULONG LinuxKernelFile)
{ {
LARGE_INTEGER Position;
/* Allocate memory for boot sector */ /* Allocate memory for boot sector */
LinuxBootSector = MmAllocateMemoryWithType(512, LoaderSystemCode); LinuxBootSector = MmAllocateMemoryWithType(512, LoaderSystemCode);
if (LinuxBootSector == NULL) if (LinuxBootSector == NULL)
return FALSE; return FALSE;
/* Read linux boot sector */ /* Read linux boot sector */
FsSetFilePointer(LinuxKernelFile, 0); Position.QuadPart = 0;
if (!FsReadFile(LinuxKernelFile, 512, NULL, LinuxBootSector)) if (ArcSeek(LinuxKernelFile, &Position, SeekAbsolute) != ESUCCESS)
return FALSE;
if (ArcRead(LinuxKernelFile, LinuxBootSector, 512, NULL) != ESUCCESS)
return FALSE; return FALSE;
/* Check for validity */ /* Check for validity */
@ -288,13 +313,16 @@ BOOLEAN LinuxReadBootSector(PFILE LinuxKernelFile)
return TRUE; return TRUE;
} }
BOOLEAN LinuxReadSetupSector(PFILE LinuxKernelFile) BOOLEAN LinuxReadSetupSector(ULONG LinuxKernelFile)
{ {
LARGE_INTEGER Position;
UCHAR TempLinuxSetupSector[512]; UCHAR TempLinuxSetupSector[512];
/* Read first linux setup sector */ /* Read first linux setup sector */
FsSetFilePointer(LinuxKernelFile, 512); Position.QuadPart = 512;
if (!FsReadFile(LinuxKernelFile, 512, NULL, TempLinuxSetupSector)) if (ArcSeek(LinuxKernelFile, &Position, SeekAbsolute) != ESUCCESS)
return FALSE;
if (ArcRead(LinuxKernelFile, TempLinuxSetupSector, 512, NULL) != ESUCCESS)
return FALSE; return FALSE;
/* Check the kernel version */ /* Check the kernel version */
@ -316,8 +344,10 @@ BOOLEAN LinuxReadSetupSector(PFILE LinuxKernelFile)
RtlCopyMemory(LinuxSetupSector, TempLinuxSetupSector, 512); RtlCopyMemory(LinuxSetupSector, TempLinuxSetupSector, 512);
/* Read in the rest of the linux setup sectors */ /* Read in the rest of the linux setup sectors */
FsSetFilePointer(LinuxKernelFile, 1024); Position.QuadPart = 1024;
if (!FsReadFile(LinuxKernelFile, SetupSectorSize - 512, NULL, (PVOID)((ULONG_PTR)LinuxSetupSector + 512))) if (ArcSeek(LinuxKernelFile, &Position, SeekAbsolute) != ESUCCESS)
return FALSE;
if (ArcRead(LinuxKernelFile, (PVOID)((ULONG_PTR)LinuxSetupSector + 512), SetupSectorSize - 512, NULL) != ESUCCESS)
return FALSE; return FALSE;
// DbgDumpBuffer(DPRINT_LINUX, LinuxSetupSector, SetupSectorSize); // DbgDumpBuffer(DPRINT_LINUX, LinuxSetupSector, SetupSectorSize);
@ -341,11 +371,12 @@ BOOLEAN LinuxReadSetupSector(PFILE LinuxKernelFile)
return TRUE; return TRUE;
} }
BOOLEAN LinuxReadKernel(PFILE LinuxKernelFile) BOOLEAN LinuxReadKernel(ULONG LinuxKernelFile)
{ {
PVOID LoadAddress;
LARGE_INTEGER Position;
ULONG BytesLoaded; ULONG BytesLoaded;
CHAR StatusText[260]; CHAR StatusText[260];
PVOID LoadAddress;
RtlStringCbPrintfA(StatusText, sizeof(StatusText), "Loading %s", LinuxKernelName); RtlStringCbPrintfA(StatusText, sizeof(StatusText), "Loading %s", LinuxKernelName);
UiDrawStatusText(StatusText); UiDrawStatusText(StatusText);
@ -360,10 +391,12 @@ BOOLEAN LinuxReadKernel(PFILE LinuxKernelFile)
LoadAddress = LinuxKernelLoadAddress; LoadAddress = LinuxKernelLoadAddress;
/* Read linux kernel to 0x100000 (1mb) */ /* 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<LinuxKernelSize; ) for (BytesLoaded=0; BytesLoaded<LinuxKernelSize; )
{ {
if (!FsReadFile(LinuxKernelFile, LINUX_READ_CHUNK_SIZE, NULL, LoadAddress)) if (ArcRead(LinuxKernelFile, LoadAddress, LINUX_READ_CHUNK_SIZE, NULL) != ESUCCESS)
return FALSE; return FALSE;
BytesLoaded += LINUX_READ_CHUNK_SIZE; BytesLoaded += LINUX_READ_CHUNK_SIZE;
@ -412,7 +445,7 @@ BOOLEAN LinuxCheckKernelVersion(VOID)
return TRUE; return TRUE;
} }
BOOLEAN LinuxReadInitrd(PFILE LinuxInitrdFile) BOOLEAN LinuxReadInitrd(ULONG LinuxInitrdFile)
{ {
ULONG BytesLoaded; ULONG BytesLoaded;
CHAR StatusText[260]; CHAR StatusText[260];
@ -452,7 +485,7 @@ BOOLEAN LinuxReadInitrd(PFILE LinuxInitrdFile)
/* Read in the ramdisk */ /* Read in the ramdisk */
for (BytesLoaded=0; BytesLoaded<LinuxInitrdSize; ) for (BytesLoaded=0; BytesLoaded<LinuxInitrdSize; )
{ {
if (!FsReadFile(LinuxInitrdFile, LINUX_READ_CHUNK_SIZE, NULL, (PVOID)LinuxInitrdLoadAddress)) if (ArcRead(LinuxInitrdFile, (PVOID)LinuxInitrdLoadAddress, LINUX_READ_CHUNK_SIZE, NULL) != ESUCCESS)
return FALSE; return FALSE;
BytesLoaded += LINUX_READ_CHUNK_SIZE; BytesLoaded += LINUX_READ_CHUNK_SIZE;

View file

@ -32,7 +32,7 @@ LoadAndBootBootSector(
IN PCHAR Envp[]) IN PCHAR Envp[])
{ {
PCSTR FileName; PCSTR FileName;
PFILE FilePointer; ULONG FileId;
ULONG BytesRead; ULONG BytesRead;
/* Find all the message box settings and run them */ /* Find all the message box settings and run them */
@ -46,15 +46,16 @@ LoadAndBootBootSector(
return EINVAL; return EINVAL;
} }
FilePointer = FsOpenFile(FileName); FileId = FsOpenFile(FileName);
if (!FilePointer) if (!FileId)
{ {
UiMessageBox("%s not found.", FileName); UiMessageBox("%s not found.", FileName);
return ENOENT; return ENOENT;
} }
/* Read boot sector */ /* Read boot sector */
if (!FsReadFile(FilePointer, 512, &BytesRead, (void*)0x7c00) || (BytesRead != 512)) if (ArcRead(FileId, (void*)0x7c00, 512, &BytesRead) != ESUCCESS ||
(BytesRead != 512))
{ {
UiMessageBox("Unable to read boot sector."); UiMessageBox("Unable to read boot sector.");
return EIO; return EIO;