diff options
| author | Amlal <amlal@nekernel.org> | 2025-04-27 03:44:22 +0200 |
|---|---|---|
| committer | Amlal <amlal@nekernel.org> | 2025-04-27 03:44:22 +0200 |
| commit | faee9f200898c0eb7f28ed89cdd16f8afa4438e1 (patch) | |
| tree | a61d1076b9239cb4f107d97e015d8d2c58edd09e /dev | |
| parent | 360c69daf7a83ec31c384390d9ec37064b78b40e (diff) | |
dev: fixes and improvements, codebase formating too.
Signed-off-by: Amlal <amlal@nekernel.org>
Diffstat (limited to 'dev')
| -rw-r--r-- | dev/ddk/DDKKit/ddk.h | 46 | ||||
| -rw-r--r-- | dev/ddk/DDKKit/dev.h | 2 | ||||
| -rw-r--r-- | dev/ddk/DDKKit/macros.h | 48 | ||||
| -rw-r--r-- | dev/kernel/FSKit/HeFS.h | 9 | ||||
| -rw-r--r-- | dev/kernel/KernelKit/CoreProcessScheduler.h | 4 | ||||
| -rw-r--r-- | dev/kernel/src/FS/HeFS.cc | 29 | ||||
| -rw-r--r-- | dev/kernel/src/FS/NeFS.cc | 2 | ||||
| -rw-r--r-- | dev/kernel/src/Gfx/FBDeviceInterface.cc | 2 | ||||
| -rw-r--r-- | dev/kernel/src/User.cc | 14 | ||||
| -rw-r--r-- | dev/kernel/src/UserProcessScheduler.cc | 9 | ||||
| -rw-r--r-- | dev/user/SystemCalls.h | 21 |
11 files changed, 114 insertions, 72 deletions
diff --git a/dev/ddk/DDKKit/ddk.h b/dev/ddk/DDKKit/ddk.h index b7bcd52c..888219c6 100644 --- a/dev/ddk/DDKKit/ddk.h +++ b/dev/ddk/DDKKit/ddk.h @@ -9,43 +9,7 @@ #pragma once -#include <stddef.h> -#include <stdint.h> - -#if defined(__cplusplus) -#define BOOL bool -#define YES true -#define NO false -#define DDK_EXTERN extern "C" __declspec(dllexport) -#define nil nullptr -#undef NULL -#define NULL 0 -#define DDK_FINAL final -#else -#define BOOL char -#define YES 1 -#define NO 0 -#define DDK_EXTERN extern __declspec(dllexport) -#define nil ((void*) 0) -#undef NULL -#define NULL ((void*) 0) -#define DDK_FINAL -#endif // defined(__cplusplus) - -#ifndef __DDK__ -#undef DDK_EXTERN -#if defined(__cplusplus) -#define DDK_EXTERN extern "C" __declspec(dllimport) -#else -#define DDK_EXTERN __declspec(dllimport) -#endif -#endif - -#define ATTRIBUTE(X) __attribute__((X)) - -#ifndef __NEOSKRNL__ -#error !!! Do not include header in EL0/Ring 3 mode !!! -#endif // __MINOSKRNL__ +#include <DDKKit/macros.h> struct DDK_STATUS_STRUCT; struct DDK_OBJECT_MANIFEST; @@ -59,10 +23,10 @@ struct DDK_OBJECT_MANIFEST DDK_FINAL { /// \brief DDK status ping structure. struct DDK_STATUS_STRUCT DDK_FINAL { - int32_t s_action_id; - int32_t s_issuer_id; - int32_t s_group_id; - void* s_object; + int32_t s_action_id; + int32_t s_issuer_id; + int32_t s_group_id; + struct DDK_OBJECT_MANIFEST* s_object; }; /// @brief Call Kernel procedure. diff --git a/dev/ddk/DDKKit/dev.h b/dev/ddk/DDKKit/dev.h index 6c8a828e..59fb48b5 100644 --- a/dev/ddk/DDKKit/dev.h +++ b/dev/ddk/DDKKit/dev.h @@ -23,6 +23,8 @@ typedef struct _DDK_DEVICE DDK_FINAL { void (*d_wait)(void); // write to device. struct _DDK_DEVICE* (*d_open)(const char* path); // open device. void (*d_close)(struct _DDK_DEVICE* dev); // close device. + void (*d_seek)(struct _DDK_DEVICE* dev, size_t off); + size_t (*d_tell)(struct _DDK_DEVICE* dev); } DDK_DEVICE, *DDK_DEVICE_PTR; /// @brief Open a new device from path. diff --git a/dev/ddk/DDKKit/macros.h b/dev/ddk/DDKKit/macros.h new file mode 100644 index 00000000..6de03ae0 --- /dev/null +++ b/dev/ddk/DDKKit/macros.h @@ -0,0 +1,48 @@ +/* ------------------------------------------- + + Copyright 2025 Amlal El Mahrouss. + + FILE: ddk.h + PURPOSE: DDK Driver model base header. + +------------------------------------------- */ + +#pragma once + +#include <stddef.h> +#include <stdint.h> + +#if defined(__cplusplus) +#define BOOL bool +#define YES true +#define NO false +#define DDK_EXTERN extern "C" __declspec(dllexport) +#define nil nullptr +#undef NULL +#define NULL 0 +#define DDK_FINAL final +#else +#define BOOL char +#define YES 1 +#define NO 0 +#define DDK_EXTERN extern __declspec(dllexport) +#define nil ((void*) 0) +#undef NULL +#define NULL ((void*) 0) +#define DDK_FINAL +#endif // defined(__cplusplus) + +#ifndef __DDK__ +#undef DDK_EXTERN +#if defined(__cplusplus) +#define DDK_EXTERN extern "C" __declspec(dllimport) +#else +#define DDK_EXTERN __declspec(dllimport) +#endif +#endif + +#define ATTRIBUTE(X) __attribute__((X)) + +#ifndef __NEOSKRNL__ +#error !!! Do not include header in EL0/Ring 3 mode !!! +#endif // __MINOSKRNL__
\ No newline at end of file diff --git a/dev/kernel/FSKit/HeFS.h b/dev/kernel/FSKit/HeFS.h index a2dd9fe0..c18f05d4 100644 --- a/dev/kernel/FSKit/HeFS.h +++ b/dev/kernel/FSKit/HeFS.h @@ -144,7 +144,8 @@ struct PACKED ALIGN(8) HEFS_INDEX_NODE final { Kernel::Utf16Char fMime[kHeFSFileNameLen]; /// @brief File mime type.
- Kernel::Boolean fSymLink; /// @brief Is this a symbolic link? (if yes, the fName is the path to the file and blocklinkstart and end contains it's inodes.)
+ Kernel::Boolean fSymLink; /// @brief Is this a symbolic link? (if yes, the fName is the path to
+ /// the file and blocklinkstart and end contains it's inodes.)
Kernel::ATime fCreated, fAccessed, fModified, fDeleted; /// @brief File timestamps.
Kernel::UInt32 fUID, fGID; /// @brief User ID and Group ID of the file.
@@ -181,7 +182,8 @@ struct PACKED ALIGN(8) HEFS_INDEX_NODE_DIRECTORY final { Kernel::Utf16Char fDim[kHeFSFileNameLen]; /// @brief Directiory Immatriculation magic.
- Kernel::ATime fCreated, fAccessed, fModified, fDeleted; /// @brief File timestamps and allocation status.
+ Kernel::ATime fCreated, fAccessed, fModified,
+ fDeleted; /// @brief File timestamps and allocation status.
Kernel::UInt32 fUID, fGID; /// @brief User ID and Group ID of the file.
Kernel::UInt32 fMode; /// @brief File mode. (read, write, execute, etc).
@@ -367,7 +369,8 @@ class HeFileSystemParser final { _Output Bool Format(_Input _Output DriveTrait* drive, _Input const Int32 flags,
const Utf16Char* part_name);
- _Output Bool CreateDirectory(_Input DriveTrait* drive, _Input const Int32 flags, const Utf16Char* dir);
+ _Output Bool CreateDirectory(_Input DriveTrait* drive, _Input const Int32 flags,
+ const Utf16Char* dir);
_Output Bool CreateFile(_Input DriveTrait* drive, _Input const Int32 flags, const Utf16Char* dir,
const Utf16Char* name);
diff --git a/dev/kernel/KernelKit/CoreProcessScheduler.h b/dev/kernel/KernelKit/CoreProcessScheduler.h index 42def9fc..acaa66c0 100644 --- a/dev/kernel/KernelKit/CoreProcessScheduler.h +++ b/dev/kernel/KernelKit/CoreProcessScheduler.h @@ -115,7 +115,7 @@ using ImagePtr = VoidPtr; struct PROCESS_IMAGE final { explicit PROCESS_IMAGE() = default; -private: + private: friend USER_PROCESS; friend KERNEL_PROCESS; friend class UserProcessScheduler; @@ -123,7 +123,7 @@ private: ImagePtr fCode; ImagePtr fBlob; -public: + public: Bool HasCode() const { return this->fCode != nullptr; } Bool HasImage() const { return this->fBlob != nullptr; } diff --git a/dev/kernel/src/FS/HeFS.cc b/dev/kernel/src/FS/HeFS.cc index 13d79c8f..f36cf3b6 100644 --- a/dev/kernel/src/FS/HeFS.cc +++ b/dev/kernel/src/FS/HeFS.cc @@ -79,7 +79,8 @@ namespace Detail { NE_UNUSED(node); if (!dir || !node) { - ke_panic(RUNTIME_CHECK_FILESYSTEM, "Error: Invalid directory node/boot_node in RB-Tree traversal."); + ke_panic(RUNTIME_CHECK_FILESYSTEM, + "Error: Invalid directory node/boot_node in RB-Tree traversal."); } if (dir->fChild != 0) { @@ -315,8 +316,7 @@ namespace Detail { return NO; } - if (parent->fDeleted || - !parent->fCreated) { + if (parent->fDeleted || !parent->fCreated) { mnt->fPacket.fPacketLba = start; mnt->fPacket.fPacketSize = sizeof(HEFS_INDEX_NODE_DIRECTORY); mnt->fPacket.fPacketContent = dir; @@ -790,13 +790,20 @@ _Output Bool HeFileSystemParser::Format(_Input _Output DriveTrait* drive, _Input // Check if the disk is already formatted. - if (KStringBuilder::Equals(root->fMagic, kHeFSMagic)) { + if (KStringBuilder::Equals(root->fMagic, kHeFSMagic) && root->fVersion == kHeFSVersion) { delete root; root = nullptr; err_global_get() = kErrorSuccess; return YES; + } else if (root->fVersion != kHeFSVersion) { + delete root; + root = nullptr; + + err_global_get() = kErrorUnrecoverableDisk; + + return NO; } rt_set_memory(root, 0, sizeof(HEFS_BOOT_NODE)); @@ -835,6 +842,8 @@ _Output Bool HeFileSystemParser::Format(_Input _Output DriveTrait* drive, _Input root->fReserved3 = 0; root->fReserved4 = 0; + root->fVersion = kHeFSVersion; + root->fChecksum = 0; root->fVID = kHeFSInvalidVID; @@ -939,7 +948,7 @@ _Output Bool HeFileSystemParser::CreateDirectory(_Input DriveTrait* drive, _Inpu drive->fInput(drive->fPacket); Detail::hefsi_balance_filesystem(root, drive); - + auto dirent = Detail::hefs_fetch_index_node_directory(root, drive, dir); if (dirent) { @@ -1067,6 +1076,9 @@ _Output Bool HeFileSystemParser::CreateFile(_Input DriveTrait* drive, _Input con node->fFlags = flags; node->fChecksum = 0; + node->fGID = 0; + node->fUID = 0; + wrt_copy_memory((VoidPtr) name, node->fName, wrt_string_len(name)); if (Detail::hefs_allocate_index_node(root, drive, dir, node)) { @@ -1076,18 +1088,21 @@ _Output Bool HeFileSystemParser::CreateFile(_Input DriveTrait* drive, _Input con return YES; } + delete node; + delete root; + return NO; } /// @brief Initialize the HeFS filesystem. /// @return To check its status, see err_local_get(). Boolean fs_init_hefs(Void) noexcept { - kout << "Creating main disk with HeFS in it...\r"; + kout << "Creating HeFS disk...\r"; auto drv = io_construct_main_drive(); if (drv.fPacket.fPacketReadOnly == YES) - ke_panic(RUNTIME_CHECK_FILESYSTEM, "Main filesystem cannot be mounted."); + ke_panic(RUNTIME_CHECK_FILESYSTEM, "Main disk cannot be mounted."); HeFileSystemParser parser; diff --git a/dev/kernel/src/FS/NeFS.cc b/dev/kernel/src/FS/NeFS.cc index e0cdc71b..e68a4035 100644 --- a/dev/kernel/src/FS/NeFS.cc +++ b/dev/kernel/src/FS/NeFS.cc @@ -877,7 +877,7 @@ Boolean fs_init_nefs(Void) noexcept { kMountpoint.A() = io_construct_main_drive(); if (kMountpoint.A().fPacket.fPacketReadOnly == YES) - ke_panic(RUNTIME_CHECK_FILESYSTEM, "Main filesystem cannot be mounted."); + ke_panic(RUNTIME_CHECK_FILESYSTEM, "Main disk cannot be mounted."); NeFileSystemParser parser; parser.Format(&kMountpoint.A(), 0, kNeFSVolumeName); diff --git a/dev/kernel/src/Gfx/FBDeviceInterface.cc b/dev/kernel/src/Gfx/FBDeviceInterface.cc index be52655d..d588e8c8 100644 --- a/dev/kernel/src/Gfx/FBDeviceInterface.cc +++ b/dev/kernel/src/Gfx/FBDeviceInterface.cc @@ -37,7 +37,7 @@ FBDeviceInterface& FBDeviceInterface::operator<<(FBDevicePacket* pckt) { /// @return the class itself after operation. FBDeviceInterface& FBDeviceInterface::operator>>(FBDevicePacket* pckt) { if (!pckt) return *this; - + this->fIn(this, pckt); return *this; diff --git a/dev/kernel/src/User.cc b/dev/kernel/src/User.cc index 54f3853d..3e6aeeba 100644 --- a/dev/kernel/src/User.cc +++ b/dev/kernel/src/User.cc @@ -29,20 +29,20 @@ namespace Detail { /// \param password password to hash. /// \return the hashed password //////////////////////////////////////////////////////////// - Int32 cred_construct_token(Char* password, const Char* in_password, User* user, SizeT length) { + Int32 user_standard_token_generator(Char* password, const Char* in_password, User* user, + SizeT length) { if (!password || !user) return 1; + if (*password == 0) return 1; - kout << "cred_construct_token: Hashing user password...\r"; + kout << "user_standard_token_generator: Hashing user password...\r"; for (SizeT i_pass = 0UL; i_pass < length; ++i_pass) { Char cur_chr = in_password[i_pass]; - if (cur_chr == 0) break; - password[i_pass] = cur_chr | (user->IsStdUser() ? kStdUserType : kSuperUserType); } - kout << "cred_construct_token: Hashed user password.\r"; + kout << "user_standard_token_generator: Hashed user password.\r"; return 0; } @@ -84,7 +84,7 @@ Bool User::Save(const UserPublicKey password_to_fill) noexcept { rt_copy_memory((VoidPtr) password_to_fill, password, len); - if (!Detail::cred_construct_token(password, password_to_fill, this, len)) { + if (!Detail::user_standard_token_generator(password, password_to_fill, this, len)) { delete[] password; password = nullptr; @@ -116,7 +116,7 @@ Bool User::Matches(const UserPublicKey password_to_fill) noexcept { rt_copy_memory((VoidPtr) password_to_fill, password, len); - if (!Detail::cred_construct_token(password, password_to_fill, this, len)) { + if (!Detail::user_standard_token_generator(password, password_to_fill, this, len)) { delete[] password; password = nullptr; diff --git a/dev/kernel/src/UserProcessScheduler.cc b/dev/kernel/src/UserProcessScheduler.cc index bc2cc8e2..5d983f34 100644 --- a/dev/kernel/src/UserProcessScheduler.cc +++ b/dev/kernel/src/UserProcessScheduler.cc @@ -101,8 +101,14 @@ Void USER_PROCESS::Wake(Bool should_wakeup) { STATIC USER_PROCESS::USER_HEAP_TREE* sched_try_go_upper_heap_tree( USER_PROCESS::USER_HEAP_TREE* tree) { + if (!tree) { + return nullptr; + } + + tree = tree->MemoryParent; + if (tree) { - tree = tree->MemoryNext; + tree = tree->MemoryParent; if (!tree) { return nullptr; @@ -162,7 +168,6 @@ ErrorOr<VoidPtr> USER_PROCESS::New(SizeT sz, SizeT pad_amount) { entry = entry->MemoryChild; is_parent = YES; } else { - entry = entry->MemoryParent; entry = sched_try_go_upper_heap_tree(entry); } } diff --git a/dev/user/SystemCalls.h b/dev/user/SystemCalls.h index 4ff7de11..5bbe2f26 100644 --- a/dev/user/SystemCalls.h +++ b/dev/user/SystemCalls.h @@ -35,14 +35,14 @@ typedef Ref SocketRef; IMPORT_C Ref LdrGetDLLSymbolFromHandle(_Input const Char* symbol, _Input Ref dll_handle);
/// @brief Open Dylib handle.
-/// @param path
-/// @param drv
-/// @return
+/// @param path dll path.
+/// @param drv driver letter.
+/// @return a dylib ref.
IMPORT_C Ref LdrOpenDLLHandle(_Input const Char* path, _Input const Char* drive_letter);
/// @brief Close Dylib handle
-/// @param dll_handle
-/// @return
+/// @param dll_handle the dylib ref.
+/// @return whether it closed or not.
IMPORT_C UInt32 LdrCloseDLLHandle(_Input Ref* dll_handle);
// ------------------------------------------------------------------------------------------ //
@@ -67,14 +67,19 @@ IMPORT_C Void IoCloseFile(_Input Ref file_desc); /// @param out_data the output data.
/// @return the number of bytes written.
/// @note This function is used to control the file descriptor, introduced for HeFS.
-IMPORT_C SInt32 IoCTLFile(_Input Ref file_desc, _Input UInt32 ioctl_code, _Input VoidPtr in_data,
- _Output VoidPtr out_data);
+IMPORT_C SInt32 IoCtrlFile(_Input Ref file_desc, _Input UInt32 ioctl_code, _Input VoidPtr in_data,
+ _Output VoidPtr out_data);
/// @brief Gets the file mime (if any)
/// @param file_desc the file descriptor.
IMPORT_C const Char* IoMimeFile(_Input Ref file_desc);
-/// @brief Write data to a file.
+/// @brief Gets the dir DIM.
+/// @param dir_desc directory descriptor.
+/// @note only works in HeFS, will return nil-x/nil if used on any other filesystem.
+IMPORT_C const Char* IoDimFile(_Input Ref dir_desc);
+
+/// @brief Write data to a file ref
/// @param file_desc the file descriptor.
/// @param out_data the data to write.
/// @param sz_data the size of the data to write.
|
