From 581fa445d2a6995a78d033deefab58951ab6ff48 Mon Sep 17 00:00:00 2001 From: Amlal Date: Tue, 21 Jan 2025 10:33:14 +0100 Subject: ADD: Moved filesystem specific code to FS/ Signed-off-by: Amlal --- dev/Kernel/src/FS/NeFS+FileMgr.cc | 245 ++++++++++++++++++++++++++++++++++++++ dev/Kernel/src/FS/NeFS+IO.cc | 101 ++++++++++++++++ dev/Kernel/src/NeFS+FileMgr.cc | 245 -------------------------------------- dev/Kernel/src/NeFS+IO.cc | 101 ---------------- 4 files changed, 346 insertions(+), 346 deletions(-) create mode 100644 dev/Kernel/src/FS/NeFS+FileMgr.cc create mode 100644 dev/Kernel/src/FS/NeFS+IO.cc delete mode 100644 dev/Kernel/src/NeFS+FileMgr.cc delete mode 100644 dev/Kernel/src/NeFS+IO.cc (limited to 'dev') diff --git a/dev/Kernel/src/FS/NeFS+FileMgr.cc b/dev/Kernel/src/FS/NeFS+FileMgr.cc new file mode 100644 index 00000000..685522a5 --- /dev/null +++ b/dev/Kernel/src/FS/NeFS+FileMgr.cc @@ -0,0 +1,245 @@ +/* ------------------------------------------- + + Copyright (C) 2024, MediaSwirl, all rights reserved. + +------------------------------------------- */ + +#include +#include + +#ifndef __ZKA_MINIMAL_OS__ +#ifdef __FSKIT_INCLUDES_NEFS__ + +/// @brief NeFS File manager. +/// BUGS: 0 + +namespace Kernel +{ + /// @brief C++ constructor + NeFileSystemMgr::NeFileSystemMgr() + { + NeFileSystemParser* mParser = new NeFileSystemParser(); + MUST_PASS(mParser); + + kcout << "We are done allocating NeFileSystemParser...\r"; + } + + NeFileSystemMgr::~NeFileSystemMgr() + { + if (mParser) + { + kcout << "Destroying NeFileSystemParser...\r"; + mm_delete_class(&mParser); + } + } + + /// @brief Removes a node from the filesystem. + /// @param path The filename + /// @return If it was deleted or not. + bool NeFileSystemMgr::Remove(_Input const Char* path) + { + if (path == nullptr || *path == 0) + return false; + + return mParser->RemoveCatalog(path); + } + + /// @brief Creates a node with the specified. + /// @param path The filename path. + /// @return The Node pointer. + NodePtr NeFileSystemMgr::Create(_Input const Char* path) + { + return node_cast(mParser->CreateCatalog(path)); + } + + /// @brief Creates a node with is a directory. + /// @param path The filename path. + /// @return The Node pointer. + NodePtr NeFileSystemMgr::CreateDirectory(const Char* path) + { + return node_cast(mParser->CreateCatalog(path, 0, kNeFSCatalogKindDir)); + } + + /// @brief Creates a node with is a alias. + /// @param path The filename path. + /// @return The Node pointer. + NodePtr NeFileSystemMgr::CreateAlias(const Char* path) + { + return node_cast(mParser->CreateCatalog(path, 0, kNeFSCatalogKindAlias)); + } + + /// @brief Creates a node with is a page file. + /// @param path The filename path. + /// @return The Node pointer. + NodePtr NeFileSystemMgr::CreateSwapFile(const Char* path) + { + return node_cast(mParser->CreateCatalog(path, 0, kNeFSCatalogKindPage)); + } + + /// @brief Gets the root directory. + /// @return + const Char* NeFileSystemHelper::Root() + { + return kNeFSRoot; + } + + /// @brief Gets the up-dir directory. + /// @return + const Char* NeFileSystemHelper::UpDir() + { + return kNeFSUpDir; + } + + /// @brief Gets the separator character. + /// @return + const Char NeFileSystemHelper::Separator() + { + return kNeFSSeparator; + } + + /// @brief Gets the metafile character. + /// @return + const Char NeFileSystemHelper::MetaFile() + { + return kNeFSMetaFilePrefix; + } + + /// @brief Opens a new file. + /// @param path + /// @param r + /// @return + _Output NodePtr NeFileSystemMgr::Open(_Input const Char* path, _Input const Char* r) + { + if (!path || *path == 0) + return nullptr; + + if (!r || *r == 0) + return nullptr; + + auto catalog = mParser->GetCatalog(path); + + return node_cast(catalog); + } + + /// @brief Writes to a catalog's fork. + /// @param node the node ptr. + /// @param data the data. + /// @param flags the size. + /// @return + Void NeFileSystemMgr::Write(_Input NodePtr node, _Input VoidPtr data, _Input Int32 flags, _Input SizeT size) + { + if (!node) + return; + if (!size) + return; + + constexpr auto cDataForkName = kNeFSDataFork; + this->Write(cDataForkName, node, data, flags, size); + } + + /// @brief Read from filesystem fork. + /// @param node the catalog node. + /// @param flags the flags with it. + /// @param sz the size to read. + /// @return + _Output VoidPtr NeFileSystemMgr::Read(_Input NodePtr node, _Input Int32 flags, _Input SizeT size) + { + if (!node) + return nullptr; + if (!size) + return nullptr; + + constexpr auto cDataForkName = kNeFSDataFork; + return this->Read(cDataForkName, node, flags, size); + } + + Void NeFileSystemMgr::Write(_Input const Char* name, + _Input NodePtr node, + _Input VoidPtr data, + _Input Int32 flags, + _Input SizeT size) + { + if (!size || + size > kNeFSForkSize) + return; + + if (!data) + return; + + ZKA_UNUSED(flags); + + if ((reinterpret_cast(node))->Kind == kNeFSCatalogKindFile) + mParser->WriteCatalog(reinterpret_cast(node), (flags & kFileFlagRsrc ? true : false), data, size, + name); + } + + _Output VoidPtr NeFileSystemMgr::Read(_Input const Char* name, + _Input NodePtr node, + _Input Int32 flags, + _Input SizeT sz) + { + if (sz > kNeFSForkSize) + return nullptr; + + if (!sz) + return nullptr; + + ZKA_UNUSED(flags); + + if ((reinterpret_cast(node))->Kind == kNeFSCatalogKindFile) + return mParser->ReadCatalog(reinterpret_cast(node), (flags & kFileFlagRsrc ? true : false), sz, + name); + + return nullptr; + } + + /// @brief Seek from Catalog. + /// @param node + /// @param off + /// @retval true always returns false, this is unimplemented. + /// @retval false always returns this, it is unimplemented. + + _Output Bool NeFileSystemMgr::Seek(NodePtr node, SizeT off) + { + if (!node || off == 0) + return false; + + return mParser->Seek(reinterpret_cast(node), off); + } + + /// @brief Tell where the catalog is. + /// @param node + /// @retval true always returns false, this is unimplemented. + /// @retval false always returns this, it is unimplemented. + + _Output SizeT NeFileSystemMgr::Tell(NodePtr node) + { + if (!node) + return kNPos; + + return mParser->Tell(reinterpret_cast(node)); + } + + /// @brief Rewinds the catalog. + /// @param node + /// @retval true always returns false, this is unimplemented. + /// @retval false always returns this, it is unimplemented. + + _Output Bool NeFileSystemMgr::Rewind(NodePtr node) + { + if (!node) + return false; + + return this->Seek(node, 0); + } + + /// @brief Returns the filesystem parser. + /// @return the Filesystem parser class. + _Output NeFileSystemParser* NeFileSystemMgr::GetParser() noexcept + { + return mParser; + } +} // namespace Kernel + +#endif // ifdef __FSKIT_INCLUDES_NEFS__ +#endif // ifndef __ZKA_MINIMAL_OS__ diff --git a/dev/Kernel/src/FS/NeFS+IO.cc b/dev/Kernel/src/FS/NeFS+IO.cc new file mode 100644 index 00000000..040f0171 --- /dev/null +++ b/dev/Kernel/src/FS/NeFS+IO.cc @@ -0,0 +1,101 @@ +/* ------------------------------------------- + + Copyright (C) 2024, MediaSwirl, all rights reserved. + +------------------------------------------- */ + +#include +#include + +/************************************************************* + * + * File: NeFS+IO.cc + * Purpose: Filesystem to mountpoint interface. + * Date: 3/26/24 + * + * Copyright (C) 2024, MediaSwirl, all rights reserved., all rights reserved. + * + *************************************************************/ + +#ifdef __FSKIT_INCLUDES_NEFS__ + +#include + +/// Useful macros. + +#define rtl_nefs_write(DRV, TRAITS, MP) (MP->DRV()).fOutput(&TRAITS) +#define rtl_nefs_read(DRV, TRAITS, MP) (MP->DRV()).fInput(&TRAITS) + +using namespace Kernel; + +/// @brief Read from newfs disk. +/// @param Mnt mounted interface. +/// @param DrvTrait drive info +/// @param DrvIndex drive index. +/// @return +Int32 fs_nefs_read(MountpointInterface* Mnt, DriveTrait& DrvTrait, Int32 DrvIndex) +{ + if (!Mnt) + return 1; + + DrvTrait.fPacket.fPacketGood = false; + + switch (DrvIndex) + { + case kNeFSSubDriveA: { + rtl_nefs_read(A, DrvTrait.fPacket, Mnt); + break; + } + case kNeFSSubDriveB: { + rtl_nefs_read(B, DrvTrait.fPacket, Mnt); + break; + } + case kNeFSSubDriveC: { + rtl_nefs_read(C, DrvTrait.fPacket, Mnt); + break; + } + case kNeFSSubDriveD: { + rtl_nefs_read(D, DrvTrait.fPacket, Mnt); + break; + } + } + + return DrvTrait.fPacket.fPacketGood; +} + +/// @brief Write to newfs disk. +/// @param Mnt mounted interface. +/// @param DrvTrait drive info +/// @param DrvIndex drive index. +/// @return +Int32 fs_nefs_write(MountpointInterface* Mnt, DriveTrait& DrvTrait, Int32 DrvIndex) +{ + if (!Mnt) + return 1; + + DrvTrait.fPacket.fPacketGood = false; + + switch (DrvIndex) + { + case kNeFSSubDriveA: { + rtl_nefs_write(A, DrvTrait.fPacket, Mnt); + break; + } + case kNeFSSubDriveB: { + rtl_nefs_write(B, DrvTrait.fPacket, Mnt); + break; + } + case kNeFSSubDriveC: { + rtl_nefs_write(C, DrvTrait.fPacket, Mnt); + break; + } + case kNeFSSubDriveD: { + rtl_nefs_write(D, DrvTrait.fPacket, Mnt); + break; + } + } + + return DrvTrait.fPacket.fPacketGood; +} + +#endif // ifdef __FSKIT_INCLUDES_NEFS__ diff --git a/dev/Kernel/src/NeFS+FileMgr.cc b/dev/Kernel/src/NeFS+FileMgr.cc deleted file mode 100644 index 685522a5..00000000 --- a/dev/Kernel/src/NeFS+FileMgr.cc +++ /dev/null @@ -1,245 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2024, MediaSwirl, all rights reserved. - -------------------------------------------- */ - -#include -#include - -#ifndef __ZKA_MINIMAL_OS__ -#ifdef __FSKIT_INCLUDES_NEFS__ - -/// @brief NeFS File manager. -/// BUGS: 0 - -namespace Kernel -{ - /// @brief C++ constructor - NeFileSystemMgr::NeFileSystemMgr() - { - NeFileSystemParser* mParser = new NeFileSystemParser(); - MUST_PASS(mParser); - - kcout << "We are done allocating NeFileSystemParser...\r"; - } - - NeFileSystemMgr::~NeFileSystemMgr() - { - if (mParser) - { - kcout << "Destroying NeFileSystemParser...\r"; - mm_delete_class(&mParser); - } - } - - /// @brief Removes a node from the filesystem. - /// @param path The filename - /// @return If it was deleted or not. - bool NeFileSystemMgr::Remove(_Input const Char* path) - { - if (path == nullptr || *path == 0) - return false; - - return mParser->RemoveCatalog(path); - } - - /// @brief Creates a node with the specified. - /// @param path The filename path. - /// @return The Node pointer. - NodePtr NeFileSystemMgr::Create(_Input const Char* path) - { - return node_cast(mParser->CreateCatalog(path)); - } - - /// @brief Creates a node with is a directory. - /// @param path The filename path. - /// @return The Node pointer. - NodePtr NeFileSystemMgr::CreateDirectory(const Char* path) - { - return node_cast(mParser->CreateCatalog(path, 0, kNeFSCatalogKindDir)); - } - - /// @brief Creates a node with is a alias. - /// @param path The filename path. - /// @return The Node pointer. - NodePtr NeFileSystemMgr::CreateAlias(const Char* path) - { - return node_cast(mParser->CreateCatalog(path, 0, kNeFSCatalogKindAlias)); - } - - /// @brief Creates a node with is a page file. - /// @param path The filename path. - /// @return The Node pointer. - NodePtr NeFileSystemMgr::CreateSwapFile(const Char* path) - { - return node_cast(mParser->CreateCatalog(path, 0, kNeFSCatalogKindPage)); - } - - /// @brief Gets the root directory. - /// @return - const Char* NeFileSystemHelper::Root() - { - return kNeFSRoot; - } - - /// @brief Gets the up-dir directory. - /// @return - const Char* NeFileSystemHelper::UpDir() - { - return kNeFSUpDir; - } - - /// @brief Gets the separator character. - /// @return - const Char NeFileSystemHelper::Separator() - { - return kNeFSSeparator; - } - - /// @brief Gets the metafile character. - /// @return - const Char NeFileSystemHelper::MetaFile() - { - return kNeFSMetaFilePrefix; - } - - /// @brief Opens a new file. - /// @param path - /// @param r - /// @return - _Output NodePtr NeFileSystemMgr::Open(_Input const Char* path, _Input const Char* r) - { - if (!path || *path == 0) - return nullptr; - - if (!r || *r == 0) - return nullptr; - - auto catalog = mParser->GetCatalog(path); - - return node_cast(catalog); - } - - /// @brief Writes to a catalog's fork. - /// @param node the node ptr. - /// @param data the data. - /// @param flags the size. - /// @return - Void NeFileSystemMgr::Write(_Input NodePtr node, _Input VoidPtr data, _Input Int32 flags, _Input SizeT size) - { - if (!node) - return; - if (!size) - return; - - constexpr auto cDataForkName = kNeFSDataFork; - this->Write(cDataForkName, node, data, flags, size); - } - - /// @brief Read from filesystem fork. - /// @param node the catalog node. - /// @param flags the flags with it. - /// @param sz the size to read. - /// @return - _Output VoidPtr NeFileSystemMgr::Read(_Input NodePtr node, _Input Int32 flags, _Input SizeT size) - { - if (!node) - return nullptr; - if (!size) - return nullptr; - - constexpr auto cDataForkName = kNeFSDataFork; - return this->Read(cDataForkName, node, flags, size); - } - - Void NeFileSystemMgr::Write(_Input const Char* name, - _Input NodePtr node, - _Input VoidPtr data, - _Input Int32 flags, - _Input SizeT size) - { - if (!size || - size > kNeFSForkSize) - return; - - if (!data) - return; - - ZKA_UNUSED(flags); - - if ((reinterpret_cast(node))->Kind == kNeFSCatalogKindFile) - mParser->WriteCatalog(reinterpret_cast(node), (flags & kFileFlagRsrc ? true : false), data, size, - name); - } - - _Output VoidPtr NeFileSystemMgr::Read(_Input const Char* name, - _Input NodePtr node, - _Input Int32 flags, - _Input SizeT sz) - { - if (sz > kNeFSForkSize) - return nullptr; - - if (!sz) - return nullptr; - - ZKA_UNUSED(flags); - - if ((reinterpret_cast(node))->Kind == kNeFSCatalogKindFile) - return mParser->ReadCatalog(reinterpret_cast(node), (flags & kFileFlagRsrc ? true : false), sz, - name); - - return nullptr; - } - - /// @brief Seek from Catalog. - /// @param node - /// @param off - /// @retval true always returns false, this is unimplemented. - /// @retval false always returns this, it is unimplemented. - - _Output Bool NeFileSystemMgr::Seek(NodePtr node, SizeT off) - { - if (!node || off == 0) - return false; - - return mParser->Seek(reinterpret_cast(node), off); - } - - /// @brief Tell where the catalog is. - /// @param node - /// @retval true always returns false, this is unimplemented. - /// @retval false always returns this, it is unimplemented. - - _Output SizeT NeFileSystemMgr::Tell(NodePtr node) - { - if (!node) - return kNPos; - - return mParser->Tell(reinterpret_cast(node)); - } - - /// @brief Rewinds the catalog. - /// @param node - /// @retval true always returns false, this is unimplemented. - /// @retval false always returns this, it is unimplemented. - - _Output Bool NeFileSystemMgr::Rewind(NodePtr node) - { - if (!node) - return false; - - return this->Seek(node, 0); - } - - /// @brief Returns the filesystem parser. - /// @return the Filesystem parser class. - _Output NeFileSystemParser* NeFileSystemMgr::GetParser() noexcept - { - return mParser; - } -} // namespace Kernel - -#endif // ifdef __FSKIT_INCLUDES_NEFS__ -#endif // ifndef __ZKA_MINIMAL_OS__ diff --git a/dev/Kernel/src/NeFS+IO.cc b/dev/Kernel/src/NeFS+IO.cc deleted file mode 100644 index 040f0171..00000000 --- a/dev/Kernel/src/NeFS+IO.cc +++ /dev/null @@ -1,101 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2024, MediaSwirl, all rights reserved. - -------------------------------------------- */ - -#include -#include - -/************************************************************* - * - * File: NeFS+IO.cc - * Purpose: Filesystem to mountpoint interface. - * Date: 3/26/24 - * - * Copyright (C) 2024, MediaSwirl, all rights reserved., all rights reserved. - * - *************************************************************/ - -#ifdef __FSKIT_INCLUDES_NEFS__ - -#include - -/// Useful macros. - -#define rtl_nefs_write(DRV, TRAITS, MP) (MP->DRV()).fOutput(&TRAITS) -#define rtl_nefs_read(DRV, TRAITS, MP) (MP->DRV()).fInput(&TRAITS) - -using namespace Kernel; - -/// @brief Read from newfs disk. -/// @param Mnt mounted interface. -/// @param DrvTrait drive info -/// @param DrvIndex drive index. -/// @return -Int32 fs_nefs_read(MountpointInterface* Mnt, DriveTrait& DrvTrait, Int32 DrvIndex) -{ - if (!Mnt) - return 1; - - DrvTrait.fPacket.fPacketGood = false; - - switch (DrvIndex) - { - case kNeFSSubDriveA: { - rtl_nefs_read(A, DrvTrait.fPacket, Mnt); - break; - } - case kNeFSSubDriveB: { - rtl_nefs_read(B, DrvTrait.fPacket, Mnt); - break; - } - case kNeFSSubDriveC: { - rtl_nefs_read(C, DrvTrait.fPacket, Mnt); - break; - } - case kNeFSSubDriveD: { - rtl_nefs_read(D, DrvTrait.fPacket, Mnt); - break; - } - } - - return DrvTrait.fPacket.fPacketGood; -} - -/// @brief Write to newfs disk. -/// @param Mnt mounted interface. -/// @param DrvTrait drive info -/// @param DrvIndex drive index. -/// @return -Int32 fs_nefs_write(MountpointInterface* Mnt, DriveTrait& DrvTrait, Int32 DrvIndex) -{ - if (!Mnt) - return 1; - - DrvTrait.fPacket.fPacketGood = false; - - switch (DrvIndex) - { - case kNeFSSubDriveA: { - rtl_nefs_write(A, DrvTrait.fPacket, Mnt); - break; - } - case kNeFSSubDriveB: { - rtl_nefs_write(B, DrvTrait.fPacket, Mnt); - break; - } - case kNeFSSubDriveC: { - rtl_nefs_write(C, DrvTrait.fPacket, Mnt); - break; - } - case kNeFSSubDriveD: { - rtl_nefs_write(D, DrvTrait.fPacket, Mnt); - break; - } - } - - return DrvTrait.fPacket.fPacketGood; -} - -#endif // ifdef __FSKIT_INCLUDES_NEFS__ -- cgit v1.2.3