From 422b8029eba71b6fbb6b3dcb386b8e115bbd08ef Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sat, 6 Apr 2024 09:31:44 +0200 Subject: NewFS, Implementing the NewFSParser class, added CreateFork method. --- Private/Source/FS/NewFS.cxx | 92 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 Private/Source/FS/NewFS.cxx (limited to 'Private/Source/FS') diff --git a/Private/Source/FS/NewFS.cxx b/Private/Source/FS/NewFS.cxx new file mode 100644 index 00000000..f497c2af --- /dev/null +++ b/Private/Source/FS/NewFS.cxx @@ -0,0 +1,92 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#ifdef __FSKIT_NEWFS__ + +#include +#include + +using namespace NewOS; + +STATIC Lba ke_find_fork(SizeT sz); +STATIC Lba ke_find_catalog(SizeT sz); +STATIC Lba ke_find_data(SizeT sz); + +STATIC MountpointInterface sMountpointInterface; + +/// @brief Creates a new fork inside the New filesystem partition. +/// @param catalog it's catalog +/// @param theFork the fork itself. +/// @return the fork +_Output NewFork* NewFSParser::CreateFork(_Input NewCatalog* catalog, _Input NewFork& theFork) +{ + if (catalog && + theFork.Name[0] != 0 && + theFork.DataSize > 0) { + Lba whereFork = 0; + + theFork.DataOffset = ke_find_fork(theFork.DataSize); + theFork.Flags |= kNewFSFlagCreated; + + if (catalog->FirstFork == 0) { + catalog->FirstFork = whereFork; + } else { + if (catalog->LastFork == 0) { + theFork.PreviousSibling = catalog->FirstFork; + } + } + + if (catalog->LastFork == 0) { + catalog->LastFork = whereFork; + } else { + theFork.PreviousSibling = catalog->LastFork; + } + + if (!sMountpointInterface.GetAddressOf(this->fDriveIndex) || + !*sMountpointInterface.GetAddressOf(this->fDriveIndex)) + return nullptr; + + auto drv = *sMountpointInterface.GetAddressOf(this->fDriveIndex); + + drv->fPacket.fLba = whereFork; + drv->fPacket.fPacketSize = theFork.DataSize; + drv->fPacket.fPacketContent = (VoidPtr)&theFork; + + rt_copy_memory((VoidPtr)"fs/newfs-packet", drv->fPacket.fPacketMime, 16); + + if (auto res = fs_newfs_write(&sMountpointInterface, *drv, this->fDriveIndex); + res) { + switch (res) + { + case 1: + DbgLastError() = kErrorDiskReadOnly; + break; + case 2: + DbgLastError() = kErrorDiskIsFull; + break; + DbgLastError() = kErrorNoSuchDisk; + break; + + default: + break; + } + return nullptr; + } + + /// Also update catalog. + this->WriteCatalog(catalog, nullptr); + + return &theFork; + } + + return nullptr; +} + +STATIC Lba ke_find_fork(SizeT sz) {} +STATIC Lba ke_find_catalog(SizeT sz) {} +STATIC Lba ke_find_data(SizeT sz) {} + +#endif // ifdef __FSKIT_NEWFS__ \ No newline at end of file -- cgit v1.2.3