summaryrefslogtreecommitdiffhomepage
path: root/dev/boot/src/BootFileReader.cc
diff options
context:
space:
mode:
authorAmlal <amlal@nekernel.org>2025-04-25 13:08:33 +0200
committerAmlal <amlal@nekernel.org>2025-04-25 13:08:33 +0200
commitfb790b07aeba8e22e4190cf3e1834d11ecde6c96 (patch)
tree4cec7d1b321307b1d5935577631dae116a658a37 /dev/boot/src/BootFileReader.cc
parent63a2d92c5dfe976175cda024ec01905d11b43738 (diff)
dev: better .clang-format, ran format command.
Signed-off-by: Amlal <amlal@nekernel.org>
Diffstat (limited to 'dev/boot/src/BootFileReader.cc')
-rw-r--r--dev/boot/src/BootFileReader.cc293
1 files changed, 132 insertions, 161 deletions
diff --git a/dev/boot/src/BootFileReader.cc b/dev/boot/src/BootFileReader.cc
index 1236b7f0..32060bd7 100644
--- a/dev/boot/src/BootFileReader.cc
+++ b/dev/boot/src/BootFileReader.cc
@@ -1,18 +1,18 @@
/* -------------------------------------------
- Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
+ Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
- File: FileReader.cc
- Purpose: New Boot FileReader,
- Read complete file and store it in a buffer.
+ File: FileReader.cc
+ Purpose: New Boot FileReader,
+ Read complete file and store it in a buffer.
------------------------------------------- */
+#include <BootKit/BootKit.h>
#include <BootKit/Platform.h>
#include <BootKit/Protocol.h>
-#include <BootKit/BootKit.h>
-#include <FirmwareKit/Handover.h>
#include <FirmwareKit/EFI/API.h>
+#include <FirmwareKit/Handover.h>
#include <modules/CoreGfx/TextGfx.h>
/// @file BootFileReader
@@ -29,178 +29,149 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
/***
- @brief File Reader constructor.
+ @brief File Reader constructor.
*/
-Boot::BootFileReader::BootFileReader(const CharacterTypeUTF16* path,
- EfiHandlePtr ImageHandle)
-{
- if (path != nullptr)
- {
- SizeT index = 0UL;
- for (; path[index] != L'\0'; ++index)
- {
- mPath[index] = path[index];
- }
-
- mPath[index] = 0;
- }
-
- /// Load protocols with their GUIDs.
-
- EfiGUID guidEfp = EfiGUID(EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID);
-
- EfiSimpleFilesystemProtocol* efp = nullptr;
-
- EfiLoadImageProtocol* img = nullptr;
- EfiGUID guidImg = EfiGUID(EFI_LOADED_IMAGE_PROTOCOL_GUID);
-
- if (BS->HandleProtocol(ImageHandle, &guidImg, (void**)&img) != kEfiOk)
- {
- mWriter.Write(L"BootZ: Handle-Protocol: No-Such-Protocol").Write(L"\r");
- this->mErrorCode = kNotSupported;
- }
-
- if (BS->HandleProtocol(img->DeviceHandle, &guidEfp, (void**)&efp) != kEfiOk)
- {
- mWriter.Write(L"BootZ: Handle-Protocol: No-Such-Protocol").Write(L"\r");
- this->mErrorCode = kNotSupported;
- return;
- }
-
- /// Start doing disk I/O
-
- if (efp->OpenVolume(efp, &mRootFs) != kEfiOk)
- {
- mWriter.Write(L"BootZ: Fetch-Protocol: No-Such-Volume").Write(L"\r");
- this->mErrorCode = kNotSupported;
- return;
- }
-
- EfiFileProtocol* fileFs = nullptr;
-
- if (mRootFs->Open(mRootFs, &fileFs, mPath, kEFIFileRead, kEFIReadOnly) !=
- kEfiOk)
- {
- mWriter.Write(L"BootZ: Fetch-Protocol: No-Such-Path: ")
- .Write(mPath)
- .Write(L"\r");
- this->mErrorCode = kNotSupported;
-
- fb_render_string("BootZ: PLEASE RECOVER YOUR MINKRNL INSTALL.", 40, 10, RGB(0xFF, 0xFF, 0xFF));
-
- mRootFs->Close(mRootFs);
-
- return;
- }
-
- mSizeFile = 0;
- mFile = fileFs;
- mErrorCode = kOperationOkay;
+Boot::BootFileReader::BootFileReader(const CharacterTypeUTF16* path, EfiHandlePtr ImageHandle) {
+ if (path != nullptr) {
+ SizeT index = 0UL;
+ for (; path[index] != L'\0'; ++index) {
+ mPath[index] = path[index];
+ }
+
+ mPath[index] = 0;
+ }
+
+ /// Load protocols with their GUIDs.
+
+ EfiGUID guidEfp = EfiGUID(EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID);
+
+ EfiSimpleFilesystemProtocol* efp = nullptr;
+
+ EfiLoadImageProtocol* img = nullptr;
+ EfiGUID guidImg = EfiGUID(EFI_LOADED_IMAGE_PROTOCOL_GUID);
+
+ if (BS->HandleProtocol(ImageHandle, &guidImg, (void**) &img) != kEfiOk) {
+ mWriter.Write(L"BootZ: Handle-Protocol: No-Such-Protocol").Write(L"\r");
+ this->mErrorCode = kNotSupported;
+ }
+
+ if (BS->HandleProtocol(img->DeviceHandle, &guidEfp, (void**) &efp) != kEfiOk) {
+ mWriter.Write(L"BootZ: Handle-Protocol: No-Such-Protocol").Write(L"\r");
+ this->mErrorCode = kNotSupported;
+ return;
+ }
+
+ /// Start doing disk I/O
+
+ if (efp->OpenVolume(efp, &mRootFs) != kEfiOk) {
+ mWriter.Write(L"BootZ: Fetch-Protocol: No-Such-Volume").Write(L"\r");
+ this->mErrorCode = kNotSupported;
+ return;
+ }
+
+ EfiFileProtocol* fileFs = nullptr;
+
+ if (mRootFs->Open(mRootFs, &fileFs, mPath, kEFIFileRead, kEFIReadOnly) != kEfiOk) {
+ mWriter.Write(L"BootZ: Fetch-Protocol: No-Such-Path: ").Write(mPath).Write(L"\r");
+ this->mErrorCode = kNotSupported;
+
+ fb_render_string("BootZ: PLEASE RECOVER YOUR MINKRNL INSTALL.", 40, 10, RGB(0xFF, 0xFF, 0xFF));
+
+ mRootFs->Close(mRootFs);
+
+ return;
+ }
+
+ mSizeFile = 0;
+ mFile = fileFs;
+ mErrorCode = kOperationOkay;
}
-Boot::BootFileReader::~BootFileReader()
-{
- if (this->mFile)
- {
- this->mFile->Close(this->mFile);
- this->mFile = nullptr;
- }
-
- if (this->mRootFs)
- {
- this->mRootFs->Close(this->mRootFs);
- this->mRootFs = nullptr;
- }
-
- if (this->mBlob)
- {
- BS->FreePool(this->mBlob);
- this->mBlob = nullptr;
- }
-
- BSetMem(this->mPath, 0, kPathLen);
+Boot::BootFileReader::~BootFileReader() {
+ if (this->mFile) {
+ this->mFile->Close(this->mFile);
+ this->mFile = nullptr;
+ }
+
+ if (this->mRootFs) {
+ this->mRootFs->Close(this->mRootFs);
+ this->mRootFs = nullptr;
+ }
+
+ if (this->mBlob) {
+ BS->FreePool(this->mBlob);
+ this->mBlob = nullptr;
+ }
+
+ BSetMem(this->mPath, 0, kPathLen);
}
/**
- @brief Reads all of the file into a buffer.
- @param **readUntil** size of file
- @param **chunkToRead** chunk to read each time.
+ @brief Reads all of the file into a buffer.
+ @param **readUntil** size of file
+ @param **chunkToRead** chunk to read each time.
*/
-Void Boot::BootFileReader::ReadAll(SizeT readUntil, SizeT chunkToRead, UIntPtr out_address)
-{
- UInt32 szInfo = sizeof(EfiFileInfo);
-
- EfiFileInfo newPtrInfo{};
-
- EfiGUID kFileInfoGUID = EFI_FILE_INFO_GUID;
-
- if (mFile->GetInfo(mFile, &kFileInfoGUID, &szInfo, &newPtrInfo) == kEfiOk)
- {
- readUntil = newPtrInfo.FileSize;
- mWriter.Write(L"BootZ: File size: ").Write(readUntil).Write("\r");
- }
-
- if (readUntil == 0)
- {
- mErrorCode = kNotSupported;
- return;
- }
-
- if (mBlob == nullptr)
- {
- if (!out_address)
- {
- if (auto err = BS->AllocatePool(EfiLoaderCode, readUntil, (VoidPtr*)&mBlob) !=
- kEfiOk)
- {
- mWriter.Write(L"*** error: ").Write(err).Write(L" ***\r");
- Boot::ThrowError(L"OutOfMemory", L"Out of memory.");
- }
- }
- else
- {
- mBlob = (VoidPtr)out_address;
- }
- }
-
- mWriter.Write(L"*** Bytes to read: ").Write(readUntil).Write(L" ***\r");
-
- UInt64 bufSize = chunkToRead;
- UInt64 szCnt = 0UL;
-
- while (szCnt < readUntil)
- {
- auto res = mFile->Read(mFile, &bufSize, (VoidPtr)(&((Char*)mBlob)[szCnt]));
-
- szCnt += bufSize;
-
- if (res == kBufferTooSmall)
- {
- bufSize = chunkToRead;
- }
- }
-
- mSizeFile = szCnt;
- mErrorCode = kOperationOkay;
+Void Boot::BootFileReader::ReadAll(SizeT readUntil, SizeT chunkToRead, UIntPtr out_address) {
+ UInt32 szInfo = sizeof(EfiFileInfo);
+
+ EfiFileInfo newPtrInfo{};
+
+ EfiGUID kFileInfoGUID = EFI_FILE_INFO_GUID;
+
+ if (mFile->GetInfo(mFile, &kFileInfoGUID, &szInfo, &newPtrInfo) == kEfiOk) {
+ readUntil = newPtrInfo.FileSize;
+ mWriter.Write(L"BootZ: File size: ").Write(readUntil).Write("\r");
+ }
+
+ if (readUntil == 0) {
+ mErrorCode = kNotSupported;
+ return;
+ }
+
+ if (mBlob == nullptr) {
+ if (!out_address) {
+ if (auto err = BS->AllocatePool(EfiLoaderCode, readUntil, (VoidPtr*) &mBlob) != kEfiOk) {
+ mWriter.Write(L"*** error: ").Write(err).Write(L" ***\r");
+ Boot::ThrowError(L"OutOfMemory", L"Out of memory.");
+ }
+ } else {
+ mBlob = (VoidPtr) out_address;
+ }
+ }
+
+ mWriter.Write(L"*** Bytes to read: ").Write(readUntil).Write(L" ***\r");
+
+ UInt64 bufSize = chunkToRead;
+ UInt64 szCnt = 0UL;
+
+ while (szCnt < readUntil) {
+ auto res = mFile->Read(mFile, &bufSize, (VoidPtr) (&((Char*) mBlob)[szCnt]));
+
+ szCnt += bufSize;
+
+ if (res == kBufferTooSmall) {
+ bufSize = chunkToRead;
+ }
+ }
+
+ mSizeFile = szCnt;
+ mErrorCode = kOperationOkay;
}
/// @brief error code getter.
/// @return the error code.
-Int32& Boot::BootFileReader::Error()
-{
- return mErrorCode;
+Int32& Boot::BootFileReader::Error() {
+ return mErrorCode;
}
/// @brief blob getter.
/// @return the blob.
-VoidPtr Boot::BootFileReader::Blob()
-{
- return mBlob;
+VoidPtr Boot::BootFileReader::Blob() {
+ return mBlob;
}
/// @breif Size getter.
/// @return the size of the file.
-UInt64& Boot::BootFileReader::Size()
-{
- return mSizeFile;
+UInt64& Boot::BootFileReader::Size() {
+ return mSizeFile;
}