summaryrefslogtreecommitdiffhomepage
path: root/dev/ZKA/Sources
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/Sources
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/Sources')
-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
7 files changed, 123 insertions, 81 deletions
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;
}