summaryrefslogtreecommitdiffhomepage
path: root/dev/ZKA
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-08-19 10:14:36 +0200
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-08-19 10:14:36 +0200
commit933d1ef6721903895b15c45917a0fc705763fbf5 (patch)
tree1aed4505be011528b6a9799bcd29bbc846eefb4a /dev/ZKA
parentda70596895d8135e08f8caac6978117697b4c021 (diff)
[IMP]
+ Fixed big parts of the user manager's code. + Fixed New FS kernel support. + Allocate 2GB of RAM for kernel. - Reported bug to Jira regarding UserManager's TryLogin method. Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'dev/ZKA')
-rw-r--r--dev/ZKA/CompilerKit/Version.hxx4
-rw-r--r--dev/ZKA/Docs/SPECIFICATION.md6
-rw-r--r--dev/ZKA/FSKit/NewFS.hxx25
-rw-r--r--dev/ZKA/FirmwareKit/Handover.hxx8
-rw-r--r--dev/ZKA/HALKit/AMD64/HalKernelMain.cxx23
-rw-r--r--dev/ZKA/HALKit/AMD64/Processor.hxx3
-rw-r--r--dev/ZKA/KernelKit/FileManager.hxx10
-rw-r--r--dev/ZKA/KernelKit/User.hxx4
-rw-r--r--dev/ZKA/Sources/FS/NewFS.cxx100
-rw-r--r--dev/ZKA/Sources/FileManager.cxx2
-rw-r--r--dev/ZKA/Sources/Heap.cxx2
-rw-r--r--dev/ZKA/Sources/NewFS+FileManager.cxx4
-rw-r--r--dev/ZKA/Sources/PageManager.cxx4
-rw-r--r--dev/ZKA/Sources/ProcessScheduler.cxx1
-rw-r--r--dev/ZKA/Sources/User.cxx91
15 files changed, 169 insertions, 118 deletions
diff --git a/dev/ZKA/CompilerKit/Version.hxx b/dev/ZKA/CompilerKit/Version.hxx
index c0d42603..edff10c5 100644
--- a/dev/ZKA/CompilerKit/Version.hxx
+++ b/dev/ZKA/CompilerKit/Version.hxx
@@ -1,4 +1,4 @@
#pragma once
-#define BOOTLOADER_VERSION L"v1.14.2"
-#define KERNEL_VERSION "v1.14.2"
+#define BOOTLOADER_VERSION "VERSION: v1.14.2"
+#define KERNEL_VERSION "VERSION: v1.14.2"
diff --git a/dev/ZKA/Docs/SPECIFICATION.md b/dev/ZKA/Docs/SPECIFICATION.md
index e58d63ee..ded0aa12 100644
--- a/dev/ZKA/Docs/SPECIFICATION.md
+++ b/dev/ZKA/Docs/SPECIFICATION.md
@@ -10,7 +10,7 @@
===================================
-# 1: The NewKernel
+# 1: The Kernel
===================================
@@ -20,8 +20,8 @@
- Networking.
- Hardware Abstraction Layer.
- Native Filesystem support (NewFS, FAT32 and ffs2).
-- Program Loaders.
-- Thread Local Storage.
+- Program Loaders interfaces.
+- TLS (Thread Local Storage) support.
- Semaphore, Locks, Timers.
- Canary mechanisms.
- Dynamic Sys.
diff --git a/dev/ZKA/FSKit/NewFS.hxx b/dev/ZKA/FSKit/NewFS.hxx
index 54b11e38..830d8b0e 100644
--- a/dev/ZKA/FSKit/NewFS.hxx
+++ b/dev/ZKA/FSKit/NewFS.hxx
@@ -248,24 +248,25 @@ 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);
- _Output NFS_CATALOG_STRUCT* GetCatalog(_Input const char* name);
+ _Output NFS_CATALOG_STRUCT* GetCatalog(_Input const Char* name);
- _Output NFS_CATALOG_STRUCT* CreateCatalog(_Input const char* name,
+ _Output NFS_CATALOG_STRUCT* CreateCatalog(_Input const Char* name,
_Input const Int32& flags,
_Input const Int32& kind);
- _Output NFS_CATALOG_STRUCT* CreateCatalog(_Input const char* name);
+ _Output NFS_CATALOG_STRUCT* CreateCatalog(_Input const Char* name);
Bool WriteCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog,
- voidPtr data,
- SizeT sizeOfData,
- _Input const char* forkName);
+ _Input Bool isRsrcFork,
+ _Input VoidPtr data,
+ _Input SizeT sizeOfData,
+ _Input const Char* forkName);
VoidPtr ReadCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog,
SizeT dataSz,
- _Input const char* forkName);
+ _Input const Char* forkName);
bool Seek(_Input _Output NFS_CATALOG_STRUCT* catalog, SizeT off);
@@ -292,10 +293,10 @@ namespace Kernel
class NewFilesystemHelper final
{
public:
- STATIC const char* Root();
- STATIC const char* UpDir();
- STATIC const char Separator();
- STATIC const char MetaFile();
+ STATIC const Char* Root();
+ STATIC const Char* UpDir();
+ STATIC const Char Separator();
+ STATIC const Char MetaFile();
};
namespace Detail
diff --git a/dev/ZKA/FirmwareKit/Handover.hxx b/dev/ZKA/FirmwareKit/Handover.hxx
index a93ace39..96daa1dc 100644
--- a/dev/ZKA/FirmwareKit/Handover.hxx
+++ b/dev/ZKA/FirmwareKit/Handover.hxx
@@ -26,6 +26,8 @@
#define kHandoverMaxCmdLine 8
+#define kHandoverHeapSz gib_cast(2)
+
#define kHandoverStructSz sizeof(HEL::HandoverHeader)
namespace Kernel::HEL
@@ -56,9 +58,11 @@ namespace Kernel::HEL
UInt64 f_Magic;
UInt64 f_Version;
- voidPtr f_VirtualStart;
+ VoidPtr f_VirtualStart;
SizeT f_VirtualSize;
- voidPtr f_PhysicalStart;
+ VoidPtr f_PhysicalStart;
+
+ VoidPtr f_HeapStart;
WideChar f_FirmwareVendorName[32];
SizeT f_FirmwareVendorLen;
diff --git a/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx b/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx
index 49ddfa6c..17502b7c 100644
--- a/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx
+++ b/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx
@@ -86,10 +86,12 @@ EXTERN_C void hal_init_platform(
}
Kernel::Void hal_real_init(Kernel::Void) noexcept
-{
+{
// reset kAllocationInProgress field to zero.
kAllocationInProgress = false;
+ kKernelVMTStart = kHandoverHeader->f_HeapStart;
+
// get page size.
kKernelVirtualSize = kHandoverHeader->f_VirtualSize;
@@ -215,36 +217,39 @@ Kernel::Void hal_real_init(Kernel::Void) noexcept
kSyscalls[cLastExitInterrupt].Leak().Leak()->fHooked = true;
kSyscalls[cShutdownInterrupt].Leak().Leak()->fHooked = true;
kSyscalls[cRebootInterrupt].Leak().Leak()->fHooked = true;
-
+
Kernel::HAL::hal_system_get_cores(kHandoverHeader->f_HardwareTables.f_VendorPtr);
Kernel::kcout << "newoskrnl: Creating filesystem and such.\r";
auto fs = new Kernel::NewFilesystemManager();
-
+
MUST_PASS(fs);
MUST_PASS(fs->GetParser());
Kernel::NewFilesystemManager::Mount(fs);
- delete fs->GetParser()->CreateCatalog("\\Users\\", 0, kNewFSCatalogKindDir);
-
- Kernel::kcout << "newoskrnl: Created filesystem and now creating " << kSuperUser << "..." << Kernel::endl;
+ if (auto node = fs->GetParser()->GetCatalog("\\Users\\");
+ !node)
+ {
+ delete fs->GetParser()->CreateCatalog("\\Users\\", 0, kNewFSCatalogKindDir);
+ }
cRoot = new Kernel::User(Kernel::RingKind::kRingSuperUser, kSuperUser);
#ifdef __DEBUG__
- const auto cPassword = "6aa162f3-20f6-4143-92f9-5dd37066aedc";
+ const auto cPassword = "infdev";
#else
const auto cPassword = "password";
#endif
-
+
Kernel::UserManager::The()->fRootUser = cRoot;
Kernel::kcout << "newoskrnl: Root is " << kSuperUser << "." << Kernel::endl;
cRoot->TrySave(cPassword);
-
+
+ /// TODO: Fix this now!
Kernel::UserManager::The()->TryLogIn(cRoot, cPassword);
Kernel::ke_stop(RUNTIME_CHECK_FAILED);
diff --git a/dev/ZKA/HALKit/AMD64/Processor.hxx b/dev/ZKA/HALKit/AMD64/Processor.hxx
index d80a2834..8d9fc1b8 100644
--- a/dev/ZKA/HALKit/AMD64/Processor.hxx
+++ b/dev/ZKA/HALKit/AMD64/Processor.hxx
@@ -40,7 +40,6 @@ EXTERN_C
#define kTaskGate (0b10001100)
#define kGdtCodeSelector (0x08)
#define kGdtUserCodeSelector (0x10)
-#define cHeapStartOffset (0x80000000)
namespace Kernel
{
@@ -341,7 +340,7 @@ EXTERN_C Kernel::Void hal_load_gdt(Kernel::HAL::RegisterGDT ptr);
#define kKernelIdtSize 0x100
#define kKernelInterruptId 0x32
-inline Kernel::VoidPtr kKernelVMTStart = (Kernel::VoidPtr)cHeapStartOffset;
+inline Kernel::VoidPtr kKernelVMTStart = nullptr;
inline Kernel::VoidPtr kKernelVirtualStart = nullptr;
inline Kernel::UIntPtr kKernelVirtualSize = 0UL;
diff --git a/dev/ZKA/KernelKit/FileManager.hxx b/dev/ZKA/KernelKit/FileManager.hxx
index 68fa1eb5..e27bcc35 100644
--- a/dev/ZKA/KernelKit/FileManager.hxx
+++ b/dev/ZKA/KernelKit/FileManager.hxx
@@ -59,6 +59,9 @@ namespace Kernel
cFileReadChunk = 102,
cFileWriteChunk = 103,
cFileIOCnt = (cFileWriteChunk - cFileWriteAll) + 1,
+ // file flags
+ cFileFlagRsrc = 104,
+ cFileFlagData = 105,
};
/// @brief filesystem node generic type.
@@ -173,11 +176,8 @@ namespace Kernel
_Input SizeT sz) override;
public:
- void SetResourceFork(const char* forkName);
- void SetDataFork(const char* forkName);
-
- /// @brief Get internal parser.
- /// @return
+ /// @brief Get NewFS parser class.
+ /// @return The filesystem parser class.
NewFSParser* GetParser() noexcept;
private:
diff --git a/dev/ZKA/KernelKit/User.hxx b/dev/ZKA/KernelKit/User.hxx
index 56014c9b..ed1f6047 100644
--- a/dev/ZKA/KernelKit/User.hxx
+++ b/dev/ZKA/KernelKit/User.hxx
@@ -59,7 +59,7 @@ namespace Kernel
const RingKind& Ring() noexcept;
/// @brief Get user name
- StringView& Name() noexcept;
+ Char* Name() noexcept;
/// @brief Is he a standard user?
Bool IsStdUser() noexcept;
@@ -71,7 +71,7 @@ namespace Kernel
private:
RingKind fRing{RingKind::kRingStdUser};
- StringView fUserName;
+ Char fUserName[kMaxUserNameLen];
VoidPtr fUserToken{nullptr};
friend UserManager;
diff --git a/dev/ZKA/Sources/FS/NewFS.cxx b/dev/ZKA/Sources/FS/NewFS.cxx
index 90f48eb2..bea3e9ec 100644
--- a/dev/ZKA/Sources/FS/NewFS.cxx
+++ b/dev/ZKA/Sources/FS/NewFS.cxx
@@ -52,10 +52,9 @@ STATIC MountpointInterface sMountpointInterface;
/// @param theFork the fork itself.
/// @return the fork
_Output NFS_FORK_STRUCT* NewFSParser::CreateFork(_Input NFS_CATALOG_STRUCT* catalog,
- _Input NFS_FORK_STRUCT& theFork)
+ _Input NFS_FORK_STRUCT& theFork)
{
- if (catalog && theFork.ForkName[0] != 0 &&
- theFork.DataSize == kNewFSForkSize)
+ if (catalog && theFork.ForkName[0] != 0)
{
Lba lba = (theFork.Kind == kNewFSDataForkKind) ? catalog->DataFork
: catalog->ResourceFork;
@@ -87,11 +86,17 @@ _Output NFS_FORK_STRUCT* NewFSParser::CreateFork(_Input NFS_CATALOG_STRUCT* cata
drv.fInput(&drv.fPacket);
+ if (curFork.NextSibling > kBadAddress)
+ {
+ kcout << "newoskrnl: bad fork: " << hex_number(curFork.NextSibling) << endl;
+ break;
+ }
+
kcout << "newoskrnl: next fork: " << hex_number(curFork.NextSibling) << endl;
if (curFork.Flags == kNewFSFlagCreated)
{
- kcout << "newoskrnl: Fork already exists.\r";
+ kcout << "newoskrnl: fork already exists.\r";
/// sanity check.
if (StringBuilder::Equals(curFork.ForkName, theFork.ForkName) &&
@@ -156,8 +161,8 @@ _Output NFS_FORK_STRUCT* NewFSParser::CreateFork(_Input NFS_CATALOG_STRUCT* cata
/// @param name the fork name.
/// @return the fork.
_Output NFS_FORK_STRUCT* NewFSParser::FindFork(_Input NFS_CATALOG_STRUCT* catalog,
- _Input const Char* name,
- Boolean isDataFork)
+ _Input const Char* name,
+ Boolean isDataFork)
{
auto drv = sMountpointInterface.A();
NFS_FORK_STRUCT* theFork = nullptr;
@@ -218,7 +223,7 @@ _Output NFS_CATALOG_STRUCT* NewFSParser::CreateCatalog(_Input const Char* name)
/// @param flags the flags of the catalog.
/// @param kind the catalog kind.
/// @return catalog pointer.
-_Output NFS_CATALOG_STRUCT* NewFSParser::CreateCatalog(_Input const Char* name,
+_Output NFS_CATALOG_STRUCT* NewFSParser::CreateCatalog(_Input const Char* name,
_Input const Int32& flags,
_Input const Int32& kind)
{
@@ -238,14 +243,14 @@ _Output NFS_CATALOG_STRUCT* NewFSParser::CreateCatalog(_Input const Char* name,
name[rt_string_len(name) - 1] == NewFilesystemHelper::Separator())
return nullptr;
- NFS_CATALOG_STRUCT* copyExists = this->FindCatalog(name, outLba);
+ NFS_CATALOG_STRUCT* catalog_copy = this->FindCatalog(name, outLba);
- if (copyExists)
+ if (catalog_copy)
{
- kcout << "newoskrnl: Copy already exists.\r";
+ kcout << "newoskrnl: Catalog already exists: " << name << ".\r";
ErrLocal() = kErrorFileExists;
- return copyExists;
+ return catalog_copy;
}
Char parentName[kNewFSNodeNameLen] = {0};
@@ -327,31 +332,31 @@ _Output NFS_CATALOG_STRUCT* NewFSParser::CreateCatalog(_Input const Char* name,
auto drive = sMountpointInterface.A();
- Lba startFree = outLba;
+ Lba start_free = outLba;
rt_copy_memory((VoidPtr) "fs/newfs-packet", drive.fPacket.fPacketMime,
rt_string_len("fs/newfs-packet"));
drive.fPacket.fPacketContent = catalogBuf;
drive.fPacket.fPacketSize = kNewFSSectorSz;
- drive.fPacket.fLba = startFree;
+ drive.fPacket.fLba = start_free;
drive.fInput(&drive.fPacket);
NFS_CATALOG_STRUCT* nextSibling = (NFS_CATALOG_STRUCT*)catalogBuf;
- startFree = nextSibling->NextSibling;
+ start_free = nextSibling->NextSibling;
catalogChild->PrevSibling = outLba;
- drive.fPacket.fLba = startFree;
+ drive.fPacket.fLba = start_free;
drive.fInput(&drive.fPacket);
while (drive.fPacket.fPacketGood)
{
nextSibling = reinterpret_cast<NFS_CATALOG_STRUCT*>(catalogBuf);
- if (startFree <= kNewFSStartLba)
+ if (start_free <= kNewFSStartLba)
{
delete catalogChild;
delete catalog;
@@ -387,28 +392,28 @@ _Output NFS_CATALOG_STRUCT* NewFSParser::CreateCatalog(_Input const Char* name,
catalogChild->ResourceFork = catalogChild->DataFork;
catalogChild->NextSibling =
- startFree + (sizeof(NFS_CATALOG_STRUCT) * cNewFSCatalogPadding);
+ start_free + (sizeof(NFS_CATALOG_STRUCT) * cNewFSCatalogPadding);
drive.fPacket.fPacketContent = catalogChild;
drive.fPacket.fPacketSize = sizeof(NFS_CATALOG_STRUCT);
- drive.fPacket.fLba = startFree;
+ drive.fPacket.fLba = start_free;
drive.fOutput(&drive.fPacket);
drive.fPacket.fPacketContent = catalogBuf;
drive.fPacket.fPacketSize = kNewFSSectorSz;
drive.fPacket.fLba =
- startFree - (sizeof(NFS_CATALOG_STRUCT) * cNewFSCatalogPadding);
+ start_free - (sizeof(NFS_CATALOG_STRUCT) * cNewFSCatalogPadding);
drive.fInput(&drive.fPacket);
- nextSibling->NextSibling = startFree;
+ nextSibling->NextSibling = start_free;
drive.fOutput(&drive.fPacket);
kcout << "newoskrnl: Create new catalog, status: "
<< hex_number(catalogChild->Flags) << endl;
- kcout << "newoskrnl: Create new catalog, status: " << catalogChild->Name
+ kcout << "newoskrnl: Create new catalog, name: " << catalogChild->Name
<< endl;
drive.fPacket.fPacketContent = sectorBufPartBlock;
@@ -431,11 +436,11 @@ _Output NFS_CATALOG_STRUCT* NewFSParser::CreateCatalog(_Input const Char* name,
constexpr auto cNewFSCatalogPadding = 4;
//// @note that's how we find the next catalog in the partition block.
- startFree = startFree + (sizeof(NFS_CATALOG_STRUCT) * cNewFSCatalogPadding);
+ start_free = start_free + (sizeof(NFS_CATALOG_STRUCT) * cNewFSCatalogPadding);
drive.fPacket.fPacketContent = catalogBuf;
drive.fPacket.fPacketSize = kNewFSSectorSz;
- drive.fPacket.fLba = startFree;
+ drive.fPacket.fLba = start_free;
drive.fInput(&drive.fPacket);
}
@@ -611,18 +616,15 @@ bool NewFSParser::Format(_Input _Output DriveTrait* drive, _Input const Lba endL
/// @param catalog the catalog itself
/// @param data the data.
/// @return if the catalog w rote the contents successfully.
-bool NewFSParser::WriteCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog, voidPtr data, SizeT sizeOfData, _Input const Char* forkName)
+bool NewFSParser::WriteCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog, Bool isRsrcFork, _Input VoidPtr data, _Input SizeT sizeOfData, _Input const Char* forkName)
{
- NFS_FORK_STRUCT forkData{0};
-
auto drive = sMountpointInterface.A();
rt_copy_memory((VoidPtr) "fs/newfs-packet", drive.fPacket.fPacketMime,
rt_string_len("fs/newfs-packet"));
- auto startFork = catalog->DataFork;
-
- rt_copy_memory(catalog->Name, forkData.CatalogName, kNewFSNodeNameLen);
+ auto startFork = (!isRsrcFork) ? catalog->DataFork
+ : catalog->ResourceFork;
NFS_FORK_STRUCT forkDataIn{0};
@@ -635,8 +637,6 @@ bool NewFSParser::WriteCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog, voidP
drive.fInput(&drive.fPacket);
- kcout << "newoskrnl: fork name: " << forkName << endl;
-
// check the fork, if it's position is valid.
if (forkDataIn.DataOffset <= kNewFSCatalogStartAddress)
{
@@ -647,22 +647,22 @@ bool NewFSParser::WriteCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog, voidP
return false;
}
- if (forkData.Flags != kNewFSFlagUnallocated &&
- forkData.Flags != kNewFSFlagDeleted &&
- StringBuilder::Equals(forkData.ForkName, forkName) &&
- StringBuilder::Equals(forkData.CatalogName, catalog->Name))
+ if (forkDataIn.Flags != kNewFSFlagUnallocated &&
+ forkDataIn.Flags != kNewFSFlagDeleted &&
+ StringBuilder::Equals(forkDataIn.ForkName, forkName) &&
+ StringBuilder::Equals(forkDataIn.CatalogName, catalog->Name))
{
if (forkDataIn.DataSize < sizeOfData)
{
- startFork = forkData.NextSibling;
+ startFork = forkDataIn.NextSibling;
continue;
}
drive.fPacket.fPacketContent = data;
drive.fPacket.fPacketSize = sizeOfData;
- drive.fPacket.fLba = forkData.DataOffset;
+ drive.fPacket.fLba = forkDataIn.DataOffset;
- kcout << "newoskrnl: data offset: " << hex_number(forkData.DataOffset) << endl;
+ kcout << "newoskrnl: data offset: " << hex_number(forkDataIn.DataOffset) << endl;
drive.fOutput(&drive.fPacket);
@@ -673,35 +673,37 @@ bool NewFSParser::WriteCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog, voidP
// ===================================================== //
// Store size of blob now.
// ===================================================== //
- forkData.DataSize = sizeOfData;
- if (sizeOfData < kNewFSForkSize)
- forkData.DataSize = kNewFSForkSize;
+ if (forkDataIn.DataSize < sizeOfData)
+ {
+ startFork = forkDataIn.NextSibling;
+ continue;
+ }
+
+ forkDataIn.Flags = kNewFSFlagCreated;
drive.fPacket.fPacketContent = data;
drive.fPacket.fPacketSize = sizeOfData;
- drive.fPacket.fLba = forkData.DataOffset;
+ drive.fPacket.fLba = forkDataIn.DataOffset;
- kcout << "newoskrnl: data offset: " << hex_number(forkData.DataOffset) << endl;
+ kcout << "newoskrnl: data offset: " << hex_number(forkDataIn.DataOffset) << endl;
drive.fOutput(&drive.fPacket);
- forkData.Flags = kNewFSFlagCreated;
-
- drive.fPacket.fPacketContent = &forkData;
+ drive.fPacket.fPacketContent = &forkDataIn;
drive.fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT);
drive.fPacket.fLba = startFork;
drive.fOutput(&drive.fPacket);
- kcout << "newoskrnl: wrote fork at offset: " << hex_number(forkData.DataOffset) << endl;
+ kcout << "newoskrnl: wrote fork at offset: " << hex_number(forkDataIn.DataOffset) << endl;
delete catalog;
return true;
}
- startFork = forkData.NextSibling;
+ startFork = forkDataIn.NextSibling;
}
return false;
@@ -922,7 +924,7 @@ Boolean NewFSParser::RemoveCatalog(_Input const Char* catalogName)
VoidPtr NewFSParser::ReadCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog,
_Input SizeT dataSz,
- _Input const Char* forkName)
+ _Input const Char* forkName)
{
if (!catalog)
{
diff --git a/dev/ZKA/Sources/FileManager.cxx b/dev/ZKA/Sources/FileManager.cxx
index aa8fca2a..b590ef69 100644
--- a/dev/ZKA/Sources/FileManager.cxx
+++ b/dev/ZKA/Sources/FileManager.cxx
@@ -122,7 +122,7 @@ namespace Kernel
NEWOS_UNUSED(flags);
if ((reinterpret_cast<NFS_CATALOG_STRUCT*>(node))->Kind == kNewFSCatalogKindFile)
- fImpl->WriteCatalog(reinterpret_cast<NFS_CATALOG_STRUCT*>(node), data, size,
+ fImpl->WriteCatalog(reinterpret_cast<NFS_CATALOG_STRUCT*>(node), (flags & cFileFlagRsrc ? true : false), data, size,
name);
}
diff --git a/dev/ZKA/Sources/Heap.cxx b/dev/ZKA/Sources/Heap.cxx
index de0c8a5c..de9eaa86 100644
--- a/dev/ZKA/Sources/Heap.cxx
+++ b/dev/ZKA/Sources/Heap.cxx
@@ -94,8 +94,6 @@ namespace Kernel
if (szFix == 0)
++szFix;
- kcout << "newoskrnl: allocating VMH page...\r";
-
auto wrapper = kHeapPageManager.Request(rw, user, false, szFix);
Detail::HEAP_INFORMATION_BLOCK_PTR heap_info_ptr =
diff --git a/dev/ZKA/Sources/NewFS+FileManager.cxx b/dev/ZKA/Sources/NewFS+FileManager.cxx
index f94831cd..36a0e984 100644
--- a/dev/ZKA/Sources/NewFS+FileManager.cxx
+++ b/dev/ZKA/Sources/NewFS+FileManager.cxx
@@ -49,7 +49,7 @@ namespace Kernel
/// @return The Node pointer.
NodePtr NewFilesystemManager::Create(const char* path)
{
- return node_cast(fImpl->CreateCatalog(path, 0, kNewFSCatalogKindFile));
+ return node_cast(fImpl->CreateCatalog(path));
}
/// @brief Creates a node with is a directory.
@@ -90,7 +90,7 @@ namespace Kernel
}
/// @brief Gets the metafile character.
- /// @return
+ /// @return
const char NewFilesystemHelper::MetaFile()
{
return kNewFSMetaFilePrefix;
diff --git a/dev/ZKA/Sources/PageManager.cxx b/dev/ZKA/Sources/PageManager.cxx
index 7e0ef67b..868a9f7a 100644
--- a/dev/ZKA/Sources/PageManager.cxx
+++ b/dev/ZKA/Sources/PageManager.cxx
@@ -63,11 +63,9 @@ namespace Kernel
/// @return
PTEWrapper PageManager::Request(Boolean Rw, Boolean User, Boolean ExecDisable, SizeT Sz)
{
- kcout << "newoskrnl: Allocating VMH page from PageManager...\r";
-
// Store PTE wrapper right after PTE.
VoidPtr ptr = Kernel::HAL::hal_alloc_page(Rw, User, Sz);
-
+
if (ptr == kBadAddress)
{
kcout << "[create_page_wrapper] kBadAddress returned\n";
diff --git a/dev/ZKA/Sources/ProcessScheduler.cxx b/dev/ZKA/Sources/ProcessScheduler.cxx
index 8ca94b60..a979c413 100644
--- a/dev/ZKA/Sources/ProcessScheduler.cxx
+++ b/dev/ZKA/Sources/ProcessScheduler.cxx
@@ -51,6 +51,7 @@ namespace Kernel
if (Kernel::ProcessScheduler::The().Leak().CurrentTeam().AsArray().Count() < 1)
{
kcout << "*** BAD PROCESS ***\rTerminating as we are the only process...\r";
+
ke_stop(RUNTIME_CHECK_PROCESS);
}
diff --git a/dev/ZKA/Sources/User.cxx b/dev/ZKA/Sources/User.cxx
index e05aa283..3aad5ad4 100644
--- a/dev/ZKA/Sources/User.cxx
+++ b/dev/ZKA/Sources/User.cxx
@@ -29,17 +29,21 @@ namespace Kernel
/// \brief Constructs a token by hashing the password.
/// \param password password to hash.
/// \return the hashed password
- const Int32 cred_construct_token(Char* password, User* user)
+ const Int32 cred_construct_token(Char* password, const Char* in_password, User* user, SizeT length)
{
if (!password || !user)
return -1;
- for (Size i_pass = 0; i_pass < rt_string_len(password); ++i_pass)
+ kcout << "Constructing token...\r";
+
+ for (Size i_pass = 0; i_pass < length; ++i_pass)
{
- Char cur_chr = password[i_pass];
+ Char cur_chr = in_password[i_pass];
password[i_pass] = cur_chr + (user->IsStdUser() ? cStdUser : cSuperUser);
}
+ kcout << "Done constructing token...\r";
+
return 0;
}
} // namespace Detail
@@ -48,46 +52,74 @@ namespace Kernel
: fRing((RingKind)sel)
{
MUST_PASS(sel >= 0);
- this->fUserName += userName;
+ rt_copy_memory((VoidPtr)userName, this->fUserName, rt_string_len(userName));
}
User::User(const RingKind& ringKind, const Char* userName)
: fRing(ringKind)
{
- this->fUserName += userName;
+ rt_copy_memory((VoidPtr)userName, this->fUserName, rt_string_len(userName));
}
User::~User() = default;
Bool User::TrySave(const Char* password) noexcept
{
- kcout << "Trying to save password...\r";
-
SizeT len = rt_string_len(password);
Char* token = new Char[len];
MUST_PASS(token);
- rt_copy_memory((VoidPtr)password, token, rt_string_len(password));
+ kcout << "Trying to save password...\r";
- Detail::cred_construct_token(token, this);
+ rt_copy_memory((VoidPtr)password, token, len);
+ Detail::cred_construct_token(token, password, this, len);
if (NewFilesystemManager::GetMounted())
{
- auto node = NewFilesystemManager::GetMounted()->Create(kUsersFile);
+ NewFilesystemManager* new_fs = (NewFilesystemManager*)NewFilesystemManager::GetMounted();
+
+ kcout << "newoskrnl: Opening catalog.\r";
+
+ auto node = new_fs->GetParser()->GetCatalog(kUsersFile);
- if (node)
+ if (!node)
{
- NewFilesystemManager::GetMounted()->Write(this->fUserName.CData(), node, (VoidPtr)token, (this->IsStdUser() ? cStdUser : cSuperUser) | kNewFSCatalogKindMetaFile, len);
- delete node;
+ node = new_fs->GetParser()->CreateCatalog(kUsersFile);
}
- delete token;
+ kcout << "newoskrnl: Writing token...\r";
+
+ NFS_FORK_STRUCT fork{0};
+
+ fork.Kind = kNewFSRsrcForkKind;
+ fork.DataSize = rt_string_len(password);
+
+ rt_copy_memory((VoidPtr)this->fUserName, fork.ForkName, rt_string_len(this->fUserName));
+ rt_copy_memory((VoidPtr)kUsersFile, fork.CatalogName, rt_string_len(kUsersFile));
+
+ fork.DataSize = len;
+
+ new_fs->GetParser()->CreateFork(node, fork);
+
+ new_fs->GetParser()->WriteCatalog(node, (fork.Kind == kNewFSRsrcForkKind), reinterpret_cast<VoidPtr>(token), len, this->fUserName);
+
+ delete node;
+ node = nullptr;
+
+ delete[] token;
+ token = nullptr;
+
+ kcout << "newoskrnl: Wrote token...\r";
return true;
}
- delete token;
+ kcout << "No filesystem mounted...\r";
+
+ delete[] token;
+ token = nullptr;
+
return false;
}
@@ -101,7 +133,7 @@ namespace Kernel
return lhs.fRing != this->fRing;
}
- StringView& User::Name() noexcept
+ Char* User::Name() noexcept
{
return this->fUserName;
}
@@ -123,7 +155,7 @@ namespace Kernel
UserManager* UserManager::The() noexcept
{
- UserManager* view = nullptr;
+ static UserManager* view = nullptr;
if (!view)
view = new UserManager();
@@ -136,22 +168,33 @@ namespace Kernel
if (!password ||
!user)
{
- ErrLocal() = kErrorInvalidData;
-
kcout << "newoskrnl: Incorrect data given.\r";
+ ErrLocal() = kErrorInvalidData;
+
return false;
}
kcout << "newoskrnl: Trying to log-in.\r";
- FileStreamUTF8 file(kUsersFile, "rb");
+ NewFilesystemManager* new_fs = (NewFilesystemManager*)NewFilesystemManager::GetMounted();
+
+ // do not use if unmounted.
+
+ if (!new_fs)
+ return false;
+
+ auto node = new_fs->GetParser()->GetCatalog(kUsersFile);
// ------------------------------------------ //
// Retrieve token from a specific file fork.
+ // Fail on null.
// ------------------------------------------ //
- auto token = file.Read(user->fUserName.CData());
+ if (!node)
+ return false;
+
+ auto token = new_fs->GetParser()->ReadCatalog(node, rt_string_len(password), user->fUserName);
if (!token)
{
@@ -162,7 +205,7 @@ namespace Kernel
}
else
{
- Char generated_token[255] = {0};
+ Char generated_token[kMaxUserTokenLen] = {0};
// ================================================== //
// Provide password on token variable.
@@ -174,7 +217,7 @@ namespace Kernel
// Construct token.
// ================================================== //
- Detail::cred_construct_token(generated_token, user);
+ Detail::cred_construct_token(generated_token, password, user, rt_string_len(password));
// ================================================== //
// Checks if it matches the current token we have.
@@ -210,7 +253,7 @@ namespace Kernel
}
fCurrentUser = user;
- Kernel::kcout << "newoskrnl: Logged in as: " << fCurrentUser->Name().CData() << Kernel::endl;
+ Kernel::kcout << "newoskrnl: Logged in as: " << fCurrentUser->Name() << Kernel::endl;
return true;
}