From 60dd6dc956cbc9db70b5c2ad2996ca5a2b863e61 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sun, 8 Mar 2026 20:04:58 +0100 Subject: [CHORE] Kernel modules updates. Signed-off-by: Amlal El Mahrouss --- src/kernel/KernelKit/DriveMgr.h | 15 ++--- src/kernel/NetworkKit/IP.h | 4 +- src/kernel/SignalKit/Signals.h | 8 +-- src/kernel/src/DriveMgr.cpp | 23 +------- src/kernel/src/Swap/DiskSwap.cpp | 2 - src/kernel/src/User.cpp | 122 +++++++++++++++++++++++++++++++++++++++ src/kernel/src/UserMgr+User.cpp | 122 --------------------------------------- src/kernel/src/UserMgr.cpp | 21 +++++++ 8 files changed, 156 insertions(+), 161 deletions(-) create mode 100644 src/kernel/src/User.cpp delete mode 100644 src/kernel/src/UserMgr+User.cpp create mode 100644 src/kernel/src/UserMgr.cpp (limited to 'src/kernel') diff --git a/src/kernel/KernelKit/DriveMgr.h b/src/kernel/KernelKit/DriveMgr.h index f4ca294e..5abb7518 100644 --- a/src/kernel/KernelKit/DriveMgr.h +++ b/src/kernel/KernelKit/DriveMgr.h @@ -1,4 +1,4 @@ -// Copyright 2024-2025, Amlal El Mahrouss (amlal@nekernel.org) +// Copyright 2024-2026, Amlal El Mahrouss (amlal@nekernel.org) // Licensed under the Apache License, Version 2.0 (see LICENSE file) // Official repository: https://github.com/ne-foss-org/nekernel @@ -6,7 +6,7 @@ #define INC_DRIVE_MANAGER_H /// @file DriveMgr.h -/// @brief Drive Manager. +/// @brief NeKernel's drive manager. /// @author Amlal El Mahrouss (amlal@nekernel.org) #include @@ -111,7 +111,7 @@ class IMountpoint final { kDriveIndexInvalid, }; - DriveTraitPtr GetAddressOf(const Int32& index) { + DriveTraitPtr GetAddressOf(const UInt32& index) { err_local_get() = kErrorSuccess; switch (index) { @@ -125,7 +125,7 @@ class IMountpoint final { return &mD; default: { err_local_get() = kErrorNoSuchDisk; - kout << "No such disc letter.\n"; + kout << "No such disc letter.\r"; break; } @@ -155,12 +155,7 @@ DriveTrait io_construct_blank_drive(Void); /// @brief Fetches the main drive. /// @param trait the new drive as a trait. Void io_construct_main_drive(DriveTrait& trait); - -/// @brief Fetches the main drive. -/// @return the new drive as a trait. -/// @deprecated use io_construct_main_drive(DriveTrait& trait) instead. -DriveTrait io_construct_main_drive(Void); - + namespace Detect { Void io_detect_drive(DriveTrait& trait); } diff --git a/src/kernel/NetworkKit/IP.h b/src/kernel/NetworkKit/IP.h index ceab7a24..3377ae3f 100644 --- a/src/kernel/NetworkKit/IP.h +++ b/src/kernel/NetworkKit/IP.h @@ -1,4 +1,4 @@ -// Copyright 2024-2025, Amlal El Mahrouss (amlal@nekernel.org) +// Copyright 2024-2026, Amlal El Mahrouss (amlal@nekernel.org) // Licensed under the Apache License, Version 2.0 (see LICENSE file) // Official repository: https://github.com/ne-foss-org/nekernel @@ -11,6 +11,7 @@ #include namespace Kernel { + class RawIPAddress6; class RawIPAddress; class IPFactory; @@ -74,6 +75,7 @@ class IPFactory final { static ErrorOr> ToKString(Ref& ipv4); static bool IpCheckVersion4(const Char* ip); }; + } // namespace Kernel #endif diff --git a/src/kernel/SignalKit/Signals.h b/src/kernel/SignalKit/Signals.h index 2070e19e..bf3f8cd8 100644 --- a/src/kernel/SignalKit/Signals.h +++ b/src/kernel/SignalKit/Signals.h @@ -1,4 +1,4 @@ -// Copyright 2024-2025, Amlal El Mahrouss (amlal@nekernel.org) +// Copyright 2024-2026, Amlal El Mahrouss (amlal@nekernel.org) // Licensed under the Apache License, Version 2.0 (see LICENSE file) // Official repository: https://github.com/ne-foss-org/nekernel @@ -25,7 +25,7 @@ namespace Kernel { -typedef SizeT rt_signal_kind; +using rt_signal_kind = SizeT; /// @brief Standard signal seed for general purpose usage. inline constexpr auto kUserSignalSeed = 0x0895034fUL; @@ -42,12 +42,12 @@ inline rt_signal_kind sig_generate_unique() { /// @brief Checks if the signal matches the seed (user_seed or kernel_seed) template -inline BOOL sig_matches_seed(rt_signal_kind sig) { +inline BOOL sig_matches_seed(const rt_signal_kind& sig) { return (sig & 0xFF000000) == (Seed & 0xFF000000); } /// @brief Validate signal from **sig** and whtether the signal is greater than SIGDTCH. -inline BOOL sig_validate_unique(rt_signal_kind sig) { +inline BOOL sig_validate_unique(const rt_signal_kind& sig) { return sig > SIGBAD && sig > SIGDTCH; } diff --git a/src/kernel/src/DriveMgr.cpp b/src/kernel/src/DriveMgr.cpp index 1ab81def..0247fba8 100644 --- a/src/kernel/src/DriveMgr.cpp +++ b/src/kernel/src/DriveMgr.cpp @@ -201,7 +201,7 @@ namespace Probe { trait.fPacket.fPacketReadOnly = YES; trait.fKind = kMassStorageDrive | kUnformattedDrive | kReadOnlyDrive; - trait.fSectorSz = 512; + trait.fSectorSz = 0x200; trait.fLbaEnd = drv_std_get_sector_count() - 1; trait.fLbaStart = 0x400; } @@ -215,27 +215,6 @@ namespace Probe { } } // namespace Probe -/// @brief Fetches the main drive. -/// @return the new drive. (returns kEPMDrive if EPM formatted) -DriveTrait io_construct_main_drive() { - constexpr auto kMainDrive = "/media/main/"; - - DriveTrait trait; - - rt_copy_memory((VoidPtr) kMainDrive, trait.fName, rt_string_len(kMainDrive)); - MUST_PASS(trait.fName[0] != 0); - - trait.fVerify = io_drv_unimplemented; - trait.fOutput = io_drv_output; - trait.fInput = io_drv_input; - trait.fInit = io_drv_init; - trait.fProtocol = io_drv_kind; - - Probe::io_detect_drive(trait); - - return trait; -} - /// @brief Replacement for io_construct_main_drive that works with IMountpoint. /// @return the new drive. (returns kEPMDrive if EPM formatted) Void io_construct_main_drive(DriveTrait& trait) { diff --git a/src/kernel/src/Swap/DiskSwap.cpp b/src/kernel/src/Swap/DiskSwap.cpp index cef7aa94..a22305ec 100644 --- a/src/kernel/src/Swap/DiskSwap.cpp +++ b/src/kernel/src/Swap/DiskSwap.cpp @@ -17,7 +17,6 @@ Int64 IDiskSwap::Write(SwapDiskHdrPtr data) { if (!data || data->fMagic != kSwapDiskHeaderMagic) return 0UL; FileStream file(kSwapPageFilePath, kRestrictWRB); - Ref ret = file.Write(data->fOffset, data, sizeof(SwapDiskHdr) + data->fBlobSz); return ret.Leak(); @@ -32,7 +31,6 @@ SwapDiskHdrPtr IDiskSwap::Read(const UIntPtr offset, SizeT data_len) { if (data_len == 0UL) return nullptr; FileStream file(kSwapPageFilePath, kRestrictRB); - ErrorOrAny blob = file.Read(offset, sizeof(SwapDiskHdr) + data_len); if (blob.HasError() || diff --git a/src/kernel/src/User.cpp b/src/kernel/src/User.cpp new file mode 100644 index 00000000..66d22d24 --- /dev/null +++ b/src/kernel/src/User.cpp @@ -0,0 +1,122 @@ +// Copyright 2024-2026, Amlal El Mahrouss (amlal@nekernel.org) +// Licensed under the Apache License, Version 2.0 (see LICENSE file) +// Official repository: https://github.com/ne-foss-org/kernel + +#include +#include +#include +#include +#include +#include +#include +#include + +/// @file UserMgr+User.cpp +/// @brief Multi-user support. + +namespace Kernel { + +namespace Detail { + //////////////////////////////////////////////////////////// + /// \brief Constructs a password by hashing the password. + /// \param password password to hash. + /// \return the hashed password + //////////////////////////////////////////////////////////// + STATIC UInt64 user_fnv_generator(const Char* password, User* user) { + kout << "user_fnv_generator: Try hashing user password...\r"; + + if (!password || !user) return 0; + if (*password == 0) return 0; + + const UInt64 kFnvOffsetBasis = 0xcbf29ce484222325ULL; + const UInt64 kFnvPrime = 0x100000001b3ULL; + + UInt64 hash = kFnvOffsetBasis; + + while (*password) { + hash ^= (Char) (*password++); + hash *= kFnvPrime; + } + + kout << "user_fnv_generator: Hashed user password.\r"; + + return hash; + } +} // namespace Detail + +//////////////////////////////////////////////////////////// +/// @brief User ring constructor. +//////////////////////////////////////////////////////////// +User::User(const Int32& sel, const Char* user_name) : mUserRing((UserRingKind) sel) { + MUST_PASS(sel >= 0); + rt_copy_memory_safe((VoidPtr) user_name, this->mUserName, rt_string_len(user_name), + kMaxUserNameLen); +} + +//////////////////////////////////////////////////////////// +/// @brief User ring constructor. +//////////////////////////////////////////////////////////// +User::User(const UserRingKind& ring_kind, const Char* user_name) : mUserRing(ring_kind) { + rt_copy_memory_safe((VoidPtr) user_name, this->mUserName, rt_string_len(user_name), + kMaxUserNameLen); +} + +//////////////////////////////////////////////////////////// +/// @brief User destructor class. +//////////////////////////////////////////////////////////// +User::~User() = default; + +Bool User::Save(const UserPublicKey password) { + if (!password || *password == 0) return No; + + this->mUserFNV = Detail::user_fnv_generator(password, this); + + kout << "User::Save: Saved password successfully...\r"; + + return Yes; +} + +Bool User::Login(const UserPublicKey password) { + if (!password || !*password) return No; + + auto ret = this->mUserFNV == Detail::user_fnv_generator(password, this); + + // now check if the password matches. + kout << (ret ? "User::Login: Password matches.\r" : "User::Login: Password doesn't match.\r"); + return ret; +} + +Bool User::operator==(const User& lhs) { + return lhs.mUserRing == this->mUserRing; +} + +Bool User::operator!=(const User& lhs) { + return lhs.mUserRing != this->mUserRing; +} + +//////////////////////////////////////////////////////////// +/// @brief Returns the user's name. +//////////////////////////////////////////////////////////// + +Char* User::Name() { + return this->mUserName; +} + +//////////////////////////////////////////////////////////// +/// @brief Returns the user's ring. +/// @return The king of ring the user is attached to. +//////////////////////////////////////////////////////////// + +const UserRingKind& User::Ring() { + return this->mUserRing; +} + +Bool User::IsStdUser() { + return this->Ring() == UserRingKind::kRingStdUser; +} + +Bool User::IsSuperUser() { + return this->Ring() == UserRingKind::kRingSuperUser; +} + +} // namespace Kernel diff --git a/src/kernel/src/UserMgr+User.cpp b/src/kernel/src/UserMgr+User.cpp deleted file mode 100644 index 0102beea..00000000 --- a/src/kernel/src/UserMgr+User.cpp +++ /dev/null @@ -1,122 +0,0 @@ -// Copyright 2024-2026, Amlal El Mahrouss (amlal@nekernel.org) -// Licensed under the Apache License, Version 2.0 (see LICENSE file) -// Official repository: https://github.com/ne-foss-org/nekernel - -#include -#include -#include -#include -#include -#include -#include -#include - -/// @file UserMgr.cc -/// @brief Multi-user support. - -namespace Kernel { - -namespace Detail { - //////////////////////////////////////////////////////////// - /// \brief Constructs a password by hashing the password. - /// \param password password to hash. - /// \return the hashed password - //////////////////////////////////////////////////////////// - STATIC UInt64 user_fnv_generator(const Char* password, User* user) { - kout << "user_fnv_generator: Try hashing user password...\r"; - - if (!password || !user) return 0; - if (*password == 0) return 0; - - const UInt64 kFnvOffsetBasis = 0xcbf29ce484222325ULL; - const UInt64 kFnvPrime = 0x100000001b3ULL; - - UInt64 hash = kFnvOffsetBasis; - - while (*password) { - hash ^= (Char) (*password++); - hash *= kFnvPrime; - } - - kout << "user_fnv_generator: Hashed user password.\r"; - - return hash; - } -} // namespace Detail - -//////////////////////////////////////////////////////////// -/// @brief User ring constructor. -//////////////////////////////////////////////////////////// -User::User(const Int32& sel, const Char* user_name) : mUserRing((UserRingKind) sel) { - MUST_PASS(sel >= 0); - rt_copy_memory_safe((VoidPtr) user_name, this->mUserName, rt_string_len(user_name), - kMaxUserNameLen); -} - -//////////////////////////////////////////////////////////// -/// @brief User ring constructor. -//////////////////////////////////////////////////////////// -User::User(const UserRingKind& ring_kind, const Char* user_name) : mUserRing(ring_kind) { - rt_copy_memory_safe((VoidPtr) user_name, this->mUserName, rt_string_len(user_name), - kMaxUserNameLen); -} - -//////////////////////////////////////////////////////////// -/// @brief User destructor class. -//////////////////////////////////////////////////////////// -User::~User() = default; - -Bool User::Save(const UserPublicKey password) { - if (!password || *password == 0) return No; - - this->mUserFNV = Detail::user_fnv_generator(password, this); - - kout << "User::Save: Saved password successfully...\r"; - - return Yes; -} - -Bool User::Login(const UserPublicKey password) { - if (!password || !*password) return No; - - auto ret = this->mUserFNV == Detail::user_fnv_generator(password, this); - - // now check if the password matches. - kout << (ret ? "User::Login: Password matches.\r" : "User::Login: Password doesn't match.\r"); - return ret; -} - -Bool User::operator==(const User& lhs) { - return lhs.mUserRing == this->mUserRing; -} - -Bool User::operator!=(const User& lhs) { - return lhs.mUserRing != this->mUserRing; -} - -//////////////////////////////////////////////////////////// -/// @brief Returns the user's name. -//////////////////////////////////////////////////////////// - -Char* User::Name() { - return this->mUserName; -} - -//////////////////////////////////////////////////////////// -/// @brief Returns the user's ring. -/// @return The king of ring the user is attached to. -//////////////////////////////////////////////////////////// - -const UserRingKind& User::Ring() { - return this->mUserRing; -} - -Bool User::IsStdUser() { - return this->Ring() == UserRingKind::kRingStdUser; -} - -Bool User::IsSuperUser() { - return this->Ring() == UserRingKind::kRingSuperUser; -} - -} // namespace Kernel diff --git a/src/kernel/src/UserMgr.cpp b/src/kernel/src/UserMgr.cpp new file mode 100644 index 00000000..c1b5140e --- /dev/null +++ b/src/kernel/src/UserMgr.cpp @@ -0,0 +1,21 @@ +// Copyright 2024-2026, Amlal El Mahrouss (amlal@nekernel.org) +// Licensed under the Apache License, Version 2.0 (see LICENSE file) +// Official repository: https://github.com/ne-foss-org/kernel + +#include +#include +#include +#include +#include +#include +#include +#include + +/// @file UserMgr+User.cpp +/// @brief Multi-user support. + +namespace Kernel { + + + +} -- cgit v1.2.3