summaryrefslogtreecommitdiffhomepage
path: root/Kernel
diff options
context:
space:
mode:
authorAmlal EL Mahrouss <amlalelmahrouss@icloud.com>2024-08-11 10:01:11 +0200
committerAmlal EL Mahrouss <amlalelmahrouss@icloud.com>2024-08-11 10:01:11 +0200
commit4bc2a20e699812c397e0d9e3901d91196d8681f0 (patch)
tree0a00c7d47236cacf21413f58341bec6c0ec97455 /Kernel
parent25c6f11de8d859d2aab49848cfc2c2d9a7f33153 (diff)
[newoskrnl.dll] Fixes and improvements, mostly on New FS and User Security support.
[encryptfs.dll] Add new DLL for filesystem encryption. [sci.dll] Add protocols for IDL parsing. Signed-off-by: Amlal EL Mahrouss <amlalelmahrouss@icloud.com>
Diffstat (limited to 'Kernel')
-rw-r--r--Kernel/FSKit/NewFS.hxx4
-rw-r--r--Kernel/FSKit/RFS.hxx24
-rw-r--r--Kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cxx30
-rw-r--r--Kernel/HALKit/AMD64/HalKernelMain.cxx13
-rw-r--r--Kernel/NewKit/Defines.hxx3
-rw-r--r--Kernel/Sources/FS/NewFS.cxx298
-rw-r--r--Kernel/Sources/HalPageAlloc.cxx24
-rw-r--r--Kernel/Sources/NewFS+FileManager.cxx4
-rw-r--r--Kernel/Sources/PageManager.cxx6
-rw-r--r--Kernel/Sources/User.cxx25
10 files changed, 198 insertions, 233 deletions
diff --git a/Kernel/FSKit/NewFS.hxx b/Kernel/FSKit/NewFS.hxx
index 6d3d6fa9..b000291a 100644
--- a/Kernel/FSKit/NewFS.hxx
+++ b/Kernel/FSKit/NewFS.hxx
@@ -38,7 +38,7 @@ default.
#define kNewFSMetaFilePrefix '$'
-#define kNewFSVersionInteger (0x127)
+#define kNewFSVersionInteger (0x0127)
#define kNewFSVerionString "1.27"
/// @brief Standard fork types.
@@ -281,7 +281,7 @@ namespace Kernel
bool Format(_Input _Output DriveTrait* drive, _Input const Lba endLba, _Input const Int32 flags, const Char* part_name);
public:
- Int32 fDriveIndex{kNewFSSubDriveC};
+ Int32 fDriveIndex{kNewFSSubDriveA};
};
///
diff --git a/Kernel/FSKit/RFS.hxx b/Kernel/FSKit/RFS.hxx
deleted file mode 100644
index b12f38c3..00000000
--- a/Kernel/FSKit/RFS.hxx
+++ /dev/null
@@ -1,24 +0,0 @@
-/* -------------------------------------------
-
- Copyright ZKA Technologies
-
- File: RFS.hxx
- Purpose: Resillient File System
-
- Revision History:
-
- 8/8/2024: Added file (amlel)
-
-------------------------------------------- */
-
-#pragma once
-
-#include <CompilerKit/CompilerKit.hxx>
-#include <HintKit/CompilerHint.hxx>
-#include <KernelKit/DriveManager.hxx>
-#include <NewKit/Defines.hxx>
-
-struct RFS_MASTER_PARTITION_BLOCK;
-struct RFS_FILE_PARTITIN_BLOCK;
-struct RFS_CATALOG_BLOCK;
-struct RFS_FORK_BLOCK; \ No newline at end of file
diff --git a/Kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cxx b/Kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cxx
index bf463ae9..e4bf13e1 100644
--- a/Kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cxx
+++ b/Kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cxx
@@ -12,55 +12,35 @@
/// @param rsp
EXTERN_C void idt_handle_gpf(Kernel::UIntPtr rsp)
{
- Kernel::kcout
- << "newoskrnl: General Protection Fault, caused by "
- << Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().GetProcessName();
-
- Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().Crash();
+ Kernel::ke_stop(RUNTIME_CHECK_BAD_BEHAVIOR);
}
/// @brief Handle page fault.
/// @param rsp
EXTERN_C void idt_handle_pf(Kernel::UIntPtr rsp)
{
- Kernel::kcout
- << "newoskrnl: Segmentation Fault, caused by "
- << Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().GetProcessName();
-
- Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().Crash();
+ Kernel::ke_stop(RUNTIME_CHECK_BAD_BEHAVIOR);
}
/// @brief Handle math fault.
/// @param rsp
EXTERN_C void idt_handle_math(Kernel::UIntPtr rsp)
{
- Kernel::kcout
- << "newoskrnl: Math error, caused by "
- << Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().GetProcessName();
-
- Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().Crash();
+ Kernel::ke_stop(RUNTIME_CHECK_BAD_BEHAVIOR);
}
/// @brief Handle any generic fault.
/// @param rsp
EXTERN_C void idt_handle_generic(Kernel::UIntPtr rsp)
{
- Kernel::kcout
- << "newoskrnl: Execution error, caused by "
- << Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().GetProcessName();
-
- Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().Crash();
+ Kernel::ke_stop(RUNTIME_CHECK_BAD_BEHAVIOR);
}
/// @brief Handle #UD fault.
/// @param rsp
EXTERN_C void idt_handle_ud(Kernel::UIntPtr rsp)
{
- Kernel::kcout
- << "newoskrnl: Invalid interrupt, caused by "
- << Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().GetProcessName();
-
- Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().Crash();
+ Kernel::ke_stop(RUNTIME_CHECK_BAD_BEHAVIOR);
}
/// @brief Enter syscall from assembly.
diff --git a/Kernel/HALKit/AMD64/HalKernelMain.cxx b/Kernel/HALKit/AMD64/HalKernelMain.cxx
index 01153c0e..9eabe9d7 100644
--- a/Kernel/HALKit/AMD64/HalKernelMain.cxx
+++ b/Kernel/HALKit/AMD64/HalKernelMain.cxx
@@ -209,13 +209,17 @@ 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::kcout << "newoskrnl: Creating Filesystem and Super User...\r";
auto fs = new Kernel::NewFilesystemManager();
Kernel::NewFilesystemManager::Mount(fs);
+ MUST_PASS(fs->GetParser());
+
+ delete fs->GetParser()->CreateCatalog("\\Users\\", 0, kNewFSCatalogKindDir);
+
+ Kernel::kcout << "newoskrnl: Creating filesystem and " << kSuperUser << "..." << Kernel::endl;
+
cRoot = new Kernel::User(Kernel::RingKind::kRingSuperUser, kSuperUser);
#ifdef __DEBUG__
@@ -223,8 +227,13 @@ Kernel::Void hal_real_init(Kernel::Void) noexcept
#else
const auto cPassword = "password";
#endif
+
+ Kernel::UserManager::The()->fRootUser = cRoot;
+
+ Kernel::kcout << "newoskrnl: Root is " << kSuperUser << "." << Kernel::endl;
cRoot->TrySave(cPassword);
+
Kernel::UserManager::The()->TryLogIn(cRoot, cPassword);
Kernel::ke_stop(RUNTIME_CHECK_FAILED);
diff --git a/Kernel/NewKit/Defines.hxx b/Kernel/NewKit/Defines.hxx
index 54bf55a2..246adc7f 100644
--- a/Kernel/NewKit/Defines.hxx
+++ b/Kernel/NewKit/Defines.hxx
@@ -66,6 +66,9 @@ namespace Kernel
using WideChar = wchar_t;
using Utf32Char = char32_t;
+ typedef UInt64 PhysicalAddress;
+ typedef UInt64 VirtualAddress;
+
using Void = void;
using Lba = UInt64;
diff --git a/Kernel/Sources/FS/NewFS.cxx b/Kernel/Sources/FS/NewFS.cxx
index a332576c..9af736e2 100644
--- a/Kernel/Sources/FS/NewFS.cxx
+++ b/Kernel/Sources/FS/NewFS.cxx
@@ -54,9 +54,6 @@ STATIC MountpointInterface sMountpointInterface;
_Output NFS_FORK_STRUCT* NewFSParser::CreateFork(_Input NFS_CATALOG_STRUCT* catalog,
_Input NFS_FORK_STRUCT& theFork)
{
- if (!sMountpointInterface.GetAddressOf(this->fDriveIndex))
- return nullptr;
-
if (catalog && theFork.ForkName[0] != 0 &&
theFork.DataSize == kNewFSForkSize)
{
@@ -68,10 +65,10 @@ _Output NFS_FORK_STRUCT* NewFSParser::CreateFork(_Input NFS_CATALOG_STRUCT* cata
if (lba <= kNewFSCatalogStartAddress)
return nullptr;
- auto drv = sMountpointInterface.GetAddressOf(this->fDriveIndex);
+ auto drv = sMountpointInterface.A();
/// special treatment.
- rt_copy_memory((VoidPtr) "fs/newfs-packet", drv->fPacket.fPacketMime,
+ rt_copy_memory((VoidPtr) "fs/newfs-packet", drv.fPacket.fPacketMime,
rt_string_len("fs/newfs-packet"));
NFS_FORK_STRUCT curFork{0};
@@ -84,11 +81,11 @@ _Output NFS_FORK_STRUCT* NewFSParser::CreateFork(_Input NFS_CATALOG_STRUCT* cata
if (lba <= kNewFSCatalogStartAddress)
break;
- drv->fPacket.fLba = lba;
- drv->fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT);
- drv->fPacket.fPacketContent = &curFork;
+ drv.fPacket.fLba = lba;
+ drv.fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT);
+ drv.fPacket.fPacketContent = &curFork;
- drv->fInput(&drv->fPacket);
+ drv.fInput(&drv.fPacket);
kcout << "newoskrnl: next fork: " << hex_number(curFork.NextSibling) << endl;
@@ -114,14 +111,14 @@ _Output NFS_FORK_STRUCT* NewFSParser::CreateFork(_Input NFS_CATALOG_STRUCT* cata
/// entry.
if (lba >= kNewFSCatalogStartAddress)
{
- drv->fPacket.fLba = lbaOfPreviousFork;
- drv->fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT);
- drv->fPacket.fPacketContent = &prevFork;
+ drv.fPacket.fLba = lbaOfPreviousFork;
+ drv.fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT);
+ drv.fPacket.fPacketContent = &prevFork;
prevFork.NextSibling = lba;
/// write to disk.
- drv->fOutput(&drv->fPacket);
+ drv.fOutput(&drv.fPacket);
}
break;
@@ -136,11 +133,11 @@ _Output NFS_FORK_STRUCT* NewFSParser::CreateFork(_Input NFS_CATALOG_STRUCT* cata
theFork.PreviousSibling = lbaOfPreviousFork;
theFork.NextSibling = theFork.DataOffset - theFork.DataSize;
- drv->fPacket.fLba = lba;
- drv->fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT);
- drv->fPacket.fPacketContent = &theFork;
+ drv.fPacket.fLba = lba;
+ drv.fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT);
+ drv.fPacket.fPacketContent = &theFork;
- drv->fOutput(&drv->fPacket);
+ drv.fOutput(&drv.fPacket);
/// log what we have now.
kcout << "newoskrnl: Wrote fork data at: " << hex_number(theFork.DataOffset)
@@ -162,21 +159,21 @@ _Output NFS_FORK_STRUCT* NewFSParser::FindFork(_Input NFS_CATALOG_STRUCT* catalo
_Input const Char* name,
Boolean isDataFork)
{
- auto drv = sMountpointInterface.GetAddressOf(this->fDriveIndex);
+ auto drv = sMountpointInterface.A();
NFS_FORK_STRUCT* theFork = nullptr;
Lba lba = isDataFork ? catalog->DataFork : catalog->ResourceFork;
while (lba != 0)
{
- drv->fPacket.fLba = lba;
- drv->fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT);
- drv->fPacket.fPacketContent = (VoidPtr)theFork;
+ drv.fPacket.fLba = lba;
+ drv.fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT);
+ drv.fPacket.fPacketContent = (VoidPtr)theFork;
- rt_copy_memory((VoidPtr) "fs/newfs-packet", drv->fPacket.fPacketMime, 16);
+ rt_copy_memory((VoidPtr) "fs/newfs-packet", drv.fPacket.fPacketMime, 16);
if (auto res =
- fs_newfs_read(&sMountpointInterface, *drv, this->fDriveIndex);
+ fs_newfs_read(&sMountpointInterface, drv, this->fDriveIndex);
res)
{
switch (res)
@@ -211,7 +208,7 @@ _Output NFS_FORK_STRUCT* NewFSParser::FindFork(_Input NFS_CATALOG_STRUCT* catalo
/// file.)
/// @param name
/// @return catalog pointer.
-_Output NFS_CATALOG_STRUCT* NewFSParser::CreateCatalog(_Input const char* name)
+_Output NFS_CATALOG_STRUCT* NewFSParser::CreateCatalog(_Input const Char* name)
{
return this->CreateCatalog(name, 0, kNewFSCatalogKindFile);
}
@@ -225,11 +222,12 @@ _Output NFS_CATALOG_STRUCT* NewFSParser::CreateCatalog(_Input const Char* name,
_Input const Int32& flags,
_Input const Int32& kind)
{
- if (!sMountpointInterface.GetAddressOf(this->fDriveIndex))
- return nullptr;
-
+ kcout << "newoskrnl: CreateCatalog(...)\r";
+
Lba outLba = 0UL;
+ kcout << "newoskrnl: Checking for extension...\r";
+
/// a directory should have a slash in the end.
if (kind == kNewFSCatalogKindDir &&
name[rt_string_len(name) - 1] != NewFilesystemHelper::Separator())
@@ -244,7 +242,7 @@ _Output NFS_CATALOG_STRUCT* NewFSParser::CreateCatalog(_Input const Char* name,
if (copyExists)
{
- kcout << "newoskrnl: copy already exists.\r";
+ kcout << "newoskrnl: Copy already exists.\r";
ErrLocal() = kErrorFileExists;
return copyExists;
@@ -259,6 +257,7 @@ _Output NFS_CATALOG_STRUCT* NewFSParser::CreateCatalog(_Input const Char* name,
if (*parentName == 0)
{
+ kcout << "newoskrnl: Parent name is NUL.\r";
ErrLocal() = kErrorFileNotFound;
return nullptr;
}
@@ -288,6 +287,7 @@ _Output NFS_CATALOG_STRUCT* NewFSParser::CreateCatalog(_Input const Char* name,
if (catalog && catalog->Kind == kNewFSCatalogKindFile)
{
+ kcout << "newoskrnl: Parent name is file.\r";
delete catalog;
return nullptr;
}
@@ -304,7 +304,8 @@ _Output NFS_CATALOG_STRUCT* NewFSParser::CreateCatalog(_Input const Char* name,
if (flagsList & kNewFSCatalogKindMetaFile)
{
- if (UserManager::The()->GetCurrent() != UserManager::The()->fRootUser)
+ if (UserManager::The()->GetCurrent() != UserManager::The()->fRootUser &&
+ UserManager::The()->fRootUser)
{
delete catalogChild;
return nullptr;
@@ -324,18 +325,18 @@ _Output NFS_CATALOG_STRUCT* NewFSParser::CreateCatalog(_Input const Char* name,
UInt16 catalogBuf[kNewFSSectorSz] = {0};
- auto drive = sMountpointInterface.GetAddressOf(this->fDriveIndex);
+ auto drive = sMountpointInterface.A();
Lba startFree = outLba;
- rt_copy_memory((VoidPtr) "fs/newfs-packet", drive->fPacket.fPacketMime,
+ 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.fPacketContent = catalogBuf;
+ drive.fPacket.fPacketSize = kNewFSSectorSz;
+ drive.fPacket.fLba = startFree;
- drive->fInput(&drive->fPacket);
+ drive.fInput(&drive.fPacket);
NFS_CATALOG_STRUCT* nextSibling = (NFS_CATALOG_STRUCT*)catalogBuf;
@@ -343,10 +344,10 @@ _Output NFS_CATALOG_STRUCT* NewFSParser::CreateCatalog(_Input const Char* name,
catalogChild->PrevSibling = outLba;
- drive->fPacket.fLba = startFree;
- drive->fInput(&drive->fPacket);
+ drive.fPacket.fLba = startFree;
+ drive.fInput(&drive.fPacket);
- while (drive->fPacket.fPacketGood)
+ while (drive.fPacket.fPacketGood)
{
nextSibling = reinterpret_cast<NFS_CATALOG_STRUCT*>(catalogBuf);
@@ -365,11 +366,11 @@ _Output NFS_CATALOG_STRUCT* NewFSParser::CreateCatalog(_Input const Char* name,
{
Char sectorBufPartBlock[kNewFSSectorSz] = {0};
- drive->fPacket.fPacketContent = sectorBufPartBlock;
- drive->fPacket.fPacketSize = kNewFSSectorSz;
- drive->fPacket.fLba = kNewFSStartLba;
+ drive.fPacket.fPacketContent = sectorBufPartBlock;
+ drive.fPacket.fPacketSize = kNewFSSectorSz;
+ drive.fPacket.fLba = kNewFSStartLba;
- drive->fInput(&drive->fPacket);
+ drive.fInput(&drive.fPacket);
constexpr auto cNewFSCatalogPadding = 4;
@@ -388,40 +389,40 @@ _Output NFS_CATALOG_STRUCT* NewFSParser::CreateCatalog(_Input const Char* name,
catalogChild->NextSibling =
startFree + (sizeof(NFS_CATALOG_STRUCT) * cNewFSCatalogPadding);
- drive->fPacket.fPacketContent = catalogChild;
- drive->fPacket.fPacketSize = sizeof(NFS_CATALOG_STRUCT);
- drive->fPacket.fLba = startFree;
+ drive.fPacket.fPacketContent = catalogChild;
+ drive.fPacket.fPacketSize = sizeof(NFS_CATALOG_STRUCT);
+ drive.fPacket.fLba = startFree;
- drive->fOutput(&drive->fPacket);
+ drive.fOutput(&drive.fPacket);
- drive->fPacket.fPacketContent = catalogBuf;
- drive->fPacket.fPacketSize = kNewFSSectorSz;
- drive->fPacket.fLba =
+ drive.fPacket.fPacketContent = catalogBuf;
+ drive.fPacket.fPacketSize = kNewFSSectorSz;
+ drive.fPacket.fLba =
startFree - (sizeof(NFS_CATALOG_STRUCT) * cNewFSCatalogPadding);
- drive->fInput(&drive->fPacket);
+ drive.fInput(&drive.fPacket);
nextSibling->NextSibling = startFree;
- drive->fOutput(&drive->fPacket);
+ drive.fOutput(&drive.fPacket);
kcout << "newoskrnl: Create new catalog, status: "
<< hex_number(catalogChild->Flags) << endl;
kcout << "newoskrnl: Create new catalog, status: " << catalogChild->Name
<< endl;
- drive->fPacket.fPacketContent = sectorBufPartBlock;
- drive->fPacket.fPacketSize = kNewFSSectorSz;
- drive->fPacket.fLba = kNewFSStartLba;
+ drive.fPacket.fPacketContent = sectorBufPartBlock;
+ drive.fPacket.fPacketSize = kNewFSSectorSz;
+ drive.fPacket.fLba = kNewFSStartLba;
- drive->fInput(&drive->fPacket);
+ drive.fInput(&drive.fPacket);
partBlock->SectorCount -= 1;
partBlock->CatalogCount += 1;
partBlock->FreeCatalog -= 1;
partBlock->FreeCatalog = catalogChild->NextSibling;
- drive->fOutput(&drive->fPacket);
+ drive.fOutput(&drive.fPacket);
delete catalog;
return catalogChild;
@@ -432,11 +433,11 @@ _Output NFS_CATALOG_STRUCT* NewFSParser::CreateCatalog(_Input const Char* name,
//// @note that's how we find the next catalog in the partition block.
startFree = startFree + (sizeof(NFS_CATALOG_STRUCT) * cNewFSCatalogPadding);
- drive->fPacket.fPacketContent = catalogBuf;
- drive->fPacket.fPacketSize = kNewFSSectorSz;
- drive->fPacket.fLba = startFree;
+ drive.fPacket.fPacketContent = catalogBuf;
+ drive.fPacket.fPacketSize = kNewFSSectorSz;
+ drive.fPacket.fLba = startFree;
- drive->fInput(&drive->fPacket);
+ drive.fInput(&drive.fPacket);
}
delete catalog;
@@ -612,125 +613,119 @@ bool NewFSParser::Format(_Input _Output DriveTrait* drive, _Input const Lba endL
/// @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)
{
- if (!sMountpointInterface.GetAddressOf(this->fDriveIndex))
- return false;
+ NFS_FORK_STRUCT forkData{0};
- NFS_FORK_STRUCT* forkData = new NFS_FORK_STRUCT();
- rt_set_memory(forkData, 0, sizeof(NFS_FORK_STRUCT));
+ auto drive = sMountpointInterface.A();
- auto drive = sMountpointInterface.GetAddressOf(this->fDriveIndex);
-
- rt_copy_memory((VoidPtr) "fs/newfs-packet", drive->fPacket.fPacketMime,
+ 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);
+ rt_copy_memory(catalog->Name, forkData.CatalogName, kNewFSNodeNameLen);
+
+ NFS_FORK_STRUCT forkDataIn{0};
// sanity check of the fork position as the condition to run the loop.
while (startFork >= kNewFSCatalogStartAddress)
{
- drive->fPacket.fPacketContent = forkData;
- drive->fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT);
- drive->fPacket.fLba = startFork;
+ drive.fPacket.fPacketContent = &forkDataIn;
+ drive.fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT);
+ drive.fPacket.fLba = startFork;
- drive->fInput(&drive->fPacket);
+ drive.fInput(&drive.fPacket);
- kcout << "newoskrnl: fork name: " << forkData->ForkName << endl;
+ kcout << "newoskrnl: fork name: " << forkName << endl;
// check the fork, if it's position is valid.
- if (forkData->DataOffset <= kNewFSCatalogStartAddress)
+ if (forkDataIn.DataOffset <= kNewFSCatalogStartAddress)
{
ErrLocal() = kErrorDiskIsCorrupted;
kcout << "newoskrnl: Invalid fork offset.\r";
- delete forkData;
return false;
}
- if (forkData->Flags != kNewFSFlagUnallocated &&
- forkData->Flags != kNewFSFlagDeleted &&
- StringBuilder::Equals(forkData->ForkName, forkName) &&
- StringBuilder::Equals(forkData->CatalogName, catalog->Name))
+ if (forkData.Flags != kNewFSFlagUnallocated &&
+ forkData.Flags != kNewFSFlagDeleted &&
+ StringBuilder::Equals(forkData.ForkName, forkName) &&
+ StringBuilder::Equals(forkData.CatalogName, catalog->Name))
{
- // ===================================================== //
- // Store size of blob now.
- // ===================================================== //
- forkData->DataSize = sizeOfData;
+ if (forkDataIn.DataSize < sizeOfData)
+ {
+ startFork = forkData.NextSibling;
+ continue;
+ }
- drive->fPacket.fPacketContent = data;
- drive->fPacket.fPacketSize = sizeOfData;
- drive->fPacket.fLba = forkData->DataOffset;
+ drive.fPacket.fPacketContent = data;
+ drive.fPacket.fPacketSize = sizeOfData;
+ drive.fPacket.fLba = forkData.DataOffset;
- kcout << "newoskrnl: data offset: " << hex_number(forkData->DataOffset) << endl;
+ kcout << "newoskrnl: data offset: " << hex_number(forkData.DataOffset) << endl;
- drive->fOutput(&drive->fPacket);
+ drive.fOutput(&drive.fPacket);
- delete forkData;
return true;
}
- else if (auto catalog = this->GetCatalog(forkData->CatalogName);
- catalog == nullptr)
+ else
{
// ===================================================== //
// Store size of blob now.
// ===================================================== //
- forkData->DataSize = sizeOfData;
+ forkData.DataSize = sizeOfData;
- delete catalog;
+ if (sizeOfData < kNewFSForkSize)
+ forkData.DataSize = kNewFSForkSize;
- drive->fPacket.fPacketContent = data;
- drive->fPacket.fPacketSize = sizeOfData;
- drive->fPacket.fLba = forkData->DataOffset;
+ drive.fPacket.fPacketContent = data;
+ drive.fPacket.fPacketSize = sizeOfData;
+ drive.fPacket.fLba = forkData.DataOffset;
- kcout << "newoskrnl: data offset: " << hex_number(forkData->DataOffset) << endl;
+ kcout << "newoskrnl: data offset: " << hex_number(forkData.DataOffset) << endl;
- drive->fOutput(&drive->fPacket);
+ drive.fOutput(&drive.fPacket);
- forkData->Flags = kNewFSFlagCreated;
+ forkData.Flags = kNewFSFlagCreated;
- drive->fPacket.fPacketContent = forkData;
- drive->fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT);
- drive->fPacket.fLba = startFork;
+ drive.fPacket.fPacketContent = &forkData;
+ drive.fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT);
+ drive.fPacket.fLba = startFork;
- drive->fOutput(&drive->fPacket);
+ drive.fOutput(&drive.fPacket);
- kcout << "newoskrnl: wrote fork at offset: " << hex_number(forkData->DataOffset) << endl;
+ kcout << "newoskrnl: wrote fork at offset: " << hex_number(forkData.DataOffset) << endl;
+
+ delete catalog;
- delete forkData;
return true;
}
- startFork = forkData->NextSibling;
+ startFork = forkData.NextSibling;
}
- delete forkData;
return false;
}
/// @brief
/// @param catalogName the catalog name.
/// @return the newly found catalog.
-_Output NFS_CATALOG_STRUCT* NewFSParser::FindCatalog(_Input const char* catalogName,
+_Output NFS_CATALOG_STRUCT* NewFSParser::FindCatalog(_Input const Char* catalogName,
Lba& outLba)
{
- if (!sMountpointInterface.GetAddressOf(this->fDriveIndex))
- return nullptr;
-
kcout << "newoskrnl: start finding catalog...\r";
Char* sectorBuf = new Char[sizeof(NFS_ROOT_PARTITION_BLOCK)];
- auto drive = sMountpointInterface.GetAddressOf(this->fDriveIndex);
+ auto drive = sMountpointInterface.A();
- rt_copy_memory((VoidPtr) "fs/newfs-packet", drive->fPacket.fPacketMime,
+ rt_copy_memory((VoidPtr) "fs/newfs-packet", drive.fPacket.fPacketMime,
rt_string_len("fs/newfs-packet"));
- drive->fPacket.fPacketContent = sectorBuf;
- drive->fPacket.fPacketSize = sizeof(NFS_ROOT_PARTITION_BLOCK);
- drive->fPacket.fLba = kNewFSStartLba;
+ drive.fPacket.fPacketContent = sectorBuf;
+ drive.fPacket.fPacketSize = sizeof(NFS_ROOT_PARTITION_BLOCK);
+ drive.fPacket.fLba = kNewFSStartLba;
- drive->fInput(&drive->fPacket);
+ drive.fInput(&drive.fPacket);
NFS_ROOT_PARTITION_BLOCK* part = (NFS_ROOT_PARTITION_BLOCK*)sectorBuf;
@@ -739,11 +734,11 @@ _Output NFS_CATALOG_STRUCT* NewFSParser::FindCatalog(_Input const char* catalogN
auto localSearchFirst = false;
- drive->fPacket.fLba = startCatalogList;
- drive->fPacket.fPacketContent = sectorBuf;
- drive->fPacket.fPacketSize = sizeof(NFS_CATALOG_STRUCT);
+ drive.fPacket.fLba = startCatalogList;
+ drive.fPacket.fPacketContent = sectorBuf;
+ drive.fPacket.fPacketSize = sizeof(NFS_CATALOG_STRUCT);
- drive->fInput(&drive->fPacket);
+ drive.fInput(&drive.fPacket);
if (!StringBuilder::Equals(catalogName, NewFilesystemHelper::Root()))
{
@@ -787,7 +782,7 @@ _Output NFS_CATALOG_STRUCT* NewFSParser::FindCatalog(_Input const char* catalogN
kcout << "newoskrnl: fetching catalog...\r";
_NewFSSearchThroughCatalogList:
- while (drive->fPacket.fPacketGood)
+ while (drive.fPacket.fPacketGood)
{
NFS_CATALOG_STRUCT* catalog = (NFS_CATALOG_STRUCT*)sectorBuf;
@@ -815,11 +810,11 @@ _NewFSSearchThroughCatalogList:
if (startCatalogList <= kNewFSStartLba)
break;
- drive->fPacket.fLba = startCatalogList;
- drive->fPacket.fPacketContent = sectorBuf;
- drive->fPacket.fPacketSize = sizeof(NFS_CATALOG_STRUCT);
+ drive.fPacket.fLba = startCatalogList;
+ drive.fPacket.fPacketContent = sectorBuf;
+ drive.fPacket.fPacketSize = sizeof(NFS_CATALOG_STRUCT);
- drive->fInput(&drive->fPacket);
+ drive.fInput(&drive.fPacket);
}
if (localSearchFirst)
@@ -839,7 +834,7 @@ _NewFSSearchThroughCatalogList:
/// @brief Get catalog from filesystem.
/// @param name the catalog's name/
/// @return
-_Output NFS_CATALOG_STRUCT* NewFSParser::GetCatalog(_Input const char* name)
+_Output NFS_CATALOG_STRUCT* NewFSParser::GetCatalog(_Input const Char* name)
{
Lba unused = 0;
return this->FindCatalog(name, unused);
@@ -879,25 +874,25 @@ Boolean NewFSParser::RemoveCatalog(_Input const Char* catalogName)
{
catalog->Flags = kNewFSFlagDeleted;
- auto drive = sMountpointInterface.GetAddressOf(this->fDriveIndex);
+ auto drive = sMountpointInterface.A();
- rt_copy_memory((VoidPtr) "fs/newfs-packet", drive->fPacket.fPacketMime,
+ rt_copy_memory((VoidPtr) "fs/newfs-packet", drive.fPacket.fPacketMime,
rt_string_len("fs/newfs-packet"));
- drive->fPacket.fLba = outLba; // the catalog position.
- drive->fPacket.fPacketSize =
- sizeof(NFS_CATALOG_STRUCT); // size of catalog. roughly the sector size.
- drive->fPacket.fPacketContent = catalog; // the catalog itself.
+ drive.fPacket.fLba = outLba; // the catalog position.
+ drive.fPacket.fPacketSize =
+ sizeof(NFS_CATALOG_STRUCT); // size of catalog. roughly the sector size.
+ drive.fPacket.fPacketContent = catalog; // the catalog itself.
- drive->fOutput(&drive->fPacket); // send packet.
+ drive.fOutput(&drive.fPacket); // send packet.
Char partitionBlockBuf[sizeof(NFS_ROOT_PARTITION_BLOCK)] = {0};
- drive->fPacket.fLba = kNewFSStartLba;
- drive->fPacket.fPacketContent = partitionBlockBuf;
- drive->fPacket.fPacketSize = sizeof(NFS_ROOT_PARTITION_BLOCK);
+ drive.fPacket.fLba = kNewFSStartLba;
+ drive.fPacket.fPacketContent = partitionBlockBuf;
+ drive.fPacket.fPacketSize = sizeof(NFS_ROOT_PARTITION_BLOCK);
- drive->fInput(&drive->fPacket);
+ drive.fInput(&drive.fPacket);
NFS_ROOT_PARTITION_BLOCK* partBlock =
reinterpret_cast<NFS_ROOT_PARTITION_BLOCK*>(partitionBlockBuf);
@@ -905,7 +900,7 @@ Boolean NewFSParser::RemoveCatalog(_Input const Char* catalogName)
++partBlock->FreeCatalog;
--partBlock->CatalogCount;
- drive->fOutput(&drive->fPacket);
+ drive.fOutput(&drive.fPacket);
return true;
}
@@ -927,7 +922,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)
{
@@ -935,9 +930,6 @@ VoidPtr NewFSParser::ReadCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog,
return nullptr;
}
- if (!sMountpointInterface.GetAddressOf(this->fDriveIndex))
- return nullptr;
-
Lba dataForkLba = catalog->DataFork;
Size dataForkSize = catalog->DataForkSize;
@@ -945,20 +937,20 @@ VoidPtr NewFSParser::ReadCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog,
<< ", fork: " << hex_number(dataForkLba) << endl;
Char* sectorBuf = new Char[sizeof(NFS_FORK_STRUCT)];
- auto drive = sMountpointInterface.GetAddressOf(this->fDriveIndex);
+ auto drive = sMountpointInterface.A();
- rt_copy_memory((VoidPtr) "fs/newfs-packet", drive->fPacket.fPacketMime,
+ rt_copy_memory((VoidPtr) "fs/newfs-packet", drive.fPacket.fPacketMime,
rt_string_len("fs/newfs-packet"));
NFS_FORK_STRUCT* forkData = nullptr;
while (dataForkLba >= kNewFSCatalogStartAddress)
{
- drive->fPacket.fLba = dataForkLba;
- drive->fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT);
- drive->fPacket.fPacketContent = sectorBuf;
+ drive.fPacket.fLba = dataForkLba;
+ drive.fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT);
+ drive.fPacket.fPacketContent = sectorBuf;
- drive->fInput(&drive->fPacket);
+ drive.fInput(&drive.fPacket);
forkData = (NFS_FORK_STRUCT*)sectorBuf;
@@ -988,11 +980,11 @@ VoidPtr NewFSParser::ReadCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog,
Char* forkBuf = new Char[dataSz];
- drive->fPacket.fLba = forkData->DataOffset;
- drive->fPacket.fPacketSize = dataSz;
- drive->fPacket.fPacketContent = forkBuf;
+ drive.fPacket.fLba = forkData->DataOffset;
+ drive.fPacket.fPacketSize = dataSz;
+ drive.fPacket.fPacketContent = forkBuf;
- drive->fInput(&drive->fPacket);
+ drive.fInput(&drive.fPacket);
delete[] sectorBuf;
return forkBuf;
diff --git a/Kernel/Sources/HalPageAlloc.cxx b/Kernel/Sources/HalPageAlloc.cxx
index d1fe83a7..d8c7696e 100644
--- a/Kernel/Sources/HalPageAlloc.cxx
+++ b/Kernel/Sources/HalPageAlloc.cxx
@@ -19,7 +19,7 @@ Kernel::Boolean kAllocationInProgress = false;
namespace Kernel
{
- constexpr auto cVMTMagic = 0xDEEFD00D;
+ constexpr auto cVMHMagic = 0xDEEFD00D;
namespace HAL
{
@@ -28,9 +28,9 @@ namespace Kernel
struct VIRTUAL_MEMORY_HEADER
{
UInt32 Magic;
- Boolean Present;
- Boolean ReadWrite;
- Boolean User;
+ Boolean Present : 1;
+ Boolean ReadWrite : 1;
+ Boolean User : 1;
SizeT Size;
};
@@ -41,7 +41,7 @@ namespace Kernel
/// @return
VIRTUAL_MEMORY_HEADER* Next(VIRTUAL_MEMORY_HEADER* current)
{
- if (current->Magic != cVMTMagic)
+ if (current->Magic != cVMHMagic)
current->Size = 8196;
return current + sizeof(VIRTUAL_MEMORY_HEADER) + current->Size;
@@ -52,7 +52,7 @@ namespace Kernel
/// @return
VIRTUAL_MEMORY_HEADER* Prev(VIRTUAL_MEMORY_HEADER* current)
{
- if (current->Magic != cVMTMagic)
+ if (current->Magic != cVMHMagic)
current->Size = 8196;
return current - sizeof(VIRTUAL_MEMORY_HEADER) - current->Size;
@@ -72,17 +72,17 @@ namespace Kernel
kAllocationInProgress = true;
- ///! fetch from the start.
+ //! fetch from the start.
Detail::VIRTUAL_MEMORY_HEADER* vmHeader = reinterpret_cast<Detail::VIRTUAL_MEMORY_HEADER*>(kKernelVMTStart);
Detail::VirtualMemoryHeaderTraits traits;
while (vmHeader->Present &&
- vmHeader->Magic == cVMTMagic)
+ vmHeader->Magic == cVMHMagic)
{
vmHeader = traits.Next(vmHeader);
}
- vmHeader->Magic = cVMTMagic;
+ vmHeader->Magic = cVMHMagic;
vmHeader->Present = true;
vmHeader->ReadWrite = rw;
vmHeader->User = user;
@@ -99,16 +99,16 @@ namespace Kernel
/// @return
auto hal_alloc_page(Boolean rw, Boolean user, SizeT size) -> VoidPtr
{
- /// Wait for a ongoing allocation to complete.
+ // Wait for a ongoing allocation to complete.
while (kAllocationInProgress)
{
- ;
+ (void)0;
}
if (size == 0)
++size;
- /// allocate new page.
+ // allocate new page.
return hal_try_alloc_new_page(rw, user, size);
}
} // namespace HAL
diff --git a/Kernel/Sources/NewFS+FileManager.cxx b/Kernel/Sources/NewFS+FileManager.cxx
index 3d216ca5..65ac1595 100644
--- a/Kernel/Sources/NewFS+FileManager.cxx
+++ b/Kernel/Sources/NewFS+FileManager.cxx
@@ -20,12 +20,12 @@ namespace Kernel
MUST_PASS(Detail::fs_init_newfs());
fImpl = new NewFSParser();
- kcout << "We are done here... (NewFilesystemManager).\r";
+ kcout << "newoskrnl: We are done here... (NewFilesystemManager).\r";
}
NewFilesystemManager::~NewFilesystemManager()
{
- kcout << "Destroying it...\r";
+ kcout << "newoskrnl: Destroying it...\r";
if (fImpl)
{
diff --git a/Kernel/Sources/PageManager.cxx b/Kernel/Sources/PageManager.cxx
index 2a1ebce8..890bf943 100644
--- a/Kernel/Sources/PageManager.cxx
+++ b/Kernel/Sources/PageManager.cxx
@@ -65,6 +65,12 @@ namespace Kernel
{
// 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";
+ ke_stop(RUNTIME_CHECK_POINTER);
+ }
return PTEWrapper{Rw, User, ExecDisable, reinterpret_cast<UIntPtr>(ptr)};
}
diff --git a/Kernel/Sources/User.cxx b/Kernel/Sources/User.cxx
index 028d184c..8da77f90 100644
--- a/Kernel/Sources/User.cxx
+++ b/Kernel/Sources/User.cxx
@@ -17,7 +17,7 @@
#include <KernelKit/Heap.hxx>
-#define cStdUser (0xCF)
+#define cStdUser (0xCF)
#define cSuperUser (0xEF)
/// BUGS: 0
@@ -75,22 +75,19 @@ namespace Kernel
if (NewFilesystemManager::GetMounted())
{
- auto dir = NewFilesystemManager::GetMounted()->CreateDirectory("\\Users\\");
-
- if (dir)
+ auto node = NewFilesystemManager::GetMounted()->Open(kUsersFile, "wb");
+
+ if (!node)
{
- delete dir;
+ NewFilesystemManager::GetMounted()->Create(kUsersFile);
}
- else
+
+ if (node)
{
- delete token;
- return false;
+ NewFilesystemManager::GetMounted()->Write(this->fUserName.CData(), node, (VoidPtr)token, (this->IsStdUser() ? cStdUser : cSuperUser) | kNewFSCatalogKindMetaFile, len);
+ delete node;
}
-
- auto node = NewFilesystemManager::GetMounted()->Create(kUsersFile);
- NewFilesystemManager::GetMounted()->Write(this->fUserName.CData(), node, (VoidPtr)token, this->IsStdUser() ? cStdUser : cSuperUser, len);
-
- delete node;
+
delete token;
return true;
@@ -153,6 +150,8 @@ namespace Kernel
return false;
}
+ kcout << "newoskrnl: Trying to log-in.\r";
+
FileStreamUTF8 file(kUsersFile, "rb");
// ------------------------------------------ //