diff options
Diffstat (limited to 'dev/kernel/src/FS')
| -rw-r--r-- | dev/kernel/src/FS/HeFS.cc | 98 | ||||
| -rw-r--r-- | dev/kernel/src/FS/NeFS.cc | 167 |
2 files changed, 119 insertions, 146 deletions
diff --git a/dev/kernel/src/FS/HeFS.cc b/dev/kernel/src/FS/HeFS.cc index 88837273..5beb8b3f 100644 --- a/dev/kernel/src/FS/HeFS.cc +++ b/dev/kernel/src/FS/HeFS.cc @@ -4,6 +4,7 @@ ------------------------------------------- */ +#include "NewKit/Defines.h" #ifdef __FSKIT_INCLUDES_HEFS__ #include <FSKit/HeFS.h> @@ -636,34 +637,95 @@ namespace Detail { /// real-time. /// @note This is certainly take longer to format a disk with it, but worth-it in the long run. -namespace Kernel { +namespace Kernel::HeFS { /// @brief Make a EPM+HeFS drive out of the disk. /// @param drive The drive to write on. /// @return If it was sucessful, see err_local_get(). -_Output Bool HeFileSystemParser::FormatEPM(_Input _Output DriveTrait* drive, - _Input const Lba end_lba, _Input const Int32 flags, - const Char* part_name) { +_Output Bool HeFileSystemParser::Format(_Input _Output DriveTrait* drive, _Input const Int32 flags, + const Utf16Char* part_name) { NE_UNUSED(drive); - NE_UNUSED(end_lba); NE_UNUSED(flags); NE_UNUSED(part_name); - return NO; + // verify disk. + drive->fVerify(drive->fPacket); + + // if disk isn't good, then error out. + if (false == drive->fPacket.fPacketGood) { + err_global_get() = kErrorDiskIsCorrupted; + return false; + } + + + HEFS_BOOT_NODE* root = new HEFS_BOOT_NODE(); + + if (!root) { + kout << "Error: Failed to allocate memory for boot node.\r"; + return NO; + } + + rt_set_memory(root, 0, sizeof(HEFS_BOOT_NODE)); + + rt_copy_memory((VoidPtr) "fs/hefs-packet", drive->fPacket.fPacketMime, + rt_string_len("fs/hefs-packet")); + + wrt_copy_memory((VoidPtr) part_name, root->fVolName, wrt_string_len(part_name)); + rt_copy_memory((VoidPtr) kHeFSMagic, root->fMagic, sizeof(kHeFSMagic)); + + root->fBadSectors = 0; + + root->fSectorCount = drv_get_sector_count(); + + root->fSectorSize = drive->fSectorSz; + + root->fStartIND = drive->fLbaStart + sizeof(HEFS_BOOT_NODE); + root->fEndIND = drive->fLbaEnd; + + root->fINDCount = root->fEndIND - root->fStartIND; + + root->fDiskSize = drv_get_size(); + root->fDiskStatus = kHeFSStatusUnlocked; + + root->fDiskFlags = flags; + + if (drive->fKind & kMassStorageDrive) { + } else if (drive->fKind & kHeFSOpticalDrive) { + root->fDiskKind = kHeFSOpticalDrive; + } else { + root->fDiskKind = kHeFSUnknown; + } + + root->fReserved = 0; + root->fReserved2 = 0; + root->fReserved3 = 0; + root->fReserved4 = 0; + + root->fChecksum = 0; + + root->fVID = kHeFSInvalidVID; + + drive->fPacket.fPacketLba = drive->fLbaStart; + drive->fPacket.fPacketSize = sizeof(HEFS_BOOT_NODE); + drive->fPacket.fPacketContent = root; + + drive->fOutput(drive->fPacket); + + return YES; } -/// @brief Make a EPM+HeFS drive out of the disk. -/// @param drive The drive to write on. -/// @return If it was sucessful, see err_local_get(). -_Output Bool HeFileSystemParser::FormatGPT(_Input _Output DriveTrait* drive, - _Input const Lba end_lba, _Input const Int32 flags, - const Char* part_name) { - NE_UNUSED(drive); - NE_UNUSED(end_lba); - NE_UNUSED(flags); - NE_UNUSED(part_name); +Boolean fs_init_hefs(Void) noexcept { + kout << "Creating main disk...\r"; - return NO; + auto drv = io_construct_main_drive(); + + if (drv.fPacket.fPacketReadOnly == YES) + ke_panic(RUNTIME_CHECK_FILESYSTEM, "Main filesystem cannot be mounted."); + + HeFileSystemParser parser; + parser.Format(&drv, kHeFSEncodingUTF16, kHeFSDefaultVoluneName); + + return YES; } -} // namespace Kernel +} // namespace Kernel::HeFS #endif // ifdef __FSKIT_INCLUDES_HEFS__ diff --git a/dev/kernel/src/FS/NeFS.cc b/dev/kernel/src/FS/NeFS.cc index d0934f94..e0cdc71b 100644 --- a/dev/kernel/src/FS/NeFS.cc +++ b/dev/kernel/src/FS/NeFS.cc @@ -415,25 +415,14 @@ _Output NEFS_CATALOG_STRUCT* NeFileSystemParser::CreateCatalog(_Input const Char return nullptr; } -_Output Bool NeFileSystemParser::FormatGPT(_Input _Output DriveTrait* drive, - _Input const Lba end_lba, _Input const Int32 flags, - const Char* part_name) { - NE_UNUSED(drive); - NE_UNUSED(end_lba); - NE_UNUSED(flags); - NE_UNUSED(part_name); - - (Void)(kout << "FormatGPT: Not implemented yet.\r"); - - return NO; -} - /// @brief Make a EPM+NeFS drive out of the disk. /// @param drive The drive to write on. /// @return If it was sucessful, see err_global_get(). -bool NeFileSystemParser::FormatEPM(_Input _Output DriveTrait* drive, _Input const Lba endLba, - _Input const Int32 flags, const Char* part_name) { - if (*part_name == 0 || endLba == 0) return false; +bool NeFileSystemParser::Format(_Input _Output DriveTrait* drive, _Input const Int32 flags, + const Char* part_name) { + if (*part_name == 0) return false; + + NE_UNUSED(flags); // verify disk. drive->fVerify(drive->fPacket); @@ -449,7 +438,7 @@ bool NeFileSystemParser::FormatEPM(_Input _Output DriveTrait* drive, _Input cons Char fs_buf[sizeof(NEFS_ROOT_PARTITION_BLOCK)] = {0}; - Lba start = kNeFSRootCatalogStartAddress; + Lba start = drive->fLbaStart; drive->fPacket.fPacketContent = fs_buf; drive->fPacket.fPacketSize = sizeof(NEFS_ROOT_PARTITION_BLOCK); @@ -457,129 +446,48 @@ bool NeFileSystemParser::FormatEPM(_Input _Output DriveTrait* drive, _Input cons drive->fInput(drive->fPacket); - if (flags & kNeFSPartitionTypeBoot) { - // make it bootable when needed. - Char buf_epm[kNeFSSectorSz] = {0}; - - EPM_PART_BLOCK* epm_boot = (EPM_PART_BLOCK*) buf_epm; - - // Write a new EPM entry. - - constexpr auto kFsName = "NeFS"; - constexpr auto kBlockName = "NeKernel:"; - - epm_boot->FsVersion = kNeFSVersionInteger; - epm_boot->LbaStart = start; - epm_boot->SectorSz = kNeFSSectorSz; - - rt_copy_memory(reinterpret_cast<VoidPtr>(const_cast<Char*>(kFsName)), epm_boot->Fs, - rt_string_len(kFsName)); - rt_copy_memory(reinterpret_cast<VoidPtr>(const_cast<Char*>(kBlockName)), epm_boot->Name, - rt_string_len(kBlockName)); - rt_copy_memory(reinterpret_cast<VoidPtr>(const_cast<Char*>(kEPMMagic)), epm_boot->Magic, - rt_string_len(kEPMMagic)); - - Lba outEpmLba = kEPMBootBlockLba; - - Char buf[kNeFSSectorSz] = {0}; - - Lba prevStart = 0; - SizeT cnt = 0; - - while (drive->fPacket.fPacketGood) { - drive->fPacket.fPacketContent = buf; - drive->fPacket.fPacketSize = sizeof(EPM_PART_BLOCK); - drive->fPacket.fPacketLba = outEpmLba; - - drive->fInput(drive->fPacket); - - if (buf[0] == 0) { - epm_boot->LbaStart = prevStart; - - if (epm_boot->LbaStart) epm_boot->LbaStart = outEpmLba; - - epm_boot->LbaEnd = endLba; - epm_boot->NumBlocks = cnt; - - drive->fPacket.fPacketContent = buf_epm; - drive->fPacket.fPacketSize = sizeof(EPM_PART_BLOCK); - drive->fPacket.fPacketLba = outEpmLba; - - drive->fOutput(drive->fPacket); + NEFS_ROOT_PARTITION_BLOCK* part_block = (NEFS_ROOT_PARTITION_BLOCK*) fs_buf; - break; - } else { - prevStart = ((EPM_PART_BLOCK*) buf)->LbaStart + ((EPM_PART_BLOCK*) buf)->LbaEnd; - } - - outEpmLba += sizeof(EPM_PART_BLOCK); - ++cnt; - } - } - - // disk isnt faulty and data has been fetched. - while (drive->fPacket.fPacketGood) { - NEFS_ROOT_PARTITION_BLOCK* part_block = (NEFS_ROOT_PARTITION_BLOCK*) fs_buf; - - // check for an empty partition here. - if (part_block->PartitionName[0] == 0 && - rt_string_cmp(part_block->Ident, kNeFSIdent, kNeFSIdentLen)) { - // partition is free and valid. - - part_block->Version = kNeFSVersionInteger; - - const auto kNeFSUntitledHD = part_name; - - rt_copy_memory((VoidPtr) kNeFSIdent, (VoidPtr) part_block->Ident, kNeFSIdentLen); - - rt_copy_memory((VoidPtr) kNeFSUntitledHD, (VoidPtr) part_block->PartitionName, - rt_string_len(kNeFSUntitledHD)); + const auto kNeFSUntitledHD = part_name; - SizeT sectorCount = drv_get_sector_count(); - SizeT diskSize = drv_get_size(); + rt_copy_memory((VoidPtr) kNeFSIdent, (VoidPtr) part_block->Ident, kNeFSIdentLen); - part_block->Kind = kNeFSPartitionTypeStandard; - part_block->StartCatalog = kNeFSCatalogStartAddress; - part_block->Flags = kNeFSPartitionTypeStandard; - part_block->CatalogCount = sectorCount / sizeof(NEFS_CATALOG_STRUCT); - part_block->FreeSectors = sectorCount / sizeof(NEFS_CATALOG_STRUCT); - part_block->SectorCount = sectorCount; - part_block->DiskSize = diskSize; - part_block->FreeCatalog = sectorCount / sizeof(NEFS_CATALOG_STRUCT); + rt_copy_memory((VoidPtr) kNeFSUntitledHD, (VoidPtr) part_block->PartitionName, + rt_string_len(kNeFSUntitledHD)); - drive->fPacket.fPacketContent = fs_buf; - drive->fPacket.fPacketSize = sizeof(NEFS_ROOT_PARTITION_BLOCK); - drive->fPacket.fPacketLba = kNeFSRootCatalogStartAddress; + SizeT sectorCount = drv_get_sector_count(); + SizeT diskSize = drv_get_size(); - drive->fOutput(drive->fPacket); + part_block->Version = kNeFSVersionInteger; - (Void)(kout << "drive kind: " << drive->fProtocol() << kendl); + part_block->Kind = kNeFSPartitionTypeStandard; + part_block->StartCatalog = start + sizeof(NEFS_ROOT_PARTITION_BLOCK); + part_block->Flags = 0UL; + part_block->CatalogCount = sectorCount / sizeof(NEFS_CATALOG_STRUCT); + part_block->FreeSectors = sectorCount / sizeof(NEFS_CATALOG_STRUCT); + part_block->SectorCount = sectorCount; + part_block->DiskSize = diskSize; + part_block->FreeCatalog = sectorCount / sizeof(NEFS_CATALOG_STRUCT); - (Void)(kout << "partition name: " << part_block->PartitionName << kendl); - (Void)(kout << "start: " << hex_number(part_block->StartCatalog) << kendl); - (Void)(kout << "number of catalogs: " << hex_number(part_block->CatalogCount) << kendl); - (Void)(kout << "free catalog: " << hex_number(part_block->FreeCatalog) << kendl); - (Void)(kout << "free sectors: " << hex_number(part_block->FreeSectors) << kendl); - (Void)(kout << "sector size: " << hex_number(part_block->SectorSize) << kendl); - - // write the root catalog. - this->CreateCatalog(kNeFSRoot, 0, kNeFSCatalogKindDir); - - return true; - } + drive->fPacket.fPacketContent = fs_buf; + drive->fPacket.fPacketSize = sizeof(NEFS_ROOT_PARTITION_BLOCK); + drive->fPacket.fPacketLba = start; - kout << "partition block already exists.\r"; + drive->fOutput(drive->fPacket); - start += part_block->DiskSize; + (Void)(kout << "drive kind: " << drive->fProtocol() << kendl); - drive->fPacket.fPacketContent = fs_buf; - drive->fPacket.fPacketSize = sizeof(NEFS_ROOT_PARTITION_BLOCK); - drive->fPacket.fPacketLba = start; + (Void)(kout << "partition name: " << part_block->PartitionName << kendl); + (Void)(kout << "start: " << hex_number(part_block->StartCatalog) << kendl); + (Void)(kout << "number of catalogs: " << hex_number(part_block->CatalogCount) << kendl); + (Void)(kout << "free catalog: " << hex_number(part_block->FreeCatalog) << kendl); + (Void)(kout << "free sectors: " << hex_number(part_block->FreeSectors) << kendl); + (Void)(kout << "sector size: " << hex_number(part_block->SectorSize) << kendl); - drive->fInput(drive->fPacket); - } + // write the root catalog. + this->CreateCatalog(kNeFSRoot, 0, kNeFSCatalogKindDir); - return false; + return true; } /// @brief Writes the data fork into a specific catalog. @@ -971,6 +879,9 @@ Boolean fs_init_nefs(Void) noexcept { if (kMountpoint.A().fPacket.fPacketReadOnly == YES) ke_panic(RUNTIME_CHECK_FILESYSTEM, "Main filesystem cannot be mounted."); + NeFileSystemParser parser; + parser.Format(&kMountpoint.A(), 0, kNeFSVolumeName); + return YES; } } // namespace Kernel::NeFS |
