summaryrefslogtreecommitdiffhomepage
path: root/dev
diff options
context:
space:
mode:
authorAmlal <amlalelmahrouss@icloud.com>2024-12-13 20:51:37 +0100
committerAmlal <amlalelmahrouss@icloud.com>2024-12-13 20:51:37 +0100
commitb81ec0adfd76d4e495311e7d10913eb1cd61c108 (patch)
tree39574cf6bc0083b75c50dbb7f7e5958299e563c8 /dev
parent9c17f7485899dd007f1f2e1507c3b05cc29265c9 (diff)
ADD: NeFileSystemJournal class for the NeFS.
META: Other refactors have been done too. Signed-off-by: Amlal <amlalelmahrouss@icloud.com>
Diffstat (limited to 'dev')
-rw-r--r--dev/ZKAKit/FSKit/NeFS.h107
-rw-r--r--dev/ZKAKit/KernelKit/FileMgr.h4
-rw-r--r--dev/ZKAKit/src/FS/NeFS.cc28
-rw-r--r--dev/ZKAKit/src/NeFS+FileMgr.cc10
4 files changed, 107 insertions, 42 deletions
diff --git a/dev/ZKAKit/FSKit/NeFS.h b/dev/ZKAKit/FSKit/NeFS.h
index b58f1d34..8144744e 100644
--- a/dev/ZKAKit/FSKit/NeFS.h
+++ b/dev/ZKAKit/FSKit/NeFS.h
@@ -110,6 +110,10 @@ default.
#define kNeFSMimeNameLen (200)
#define kNeFSForkNameLen (200)
+#define kNeFSFrameworkExt ".fwrk"
+#define kNeFSApplicationExt ".app"
+#define kNeFSJournalExt ".jrnl"
+
struct NFS_CATALOG_STRUCT;
struct NFS_FORK_STRUCT;
struct NFS_ROOT_PARTITION_BLOCK;
@@ -198,12 +202,16 @@ struct PACKED NFS_ROOT_PARTITION_BLOCK final
Kernel::UInt64 Version;
Kernel::Lba EpmBlock;
-
+
Kernel::Char Pad[kNeFSPadLen];
};
namespace Kernel
{
+ class NeFileSystemParser;
+ class NeFileSystemJournal;
+ class NeFileSystemHelper;
+
enum
{
kNeFSSubDriveA,
@@ -222,18 +230,18 @@ namespace Kernel
};
///
- /// \name NeFSParser
+ /// \name NeFileSystemParser
/// \brief NeFS parser class. (catalog creation, remove removal, root,
/// forks...) Designed like the DOM, detects the filesystem automatically.
///
- class NeFSParser final
+ class NeFileSystemParser final
{
public:
- explicit NeFSParser() = default;
- ~NeFSParser() = default;
+ explicit NeFileSystemParser() = default;
+ ~NeFileSystemParser() = default;
public:
- ZKA_COPY_DEFAULT(NeFSParser);
+ ZKA_COPY_DEFAULT(NeFileSystemParser);
public:
/// @brief Creates a new fork inside the New filesystem partition.
@@ -290,7 +298,7 @@ namespace Kernel
bool Format(_Input _Output DriveTrait* drive, _Input const Lba endLba, _Input const Int32 flags, const Char* part_name);
public:
- Int32 fDriveIndex{kNeFSSubDriveA};
+ Int32 mDriveIndex{kNeFSSubDriveA};
};
///
@@ -307,6 +315,63 @@ namespace Kernel
STATIC const Char MetaFile();
};
+ class NeFileSystemJournal final
+ {
+ public:
+ explicit NeFileSystemJournal(const char* stamp)
+ {
+ if (!stamp)
+ {
+ kcout << "Invalid: Journal Stamp.\r";
+ return;
+ }
+
+ kcout << "Info: Journal stamp: " << stamp << endl;
+ rt_copy_memory((VoidPtr)stamp, this->mStamp, rt_string_len(stamp));
+ }
+
+ ~NeFileSystemJournal() = default;
+
+ ZKA_COPY_DEFAULT(NeFileSystemJournal);
+
+ Bool CreateJournal(NeFileSystemParser* parser)
+ {
+ if (!parser)
+ return NO;
+
+ auto node = parser->CreateCatalog(mStamp);
+
+ if (!node)
+ return NO;
+
+ delete node;
+ node = nullptr;
+
+ return YES;
+ }
+
+ Bool IsJournalValid(NeFileSystemParser* parser)
+ {
+ if (!parser)
+ return NO;
+
+ if (auto node = parser->GetCatalog(mStamp);
+ node)
+ {
+ delete node;
+ node = nullptr;
+
+ return YES;
+ }
+
+ return NO;
+ }
+
+ private:
+ Char mStamp[255] = { "/System/FileSystemStamp.jrnl" };
+
+ };
+
namespace Detail
{
Boolean fs_init_newfs(Void) noexcept;
@@ -314,19 +379,19 @@ namespace Kernel
} // namespace Kernel
/// @brief Write to newfs disk.
-/// @param Mnt mounted interface.
-/// @param DrvTrait drive info
-/// @param DrvIndex drive index.
-/// @return
-Kernel::Int32 fs_newfs_write(Kernel::MountpointInterface* Mnt,
- Kernel::DriveTrait& DrvTrait,
- Kernel::Int32 DrvIndex);
+/// @param drv_mnt mounted interface.
+/// @param drv_trait drive info
+/// @param drv_indx drive index.
+/// @return status code.
+Kernel::Int32 fs_newfs_write(Kernel::MountpointInterface* drv_mnt,
+ Kernel::DriveTrait& drv_trait,
+ Kernel::Int32 drv_indx);
/// @brief Read from newfs disk.
-/// @param Mnt mounted interface.
-/// @param DrvTrait drive info
-/// @param DrvIndex drive index.
-/// @return
-Kernel::Int32 fs_newfs_read(Kernel::MountpointInterface* Mnt,
- Kernel::DriveTrait& DrvTrait,
- Kernel::Int32 DrvIndex);
+/// @param drv_mnt mounted interface.
+/// @param drv_trait drive info
+/// @param drv_indx drive index.
+/// @return status code.
+Kernel::Int32 fs_newfs_read(Kernel::MountpointInterface* drv_mnt,
+ Kernel::DriveTrait& drv_trait,
+ Kernel::Int32 drv_indx);
diff --git a/dev/ZKAKit/KernelKit/FileMgr.h b/dev/ZKAKit/KernelKit/FileMgr.h
index 7c92df9f..68c98889 100644
--- a/dev/ZKAKit/KernelKit/FileMgr.h
+++ b/dev/ZKAKit/KernelKit/FileMgr.h
@@ -183,10 +183,10 @@ namespace Kernel
public:
/// @brief Get NeFS parser class.
/// @return The filesystem parser class.
- NeFSParser* GetParser() noexcept;
+ NeFileSystemParser* GetParser() noexcept;
private:
- NeFSParser* fImpl{nullptr};
+ NeFileSystemParser* fImpl{nullptr};
};
#endif // ifdef __FSKIT_INCLUDES_NEFS__
diff --git a/dev/ZKAKit/src/FS/NeFS.cc b/dev/ZKAKit/src/FS/NeFS.cc
index 4f18b296..7372e930 100644
--- a/dev/ZKAKit/src/FS/NeFS.cc
+++ b/dev/ZKAKit/src/FS/NeFS.cc
@@ -60,7 +60,7 @@ STATIC MountpointInterface kDiskMountpoint;
/// @param the_fork the fork itself.
/// @return the fork
/***********************************************************************************/
-_Output NFS_FORK_STRUCT* NeFSParser::CreateFork(_Input NFS_CATALOG_STRUCT* catalog,
+_Output NFS_FORK_STRUCT* NeFileSystemParser::CreateFork(_Input NFS_CATALOG_STRUCT* catalog,
_Input NFS_FORK_STRUCT& the_fork)
{
if (catalog && the_fork.ForkName[0] != 0 &&
@@ -169,7 +169,7 @@ _Output NFS_FORK_STRUCT* NeFSParser::CreateFork(_Input NFS_CATALOG_STRUCT* catal
/// @param name the fork name.
/// @return the fork.
/***********************************************************************************/
-_Output NFS_FORK_STRUCT* NeFSParser::FindFork(_Input NFS_CATALOG_STRUCT* catalog,
+_Output NFS_FORK_STRUCT* NeFileSystemParser::FindFork(_Input NFS_CATALOG_STRUCT* catalog,
_Input const Char* name,
Boolean isDataFork)
{
@@ -187,7 +187,7 @@ _Output NFS_FORK_STRUCT* NeFSParser::FindFork(_Input NFS_CATALOG_STRUCT* catalog
rt_copy_memory((VoidPtr) "fs/nefs-packet", drv.fPacket.fPacketMime, 16);
if (auto res =
- fs_newfs_read(&kDiskMountpoint, drv, this->fDriveIndex);
+ fs_newfs_read(&kDiskMountpoint, drv, this->mDriveIndex);
res)
{
switch (res)
@@ -224,7 +224,7 @@ _Output NFS_FORK_STRUCT* NeFSParser::FindFork(_Input NFS_CATALOG_STRUCT* catalog
/// @param name
/// @return catalog pointer.
/***********************************************************************************/
-_Output NFS_CATALOG_STRUCT* NeFSParser::CreateCatalog(_Input const Char* name)
+_Output NFS_CATALOG_STRUCT* NeFileSystemParser::CreateCatalog(_Input const Char* name)
{
return this->CreateCatalog(name, 0, kNeFSCatalogKindFile);
}
@@ -236,7 +236,7 @@ _Output NFS_CATALOG_STRUCT* NeFSParser::CreateCatalog(_Input const Char* name)
/// @param kind the catalog kind.
/// @return catalog pointer.
/***********************************************************************************/
-_Output NFS_CATALOG_STRUCT* NeFSParser::CreateCatalog(_Input const Char* name,
+_Output NFS_CATALOG_STRUCT* NeFileSystemParser::CreateCatalog(_Input const Char* name,
_Input const Int32& flags,
_Input const Int32& kind)
{
@@ -465,7 +465,7 @@ _Output NFS_CATALOG_STRUCT* NeFSParser::CreateCatalog(_Input const Char* name,
/// @brief Make a EPM+NeFS drive out of the disk.
/// @param drive The drive to write on.
/// @return If it was sucessful, see err_local_get().
-bool NeFSParser::Format(_Input _Output DriveTrait* drive, _Input const Lba endLba, _Input const Int32 flags, const Char* part_name)
+bool NeFileSystemParser::Format(_Input _Output DriveTrait* drive, _Input const Lba endLba, _Input const Int32 flags, const Char* part_name)
{
if (*part_name == 0 ||
endLba == 0)
@@ -631,7 +631,7 @@ bool NeFSParser::Format(_Input _Output DriveTrait* drive, _Input const Lba endLb
/// @param catalog the catalog itself
/// @param data the data.
/// @return if the catalog w rote the contents successfully.
-bool NeFSParser::WriteCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog, Bool is_rsrc_fork, _Input VoidPtr data, _Input SizeT size_of_data, _Input const Char* forkName)
+bool NeFileSystemParser::WriteCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog, Bool is_rsrc_fork, _Input VoidPtr data, _Input SizeT size_of_data, _Input const Char* forkName)
{
if (size_of_data > kNeFSForkDataSz ||
size_of_data == 0)
@@ -719,7 +719,7 @@ bool NeFSParser::WriteCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog, Bool i
/// @brief
/// @param catalogName the catalog name.
/// @return the newly found catalog.
-_Output NFS_CATALOG_STRUCT* NeFSParser::FindCatalog(_Input const Char* catalogName,
+_Output NFS_CATALOG_STRUCT* NeFileSystemParser::FindCatalog(_Input const Char* catalogName,
Lba& out_lba)
{
kcout << "Start finding catalog...\r";
@@ -847,7 +847,7 @@ NeFSSearchThroughCatalogList:
/// @brief Get catalog from filesystem.
/// @param name the catalog's name/
/// @return
-_Output NFS_CATALOG_STRUCT* NeFSParser::GetCatalog(_Input const Char* name)
+_Output NFS_CATALOG_STRUCT* NeFileSystemParser::GetCatalog(_Input const Char* name)
{
Lba unused = 0;
return this->FindCatalog(name, unused);
@@ -856,7 +856,7 @@ _Output NFS_CATALOG_STRUCT* NeFSParser::GetCatalog(_Input const Char* name)
/// @brief Closes a catalog, (frees it).
/// @param catalog the catalog to close.
/// @return
-Boolean NeFSParser::CloseCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog)
+Boolean NeFileSystemParser::CloseCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog)
{
if (!catalog)
return false;
@@ -870,7 +870,7 @@ Boolean NeFSParser::CloseCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog)
/// @brief Mark catalog as removed.
/// @param catalog The catalog structure.
/// @return if the catalog was removed or not.
-Boolean NeFSParser::RemoveCatalog(_Input const Char* catalogName)
+Boolean NeFileSystemParser::RemoveCatalog(_Input const Char* catalogName)
{
if (!catalogName ||
StringBuilder::Equals(catalogName, NeFileSystemHelper::Root()))
@@ -933,7 +933,7 @@ Boolean NeFSParser::RemoveCatalog(_Input const Char* catalogName)
/// @return
/***********************************************************************************/
-VoidPtr NeFSParser::ReadCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog,
+VoidPtr NeFileSystemParser::ReadCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog,
_Input Bool is_rsrc_fork,
_Input SizeT dataSz,
_Input const Char* forkName)
@@ -996,7 +996,7 @@ VoidPtr NeFSParser::ReadCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog,
/// @return if the seeking was successful.
/***********************************************************************************/
-bool NeFSParser::Seek(_Input _Output NFS_CATALOG_STRUCT* catalog, SizeT off)
+bool NeFileSystemParser::Seek(_Input _Output NFS_CATALOG_STRUCT* catalog, SizeT off)
{
if (!catalog)
{
@@ -1014,7 +1014,7 @@ bool NeFSParser::Seek(_Input _Output NFS_CATALOG_STRUCT* catalog, SizeT off)
/// @return The position on the file.
/***********************************************************************************/
-SizeT NeFSParser::Tell(_Input _Output NFS_CATALOG_STRUCT* catalog)
+SizeT NeFileSystemParser::Tell(_Input _Output NFS_CATALOG_STRUCT* catalog)
{
if (!catalog)
{
diff --git a/dev/ZKAKit/src/NeFS+FileMgr.cc b/dev/ZKAKit/src/NeFS+FileMgr.cc
index 1d9f73f1..12d9f08c 100644
--- a/dev/ZKAKit/src/NeFS+FileMgr.cc
+++ b/dev/ZKAKit/src/NeFS+FileMgr.cc
@@ -20,18 +20,18 @@ namespace Kernel
{
MUST_PASS(Detail::fs_init_newfs());
- NeFSParser* fImpl;
- mm_new_class<NeFSParser>(&fImpl);
+ NeFileSystemParser* fImpl;
+ mm_new_class<NeFileSystemParser>(&fImpl);
MUST_PASS(fImpl);
- kcout << "We are done allocating NeFSParser...\r";
+ kcout << "We are done allocating NeFileSystemParser...\r";
}
NeFileSystemMgr::~NeFileSystemMgr()
{
if (fImpl)
{
- kcout << "Destroying NeFSParser...\r";
+ kcout << "Destroying NeFileSystemParser...\r";
mm_delete_class(&fImpl);
}
@@ -239,7 +239,7 @@ namespace Kernel
/// @brief Returns the filesystem parser.
/// @return the Filesystem parser class.
- _Output NeFSParser* NeFileSystemMgr::GetParser() noexcept
+ _Output NeFileSystemParser* NeFileSystemMgr::GetParser() noexcept
{
return fImpl;
}