summaryrefslogtreecommitdiffhomepage
path: root/dev
diff options
context:
space:
mode:
authorAmlal <amlal@nekernel.org>2025-04-26 13:44:35 +0200
committerAmlal <amlal@nekernel.org>2025-04-26 13:44:35 +0200
commit9c33e844d76f9db6d7110de4f05cbe2084cdbca1 (patch)
tree9875059712c6e819ae9a3dbbccda7ba105708326 /dev
parenta02a39e77abf2a71bcd023c33c63d405ef1c3081 (diff)
dev, kernel and user: codebase additions and work in progress 'tactical pause'
why? - HeFS's Formating needs some thought before being layed out, that's the kind of thing that bites hard in the ass. - Alongside those changes I improved parts of the kernel too. Signed-off-by: Amlal <amlal@nekernel.org>
Diffstat (limited to 'dev')
-rw-r--r--dev/kernel/FSKit/HeFS.h10
-rw-r--r--dev/kernel/KernelKit/DeviceMgr.h4
-rw-r--r--dev/kernel/src/DriveMgr.cc2
-rw-r--r--dev/kernel/src/FS/HeFS.cc51
-rw-r--r--dev/kernel/src/Gfx/FBDeviceInterface.cc10
-rw-r--r--dev/kernel/src/Storage/AHCIDeviceInterface.cc2
-rw-r--r--dev/kernel/src/Storage/ATADeviceInterface.cc2
-rw-r--r--dev/kernel/src/Storage/NVMEDeviceInterface.cc2
-rw-r--r--dev/user/SystemCalls.h10
9 files changed, 73 insertions, 20 deletions
diff --git a/dev/kernel/FSKit/HeFS.h b/dev/kernel/FSKit/HeFS.h
index 895422a6..693ec2d3 100644
--- a/dev/kernel/FSKit/HeFS.h
+++ b/dev/kernel/FSKit/HeFS.h
@@ -28,6 +28,9 @@
#define kHeFSDefaultVoluneName u"HeFS Volume"
+#define kHeFSDIMBootDir u"boot-x/dir"
+#define kHeFSDIMBootFile u"boot-x/file"
+
#define kHeFSSearchAllStr u"*"
struct HEFS_BOOT_NODE;
@@ -63,6 +66,7 @@ enum {
kHeFSEncodingUTF32LE,
kHeFSEncodingUTF8BE,
kHeFSEncodingUTF8LE,
+ kHeFSEncodingBinary,
kHeFSEncodingCount,
};
@@ -135,6 +139,10 @@ struct PACKED ALIGN(8) HEFS_INDEX_NODE final {
fLinkChecksum; /// @brief Checksum of the file, recovery checksum, block checksum, link
/// checksum.
+ 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::ATime fCreated, fAccessed, fModified, fDeleted; /// @brief File timestamps.
Kernel::UInt32 fUID, fGID; /// @brief User ID and Group ID of the file.
Kernel::UInt32 fMode; /// @brief File mode. (read, write, execute, etc).
@@ -168,6 +176,8 @@ struct PACKED ALIGN(8) HEFS_INDEX_NODE_DIRECTORY final {
Kernel::UInt32 fChecksum,
fIndexNodeChecksum; /// @brief Checksum of the file, index node checksum.
+ Kernel::Utf16Char fDim[kHeFSFileNameLen]; /// @brief Directiory Immatriculation magic.
+
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).
diff --git a/dev/kernel/KernelKit/DeviceMgr.h b/dev/kernel/KernelKit/DeviceMgr.h
index 8da52699..210cef2a 100644
--- a/dev/kernel/KernelKit/DeviceMgr.h
+++ b/dev/kernel/KernelKit/DeviceMgr.h
@@ -22,7 +22,7 @@
#include <NewKit/ErrorOr.h>
#include <NewKit/Ref.h>
-#define kDeviceMgrRootDirPath "/dev/"
+#define kDeviceMgrRootDirPath "/devices/"
#define NE_DEVICE : public ::Kernel::IDeviceObject
@@ -58,7 +58,7 @@ class IDeviceObject {
return *this;
}
- virtual const char* Name() const { return "/dev/null"; }
+ virtual const char* Name() const { return "/devices/null"; }
operator bool() { return fOut && fIn; }
diff --git a/dev/kernel/src/DriveMgr.cc b/dev/kernel/src/DriveMgr.cc
index 17c6c8cc..46a5c588 100644
--- a/dev/kernel/src/DriveMgr.cc
+++ b/dev/kernel/src/DriveMgr.cc
@@ -25,7 +25,7 @@ STATIC UInt8 kATAMaster = 0U;
#endif
#if defined(__AHCI__)
-STATIC UInt16 kAHCIPortsImplemented = 0UL;
+STATIC UInt16 kAHCIPortsImplemented [[maybe_unused]] = 0UL;
#endif
/// @brief reads from an ATA drive.
diff --git a/dev/kernel/src/FS/HeFS.cc b/dev/kernel/src/FS/HeFS.cc
index 1da886c4..81316ba5 100644
--- a/dev/kernel/src/FS/HeFS.cc
+++ b/dev/kernel/src/FS/HeFS.cc
@@ -756,7 +756,7 @@ namespace Kernel::HeFS {
/// @param drive The drive to write on.
/// @return If it was sucessful, see err_local_get().
_Output Bool HeFileSystemParser::Format(_Input _Output DriveTrait* drive, _Input const Int32 flags,
- const Utf16Char* part_name) {
+ _Input const Utf16Char* part_name) {
NE_UNUSED(drive);
NE_UNUSED(flags);
NE_UNUSED(part_name);
@@ -779,6 +779,34 @@ _Output Bool HeFileSystemParser::Format(_Input _Output DriveTrait* drive, _Input
rt_set_memory(root, 0, sizeof(HEFS_BOOT_NODE));
+ drive->fPacket.fPacketLba = drive->fLbaStart;
+ drive->fPacket.fPacketSize = sizeof(HEFS_BOOT_NODE);
+ drive->fPacket.fPacketContent = root;
+
+ drive->fInput(drive->fPacket);
+
+ if (!drive->fPacket.fPacketGood) {
+ delete root;
+ root = nullptr;
+
+ err_global_get() = kErrorDiskIsCorrupted;
+
+ return NO;
+ }
+
+ // Check if the disk is already formatted.
+
+ if (KStringBuilder::Equals(root->fMagic, kHeFSMagic)) {
+ delete root;
+ root = nullptr;
+
+ err_global_get() = kErrorSuccess;
+
+ return YES;
+ }
+
+ rt_set_memory(root, 0, sizeof(HEFS_BOOT_NODE));
+
rt_copy_memory((VoidPtr) "fs/hefs-packet", drive->fPacket.fPacketMime,
rt_string_len("fs/hefs-packet"));
@@ -836,9 +864,10 @@ _Output Bool HeFileSystemParser::Format(_Input _Output DriveTrait* drive, _Input
rt_set_memory(root_dir, 0, sizeof(HEFS_INDEX_NODE_DIRECTORY));
wrt_copy_memory((VoidPtr) u"/", root_dir->fName, wrt_string_len(u"/"));
+ wrt_copy_memory((VoidPtr) kHeFSDIMBootDir, root_dir->fDim, wrt_string_len(kHeFSDIMBootDir));
root_dir->fKind = kHeFSFileKindDirectory;
- root_dir->fColor = kHeFSBlack;
+ root_dir->fColor = kHeFSBlack; // Every RB-Tree root starts black. (a condition of the algorithm)
root_dir->fParent = 0; // No parent (it's the real root)
root_dir->fChild = 0; // No children yet
root_dir->fNext = 0; // No next
@@ -858,6 +887,19 @@ _Output Bool HeFileSystemParser::Format(_Input _Output DriveTrait* drive, _Input
root = nullptr;
root_dir = nullptr;
+ // Create the directories, something UNIX inspired but more explicit and forward looking.
+
+ this->CreateDirectory(drive, kHeFSEncodingUTF16, u"/boot");
+ this->CreateDirectory(drive, kHeFSEncodingUTF16, u"/netdevices");
+ this->CreateDirectory(drive, kHeFSEncodingUTF16, u"/binaries");
+ this->CreateDirectory(drive, kHeFSEncodingUTF16, u"/users");
+ this->CreateDirectory(drive, kHeFSEncodingUTF16, u"/config");
+ this->CreateDirectory(drive, kHeFSEncodingUTF16, u"/config/xml");
+ this->CreateDirectory(drive, kHeFSEncodingUTF16, u"/config/json");
+ this->CreateDirectory(drive, kHeFSEncodingUTF16, u"/devices");
+ this->CreateDirectory(drive, kHeFSEncodingUTF16, u"/media");
+ this->CreateFile(drive, kHeFSEncodingBinary, u"/", u"mk.hefs");
+
if (drive->fPacket.fPacketGood) return YES;
err_global_get() = kErrorDiskIsCorrupted;
@@ -1036,7 +1078,7 @@ _Output Bool HeFileSystemParser::CreateFile(_Input DriveTrait* drive, _Input con
}
Boolean fs_init_hefs(Void) noexcept {
- kout << "Creating main disk...\r";
+ kout << "Creating main disk with HeFS in it...\r";
auto drv = io_construct_main_drive();
@@ -1047,9 +1089,6 @@ Boolean fs_init_hefs(Void) noexcept {
parser.Format(&drv, kHeFSEncodingUTF16, kHeFSDefaultVoluneName);
- parser.CreateDirectory(&drv, kHeFSEncodingUTF16, u"boot");
- parser.CreateFile(&drv, kHeFSEncodingUTF16, u"boot", u".hefs");
-
return YES;
}
} // namespace Kernel::HeFS
diff --git a/dev/kernel/src/Gfx/FBDeviceInterface.cc b/dev/kernel/src/Gfx/FBDeviceInterface.cc
index 185b22b0..be52655d 100644
--- a/dev/kernel/src/Gfx/FBDeviceInterface.cc
+++ b/dev/kernel/src/Gfx/FBDeviceInterface.cc
@@ -27,9 +27,6 @@ FBDeviceInterface& FBDeviceInterface::operator<<(FBDevicePacket* pckt) {
if (pckt->fHeight == 0 || pckt->fWidth == 0) return *this;
- if (pckt->fX > kHandoverHeader->f_GOP.f_Width || pckt->fY > kHandoverHeader->f_GOP.f_Height)
- return *this;
-
this->fOut(this, pckt);
return *this;
@@ -40,10 +37,7 @@ FBDeviceInterface& FBDeviceInterface::operator<<(FBDevicePacket* pckt) {
/// @return the class itself after operation.
FBDeviceInterface& FBDeviceInterface::operator>>(FBDevicePacket* pckt) {
if (!pckt) return *this;
-
- if (pckt->fX > kHandoverHeader->f_GOP.f_Width || pckt->fY > kHandoverHeader->f_GOP.f_Height)
- return *this;
-
+
this->fIn(this, pckt);
return *this;
@@ -52,5 +46,5 @@ FBDeviceInterface& FBDeviceInterface::operator>>(FBDevicePacket* pckt) {
/// @brief Returns the name of the device interface.
/// @return it's name as a string.
const Char* FBDeviceInterface::Name() const {
- return "/dev/fb{}";
+ return "/devices/fb{}";
} \ No newline at end of file
diff --git a/dev/kernel/src/Storage/AHCIDeviceInterface.cc b/dev/kernel/src/Storage/AHCIDeviceInterface.cc
index d5c1e5c6..2d97eee7 100644
--- a/dev/kernel/src/Storage/AHCIDeviceInterface.cc
+++ b/dev/kernel/src/Storage/AHCIDeviceInterface.cc
@@ -24,7 +24,7 @@ AHCIDeviceInterface::~AHCIDeviceInterface() = default;
/// @brief Returns the name of the device interface.
/// @return it's name as a string.
const Char* AHCIDeviceInterface::Name() const {
- return "/dev/sda{}";
+ return "/devices/sda{}";
}
/// @brief Output operator.
diff --git a/dev/kernel/src/Storage/ATADeviceInterface.cc b/dev/kernel/src/Storage/ATADeviceInterface.cc
index f38d5359..a66d812b 100644
--- a/dev/kernel/src/Storage/ATADeviceInterface.cc
+++ b/dev/kernel/src/Storage/ATADeviceInterface.cc
@@ -22,7 +22,7 @@ ATADeviceInterface::~ATADeviceInterface() = default;
/// @brief Returns the name of the device interface.
/// @return it's name as a string.
const Char* ATADeviceInterface::Name() const {
- return "/dev/hda{}";
+ return "/devices/hda{}";
}
/// @brief Output operator.
diff --git a/dev/kernel/src/Storage/NVMEDeviceInterface.cc b/dev/kernel/src/Storage/NVMEDeviceInterface.cc
index edec6d6d..cff776c9 100644
--- a/dev/kernel/src/Storage/NVMEDeviceInterface.cc
+++ b/dev/kernel/src/Storage/NVMEDeviceInterface.cc
@@ -18,6 +18,6 @@ NVMEDeviceInterface::~NVMEDeviceInterface() {
}
const Char* NVMEDeviceInterface::Name() const {
- return ("/dev/nvme{}");
+ return ("/devices/nvme{}");
}
} // namespace Kernel
diff --git a/dev/user/SystemCalls.h b/dev/user/SystemCalls.h
index 1e391d8a..4ff7de11 100644
--- a/dev/user/SystemCalls.h
+++ b/dev/user/SystemCalls.h
@@ -60,6 +60,16 @@ IMPORT_C Ref IoOpenFile(const Char* fs_path, const Char* drive_letter);
/// @return Function doesn't return a type.
IMPORT_C Void IoCloseFile(_Input Ref file_desc);
+/// @brief I/O control (ioctl) on a file.
+/// @param file_desc the file descriptor.
+/// @param ioctl_code the ioctl code.
+/// @param in_data the input data.
+/// @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);
+
/// @brief Gets the file mime (if any)
/// @param file_desc the file descriptor.
IMPORT_C const Char* IoMimeFile(_Input Ref file_desc);