summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-12-29 09:57:48 +0100
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-12-29 09:57:48 +0100
commit8b7216aaf2dacad7ce67d734d07b047fed8ec01e (patch)
tree7af56dd646a4d12a25024da7ad5e6406ff98f124
parent5b1bb6cc086047e99a1d246fd2d337bf76887bd8 (diff)
IMPL: NeFS: Add file lock feature and validation for it.
- It is added to hide files from indexing. - And will be used to hide system files. IMPL: Swap: Add SwapDiskDelegate class, will also work on a swap packet structure. Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
-rw-r--r--dev/Boot/BootKit/BootKit.h5
-rw-r--r--dev/Kernel/FSKit/NeFS.h16
-rw-r--r--dev/Kernel/KernelKit/LPC.h1
-rw-r--r--dev/Kernel/KernelKit/Timer.h1
-rw-r--r--dev/Kernel/KernelKit/UserProcessScheduler.h5
-rw-r--r--dev/Kernel/SystemKit/Scheduler.h (renamed from dev/Kernel/SystemKit/ThreadMgr.h)2
-rw-r--r--dev/Kernel/SystemKit/Swap.h (renamed from dev/Kernel/SystemKit/SwapMgr.h)4
-rw-r--r--dev/Kernel/src/FS/NeFS.cc23
-rw-r--r--dev/Kernel/src/Mgr/SwapMgr.cc28
-rw-r--r--dev/Kernel/src/System/SwapDiskDelegate.cc57
10 files changed, 96 insertions, 46 deletions
diff --git a/dev/Boot/BootKit/BootKit.h b/dev/Boot/BootKit/BootKit.h
index a92614f4..ab9f9b8f 100644
--- a/dev/Boot/BootKit/BootKit.h
+++ b/dev/Boot/BootKit/BootKit.h
@@ -278,8 +278,9 @@ namespace Boot
catalogKind.NextSibling = (startLba + sizeof(NFS_CATALOG_STRUCT) * cNeFSCatalogPadding);
/// Fill catalog kind.
- catalogKind.Kind = blob->fKind;
- catalogKind.Flags = kNeFSFlagCreated;
+ catalogKind.Kind = blob->fKind;
+ catalogKind.Flags = kNeFSFlagCreated;
+ catalogKind.Status = kNeFSStatusUnlocked;
--partBlock.FreeCatalog;
--partBlock.FreeSectors;
diff --git a/dev/Kernel/FSKit/NeFS.h b/dev/Kernel/FSKit/NeFS.h
index 6d0b6bfe..c33ffaf7 100644
--- a/dev/Kernel/FSKit/NeFS.h
+++ b/dev/Kernel/FSKit/NeFS.h
@@ -131,25 +131,33 @@ enum
kNeFSDriveCount = 7,
};
+enum
+{
+ kNeFSStatusUnlocked,
+ kNeFSStatusLocked,
+ kNeFSStatusError,
+ kNeFSStatusInvalid,
+};
+
/// @brief Catalog type.
struct PACKED NFS_CATALOG_STRUCT final
{
Kernel::Char Name[kNeFSNodeNameLen];
Kernel::Char Mime[kNeFSMimeNameLen];
- /// Catalog status flag.
+ /// Catalog flags.
Kernel::UInt16 Flags;
+ Kernel::UInt16 Status;
/// Custom catalog flags.
Kernel::UInt16 FilkMMFlags;
/// Catalog kind.
Kernel::Int32 Kind;
-
/// Size of the data fork.
Kernel::Lba DataForkSize;
-
/// Size of all resource forks.
Kernel::Lba ResourceForkSize;
+ /// Forks LBA.
Kernel::Lba DataFork;
Kernel::Lba ResourceFork;
@@ -264,7 +272,7 @@ namespace Kernel
_Output Void CloseFork(_Input NFS_FORK_STRUCT* fork);
- _Output NFS_CATALOG_STRUCT* FindCatalog(_Input const Char* catalogName, Lba& outLba);
+ _Output NFS_CATALOG_STRUCT* FindCatalog(_Input const Char* catalogName, Lba& outLba, Bool searchHidden = YES);
_Output NFS_CATALOG_STRUCT* GetCatalog(_Input const Char* name);
diff --git a/dev/Kernel/KernelKit/LPC.h b/dev/Kernel/KernelKit/LPC.h
index 6596d77f..c73c9da7 100644
--- a/dev/Kernel/KernelKit/LPC.h
+++ b/dev/Kernel/KernelKit/LPC.h
@@ -57,6 +57,7 @@ namespace Kernel
inline constexpr HError kErrorInvalidCreds = 61;
inline constexpr HError kErrorCDTrayBroken = 62;
inline constexpr HError kErrorUnrecoverableDisk = 63;
+ inline constexpr HError kErrorFileLocked = 64;
inline constexpr HError kErrorUnimplemented = 0;
/// @brief Raises a bug check stop code.
diff --git a/dev/Kernel/KernelKit/Timer.h b/dev/Kernel/KernelKit/Timer.h
index b95dc9ca..59c21d40 100644
--- a/dev/Kernel/KernelKit/Timer.h
+++ b/dev/Kernel/KernelKit/Timer.h
@@ -7,7 +7,6 @@
#pragma once
#include <ArchKit/ArchKit.h>
-#include <CompilerKit/CompilerKit.h>
#include <KernelKit/LPC.h>
namespace Kernel
diff --git a/dev/Kernel/KernelKit/UserProcessScheduler.h b/dev/Kernel/KernelKit/UserProcessScheduler.h
index 73780dc3..b79985dd 100644
--- a/dev/Kernel/KernelKit/UserProcessScheduler.h
+++ b/dev/Kernel/KernelKit/UserProcessScheduler.h
@@ -7,7 +7,6 @@
#ifndef INC_PROCESS_SCHEDULER_H
#define INC_PROCESS_SCHEDULER_H
-#include "NewKit/Defines.h"
#include <ArchKit/ArchKit.h>
#include <KernelKit/LockDelegate.h>
#include <KernelKit/User.h>
@@ -155,14 +154,14 @@ namespace Kernel
ZKA_COPY_DEFAULT(UserProcess);
public:
- Char Name[kProcessNameLen] = {"Process (Unnamed)"};
+ Char Name[kProcessNameLen] = {"Process (Unnamed, No Subsystem)"};
ProcessSubsystem SubSystem{ProcessSubsystem::kProcessSubsystemInvalid};
User* Owner{nullptr};
HAL::StackFramePtr StackFrame{nullptr};
AffinityKind Affinity{AffinityKind::kStandard};
ProcessStatusKind Status{ProcessStatusKind::kFinished};
UInt8* StackReserve{nullptr};
- UserProcessImage Image;
+ UserProcessImage Image{};
SizeT StackSize{kSchedMaxStackSz};
IDLLObject* DylibDelegate{nullptr};
SizeT MemoryCursor{0UL};
diff --git a/dev/Kernel/SystemKit/ThreadMgr.h b/dev/Kernel/SystemKit/Scheduler.h
index 27a9707a..5b6c8719 100644
--- a/dev/Kernel/SystemKit/ThreadMgr.h
+++ b/dev/Kernel/SystemKit/Scheduler.h
@@ -9,7 +9,7 @@
#include <NewKit/Defines.h>
-/// @file ThreadMgr.h
+/// @file Scheduler.h
/// @brief This file takes care of creating processes/threads from a subsystem context.
namespace Kernel
diff --git a/dev/Kernel/SystemKit/SwapMgr.h b/dev/Kernel/SystemKit/Swap.h
index 9f1ecc3e..5d9d1ade 100644
--- a/dev/Kernel/SystemKit/SwapMgr.h
+++ b/dev/Kernel/SystemKit/Swap.h
@@ -14,5 +14,5 @@
#define kSwapMgrPageFile "/System/pagefile.sys"
-/// @file SwapMgr.h
-/// @brief Virtual memory swap manager.
+/// @file Swap.h
+/// @brief Virtual memory swap API.
diff --git a/dev/Kernel/src/FS/NeFS.cc b/dev/Kernel/src/FS/NeFS.cc
index 27a027cd..bf39f7e6 100644
--- a/dev/Kernel/src/FS/NeFS.cc
+++ b/dev/Kernel/src/FS/NeFS.cc
@@ -720,7 +720,8 @@ bool NeFileSystemParser::WriteCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog
/// @param catalog_name the catalog name.
/// @return the newly found catalog.
_Output NFS_CATALOG_STRUCT* NeFileSystemParser::FindCatalog(_Input const Char* catalog_name,
- Lba& out_lba)
+ Lba& out_lba,
+ Bool search_hidden)
{
if (!catalog_name ||
*catalog_name == 0)
@@ -798,7 +799,7 @@ _Output NFS_CATALOG_STRUCT* NeFileSystemParser::FindCatalog(_Input const Char* c
}
}
- kcout << "Fetching catalog...\r";
+ kcout << "Finding catalog...\r";
NeFSSearchThroughCatalogList:
while (drive.fPacket.fPacketGood)
@@ -813,6 +814,14 @@ NeFSSearchThroughCatalogList:
if (StringBuilder::Equals(catalog_name, catalog->Name))
{
+ /// ignore it, it's locked.
+ if (catalog->Status == kNeFSStatusLocked &&
+ !search_hidden)
+ {
+ err_local_get() = kErrorFileLocked;
+ goto NeFSContinueSearch;
+ }
+
/// ignore unallocated catalog, break
if (!(catalog->Flags & kNeFSFlagCreated))
{
@@ -822,8 +831,8 @@ NeFSSearchThroughCatalogList:
NFS_CATALOG_STRUCT* catalogPtr = new NFS_CATALOG_STRUCT();
rt_copy_memory(catalog, catalogPtr, sizeof(NFS_CATALOG_STRUCT));
- kcout << "Found catalog at: " << hex_number(start_catalog_lba) << endl;
- kcout << "Found catalog at: " << catalog->Name << endl;
+ kcout << "Found available catalog at: " << hex_number(start_catalog_lba) << endl;
+ kcout << "Found available catalog at: " << catalog->Name << endl;
out_lba = start_catalog_lba;
return catalogPtr;
@@ -844,6 +853,8 @@ NeFSSearchThroughCatalogList:
goto NeFSSearchThroughCatalogList;
}
+ err_local_get() = kErrorFileNotFound;
+
out_lba = 0UL;
return nullptr;
}
@@ -854,7 +865,7 @@ NeFSSearchThroughCatalogList:
_Output NFS_CATALOG_STRUCT* NeFileSystemParser::GetCatalog(_Input const Char* name)
{
Lba unused = 0;
- return this->FindCatalog(name, unused);
+ return this->FindCatalog(name, unused, true);
}
/// @brief Closes a catalog, (frees it).
@@ -923,6 +934,8 @@ Boolean NeFileSystemParser::RemoveCatalog(_Input const Char* catalog_name)
}
delete catalog;
+ catalog = nullptr;
+
return false;
}
diff --git a/dev/Kernel/src/Mgr/SwapMgr.cc b/dev/Kernel/src/Mgr/SwapMgr.cc
deleted file mode 100644
index a909846f..00000000
--- a/dev/Kernel/src/Mgr/SwapMgr.cc
+++ /dev/null
@@ -1,28 +0,0 @@
-/* -------------------------------------------
-
- Copyright (C) 2024, Theater Quality Corp, all rights reserved.
-
-------------------------------------------- */
-
-#include <SystemKit/SwapMgr.h>
-#include <KernelKit/FileMgr.h>
-
-namespace Kernel
-{
- class SwapMgrDiskMgr;
-
- class SwapMgrDiskMgr final
- {
- static BOOL DumpToDisk(const Char* fork_name, const SizeT fork_name_len, VoidPtr data, const SizeT data_len)
- {
- if (!fork_name || !fork_name_len)
- return NO;
-
- FileStream file(kSwapMgrPageFile, "wb");
-
- file.Write(fork_name, data, data_len);
-
- return YES;
- }
- }
-} // namespace Kernel \ No newline at end of file
diff --git a/dev/Kernel/src/System/SwapDiskDelegate.cc b/dev/Kernel/src/System/SwapDiskDelegate.cc
new file mode 100644
index 00000000..ffe8812d
--- /dev/null
+++ b/dev/Kernel/src/System/SwapDiskDelegate.cc
@@ -0,0 +1,57 @@
+/* -------------------------------------------
+
+ Copyright (C) 2024, Theater Quality Corp, all rights reserved.
+
+------------------------------------------- */
+
+#include <SystemKit/Swap.h>
+#include <KernelKit/FileMgr.h>
+
+namespace Kernel::Detail
+{
+ class SwapDiskDelegate;
+
+ class SwapDiskDelegate final
+ {
+ public:
+ explicit SwapDiskDelegate() = default;
+ ~SwapDiskDelegate() = default;
+
+ ZKA_COPY_DEFAULT(SwapDiskDelegate);
+
+ BOOL Write(const Char* fork_name, const SizeT fork_name_len, VoidPtr data, const SizeT data_len)
+ {
+ if (!fork_name || !fork_name_len)
+ return NO;
+
+ if (data_len > mib_cast(16))
+ return NO;
+
+ if (!data)
+ return NO;
+
+ FileStream file(kSwapMgrPageFile, "wb");
+
+ if (file.Write(fork_name, data, data_len).Error())
+ {
+ return NO;
+ }
+
+ return YES;
+ }
+
+ VoidPtr Read(const Char* fork_name, const SizeT fork_name_len, const SizeT data_len)
+ {
+ if (!fork_name || !fork_name_len)
+ return nullptr;
+
+ if (data_len > mib_cast(16))
+ return nullptr;
+
+ FileStream file(kSwapMgrPageFile, "rb");
+
+ voidPtr blob = file.Read(fork_name, data_len);
+ return blob;
+ }
+ };
+} // namespace Kernel::Detail \ No newline at end of file