summaryrefslogtreecommitdiffhomepage
path: root/dev
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2025-03-20 04:48:20 +0100
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2025-03-20 04:50:07 +0100
commitab4e4900ed17b344efc1497d06a7f397a318d7a1 (patch)
tree11ddf51028ccb695e6d2213a1ba751002e5157e8 /dev
parent0c4f417129e3cec71d2b3f805f12d9d1ed984438 (diff)
BootKit.h: refactor BDiskFormatFactory class.
- Make use of BFileDescriptor to provide a single file, or a bunch of them. Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'dev')
-rw-r--r--dev/Boot/BootKit/BootKit.h45
1 files changed, 25 insertions, 20 deletions
diff --git a/dev/Boot/BootKit/BootKit.h b/dev/Boot/BootKit/BootKit.h
index aef84a77..2de5ca09 100644
--- a/dev/Boot/BootKit/BootKit.h
+++ b/dev/Boot/BootKit/BootKit.h
@@ -220,13 +220,13 @@ namespace Boot
NE_COPY_DELETE(BDiskFormatFactory);
- /// @brief Format disk using partition name and blob_list.
+ /// @brief Format disk using partition name and blob.
/// @param Partition part_name the target partition name.
- /// @param blob_list blobs array.
- /// @param blob_cnt blobs array count.
+ /// @param blob blobs array.
+ /// @param blob_sz blobs array count.
/// @retval True disk has been formatted.
/// @retval False failed to format.
- Boolean Format(const Char* part_name, BFileDescriptor* blob_list, SizeT blob_cnt);
+ Boolean Format(const Char* part_name, BFileDescriptor* blob, SizeT blob_sz);
/// @brief check if partition is good.
Bool IsPartitionValid() noexcept
@@ -268,12 +268,17 @@ namespace Boot
private:
/// @brief Write all of the requested catalogs into the filesystem.
- /// @param blob_list the blobs.
- /// @param blob_cnt the number of blobs to write.
+ /// @param blob the blobs.
+ /// @param blob_sz the number of blobs to write.
/// @param part the NeFS partition block.
- Boolean WriteCatalogList(BFileDescriptor* blob_list, SizeT blob_cnt, NEFS_ROOT_PARTITION_BLOCK& part)
+ Boolean WriteCatalogList(BFileDescriptor* blob, SizeT blob_sz, NEFS_ROOT_PARTITION_BLOCK& part)
{
- BFileDescriptor* blob = blob_list;
+ if (blob_sz < sizeof(NEFS_CATALOG_STRUCT))
+ return NO;
+
+ if (!blob)
+ return NO;
+
Lba startLba = part.StartCatalog;
BTextWriter writer;
@@ -316,10 +321,10 @@ namespace Boot
/// @retval False failed to format.
template <typename BootDev>
inline Boolean BDiskFormatFactory<BootDev>::Format(const Char* part_name,
- BDiskFormatFactory::BFileDescriptor* blob_list,
- SizeT blob_cnt)
+ BDiskFormatFactory::BFileDescriptor* blob,
+ SizeT blob_sz)
{
- if (!blob_list || !blob_cnt)
+ if (!blob || !blob_sz)
return false; /// sanity check
/// @note A catalog roughly equal to a sector.
@@ -343,9 +348,9 @@ namespace Boot
CopyMem(part.PartitionName, part_name, StrLen(part_name));
part.Version = kNeFSVersionInteger;
- part.CatalogCount = blob_cnt;
- part.Kind = kNeFSHardDrive;
- part.SectorSize = 512;
+ part.CatalogCount = blob_sz / sizeof(NEFS_CATALOG_STRUCT);
+ part.Kind = BootDev::kSectorSize;
+ part.SectorSize = kATASectorSize;
part.FreeCatalog = fDiskDev.GetSectorsCount() / sizeof(NEFS_CATALOG_STRUCT);
part.SectorCount = fDiskDev.GetSectorsCount();
part.FreeSectors = fDiskDev.GetSectorsCount();
@@ -360,12 +365,12 @@ namespace Boot
BTextWriter writer;
- writer << "partition name: " << part.PartitionName << "\n";
- writer << "start: " << part.StartCatalog << "\n";
- writer << "number of catalogs: " << part.CatalogCount << "\n";
- writer << "free catalog: " << part.FreeCatalog << "\n";
- writer << "free sectors: " << part.FreeSectors << "\n";
- writer << "sector size: " << part.SectorSize << "\n";
+ writer << "partition name: " << part.PartitionName << "\r";
+ writer << "start: " << part.StartCatalog << "\r";
+ writer << "number of catalogs: " << part.CatalogCount << "\r";
+ writer << "free catalog: " << part.FreeCatalog << "\r";
+ writer << "free sectors: " << part.FreeSectors << "\r";
+ writer << "sector size: " << part.SectorSize << "\r";
#ifdef BOOTZ_EPM_SUPPORT
EPM_PART_BLOCK epm_boot{0};