From 14f26421cc6ebd678c2b5a2a04fe6cdc63ee5d38 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 25 Apr 2024 13:44:36 +0200 Subject: MHR-16: Adding BDiskFormatFactory according to MHR-16, bug fixes and improvements as well. Signed-off-by: Amlal El Mahrouss --- Private/NewBoot/BootKit/BootKit.hxx | 108 +++++++++++++++++++++++++++++----- Private/NewBoot/BootKit/HW/ATA.hxx | 4 +- Private/NewBoot/BootKit/Vendor/Qr.hxx | 3 + 3 files changed, 99 insertions(+), 16 deletions(-) (limited to 'Private/NewBoot/BootKit') diff --git a/Private/NewBoot/BootKit/BootKit.hxx b/Private/NewBoot/BootKit/BootKit.hxx index 5c3a531d..15700f54 100644 --- a/Private/NewBoot/BootKit/BootKit.hxx +++ b/Private/NewBoot/BootKit/BootKit.hxx @@ -11,6 +11,22 @@ #pragma once +#include +#include + +/// include NewFS header and Support header as well. + +#include +#include +#include + +/***********************************************************************************/ +/// Include other APIs. +/***********************************************************************************/ + +#include +#include "Builtins/ATA/ATA.hxx" + /***********************************************************************************/ /// Framebuffer helpers. /***********************************************************************************/ @@ -22,15 +38,6 @@ class BFileReader; class BFileRunner; class BVersionString; -#include -#include - -/***********************************************************************************/ -/// Include other APIs. -/***********************************************************************************/ - -#include - ///! @note This address is reserved to NewKernel. #define kBootVirtualAddress (0xfffffff80000000) @@ -39,12 +46,6 @@ using namespace NewOS; typedef Char *PEFImagePtr; typedef Char *PEImagePtr; -enum { - kSegmentCode = 2, - kSegmentData = 4, - kSegmentBss = 6, -}; - typedef WideChar CharacterTypeUTF16; typedef Char CharacterTypeUTF8; @@ -169,3 +170,80 @@ static inline const UInt32 kRgbGreen = 0x0000FF00; static inline const UInt32 kRgbBlue = 0x00FF0000; static inline const UInt32 kRgbBlack = 0x00000000; static inline const UInt32 kRgbWhite = 0x00FFFFFF; + +/// @brief BootKit Disk Formatter. +template +class BDiskFormatFactory final { +public: + /// @brief File entry for **BDiskFormatFactory**. + struct BFileDescriptor final { + Char fFilename[255]; + Char fForkName[255]; + + VoidPtr fBlob; + SizeT fBlobSz; + + struct BFileDescriptor* fPrev; + struct BFileDescriptor* fNext; + }; + +public: + explicit BDiskFormatFactory() = default; + explicit BDiskFormatFactory(BootDev dev) : fDiskDev(dev) {} + ~BDiskFormatFactory() = default; + + NEWOS_COPY_DELETE(BDiskFormatFactory); + + /// @brief Format disk. + /// @param Partition Name + /// @param Blobs. + /// @param Number of blobs. + /// @retval True disk has been formatted. + /// @retval False failed to format. + Boolean Format(const char* partName, BFileDescriptor* fileBlobs, SizeT blobCount); + +private: + /// @brief Write all of the requested catalogs into the filesystem. + Boolean _AppendCatalogList(BFileDescriptor* fileBlobs, SizeT blobCount) { + return true; + } + +private: + BootDev fDiskDev; + +}; + +/// @brief Format disk. +/// @param Partition Name +/// @param Blobs. +/// @param Number of blobs. +/// @retval True disk has been formatted. +/// @retval False failed to format. +template +inline Boolean BDiskFormatFactory::Format(const char* partName, + BDiskFormatFactory::BFileDescriptor* fileBlobs, SizeT blobCount) { + // if (!fileBlobs || !blobCount) return false; + + static_assert(kNewFSMinimumSectorSz == kATASectorSize, "Sector size doesn't match!"); + + Char buf[kNewFSMinimumSectorSz] = { 0 }; + NewPartitionBlock* partBlock = reinterpret_cast(buf); + + memcpy(partBlock->PartitionName, partName, strlen(partName)); + + /// @note A catalog roughly equal to a sector. + + partBlock->CatalogCount = blobCount; + partBlock->Kind = kNewFSHardDrive; + partBlock->SectorCount = kNewFSMinimumSectorSz; + partBlock->FreeCatalog = fDiskDev.GetSectorsCount() - partBlock->CatalogCount; + partBlock->SectorCount = fDiskDev.GetSectorsCount(); + partBlock->FreeSectors = fDiskDev.GetSectorsCount() - partBlock->CatalogCount; + partBlock->StartCatalog = kNewFSAddressAsLba + sizeof(NewPartitionBlock); + + fDiskDev.Leak().mBase = (kNewFSAddressAsLba / kNewFSMinimumSectorSz); + fDiskDev.Leak().mSize = kNewFSMinimumSectorSz; + fDiskDev.Write(buf, kNewFSMinimumSectorSz); + + return this->_AppendCatalogList(fileBlobs, blobCount); +} diff --git a/Private/NewBoot/BootKit/HW/ATA.hxx b/Private/NewBoot/BootKit/HW/ATA.hxx index 9127e598..c557aeb8 100644 --- a/Private/NewBoot/BootKit/HW/ATA.hxx +++ b/Private/NewBoot/BootKit/HW/ATA.hxx @@ -34,6 +34,8 @@ class BootDeviceATA final : public Device { public: operator bool(); + SizeT GetSectorsCount() noexcept; + BootDeviceATA& Read(Char* Buf, const SizeT& SecCount) override; BootDeviceATA& Write(Char* Buf, const SizeT& SecCount) override; @@ -41,4 +43,4 @@ class BootDeviceATA final : public Device { private: ATATrait mTrait; -}; \ No newline at end of file +}; diff --git a/Private/NewBoot/BootKit/Vendor/Qr.hxx b/Private/NewBoot/BootKit/Vendor/Qr.hxx index ca5eb566..27db8060 100644 --- a/Private/NewBoot/BootKit/Vendor/Qr.hxx +++ b/Private/NewBoot/BootKit/Vendor/Qr.hxx @@ -12,6 +12,7 @@ #include #include #include +#include namespace qr { inline uint8_t min_poly = @@ -811,6 +812,8 @@ public: explicit QrDelegate() = default; ~QrDelegate() = default; + NEWOS_COPY_DEFAULT(QrDelegate); + /// @brief Draw method delegate. template bool draw(Qr& subject, int x, int y) noexcept { -- cgit v1.2.3