summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2026-03-06 19:48:55 +0100
committerAmlal El Mahrouss <amlal@nekernel.org>2026-03-06 19:48:55 +0100
commit94f0d53e6f57edb09541a3a7d67dd82a1f187a33 (patch)
tree6849038374e7f5f570090bf108d1e656816eef91 /src
parent1e1a36c03e9c564f33d1a610f77c858bb7127f72 (diff)
[FEAT] Implement OpenHeFS FileMgr, and semaphores API design rework.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'src')
-rw-r--r--src/kernel/KernelKit/Semaphore.h8
-rw-r--r--src/kernel/src/FS/NeFS+FileMgr.cpp5
-rw-r--r--src/kernel/src/FS/OpenHeFS+FileMgr.cpp36
-rw-r--r--src/kernel/src/Storage/AHCIDeviceInterface.cpp4
-rw-r--r--src/libPOSIX/POSIXKit/unistd.h0
5 files changed, 34 insertions, 19 deletions
diff --git a/src/kernel/KernelKit/Semaphore.h b/src/kernel/KernelKit/Semaphore.h
index 3fe993b4..4dc8f388 100644
--- a/src/kernel/KernelKit/Semaphore.h
+++ b/src/kernel/KernelKit/Semaphore.h
@@ -27,7 +27,7 @@ namespace Kernel {
using SemaphoreArr = UInt64[kSemaphoreCount];
/// @brief Checks if the semaphore is valid.
-inline bool rtl_sem_is_valid(const SemaphoreArr& sem, UInt64 owner = 0) {
+inline bool rtl_sem_is_valid(const SemaphoreArr& sem, const UInt64& owner = 0) {
return sem[kSemaphoreOwnerIndex] == owner && sem[kSemaphoreCountIndex] > 0;
}
@@ -45,10 +45,10 @@ inline bool rtl_sem_release(SemaphoreArr& sem) {
/// @param sem the semaphore array to use.
/// @param owner the owner to set, could be anything identifitable.
/// @return
-inline bool rtl_sem_acquire(SemaphoreArr& sem, const UInt64 owner) {
+inline bool rtl_sem_acquire(SemaphoreArr& sem, const UInt64& owner) {
if (!owner) {
err_global_get() = kErrorInvalidData;
- return false; // Invalid owner
+ return false; // Invalid owner, return false and set KPC.
}
sem[kSemaphoreOwnerIndex] = owner;
@@ -62,7 +62,7 @@ inline bool rtl_sem_acquire(SemaphoreArr& sem, const UInt64 owner) {
/// @param timeout
/// @param condition condition pointer.
/// @return
-inline bool rtl_sem_wait(SemaphoreArr& sem, const UInt64 owner, const UInt64 timeout,
+inline bool rtl_sem_wait(SemaphoreArr& sem, const UInt64& owner, const UInt64& timeout,
bool& condition) {
if (!rtl_sem_is_valid(sem, owner)) {
return false;
diff --git a/src/kernel/src/FS/NeFS+FileMgr.cpp b/src/kernel/src/FS/NeFS+FileMgr.cpp
index bec50c7f..72161355 100644
--- a/src/kernel/src/FS/NeFS+FileMgr.cpp
+++ b/src/kernel/src/FS/NeFS+FileMgr.cpp
@@ -49,6 +49,7 @@ NodePtr NeFileSystemMgr::Create(_Input const Char* path) {
kout << "NeFS: Create called with null or empty path\n";
return nullptr;
}
+
return rtl_node_cast(mParser->CreateCatalog(path));
}
@@ -60,6 +61,7 @@ NodePtr NeFileSystemMgr::CreateDirectory(const Char* path) {
kout << "NeFS: CreateDirectory called with null or empty path\n";
return nullptr;
}
+
return rtl_node_cast(mParser->CreateCatalog(path, 0, kNeFSCatalogKindDir));
}
@@ -71,6 +73,7 @@ NodePtr NeFileSystemMgr::CreateAlias(const Char* path) {
kout << "NeFS: CreateAlias called with null or empty path\n";
return nullptr;
}
+
return rtl_node_cast(mParser->CreateCatalog(path, 0, kNeFSCatalogKindAlias));
}
@@ -115,10 +118,12 @@ _Output NodePtr NeFileSystemMgr::Open(_Input const Char* path, _Input const Char
kout << "NeFS: Open called with null or empty path\n";
return nullptr;
}
+
if (!r || *r == 0) {
kout << "NeFS: Open called with null or empty mode string\n";
return nullptr;
}
+
auto catalog = mParser->GetCatalog(path);
if (!catalog) {
kout << "NeFS: Open could not find catalog for path\n";
diff --git a/src/kernel/src/FS/OpenHeFS+FileMgr.cpp b/src/kernel/src/FS/OpenHeFS+FileMgr.cpp
index ef367076..8ec3d2cc 100644
--- a/src/kernel/src/FS/OpenHeFS+FileMgr.cpp
+++ b/src/kernel/src/FS/OpenHeFS+FileMgr.cpp
@@ -222,18 +222,21 @@ _Output VoidPtr HeFileSystemMgr::Read(_Input NodePtr node, _Input Int32 flags, _
/// @note name is not used in OpenHeFS to mark data offsets. That's an NeFS-ism.
Void HeFileSystemMgr::Write(_Input const Char* name, _Input NodePtr node, _Input VoidPtr data,
_Input Int32 flags, _Input SizeT size) {
- //NE_UNUSED(node);
+ NE_UNUSED(node);
//NE_UNUSED(flags);
//NE_UNUSED(size);
- NE_UNUSED(name);
+ //NE_UNUSED(name);
//NE_UNUSED(data);
- if (!node) return;
if (!flags) return;
if (!size) return;
if (!data) return;
+ if (!name) return;
-
+ static IMountpoint mnt;
+ io_construct_main_drive(mnt.A());
+
+ mParser->INodeManip(&mnt.A(), (VoidPtr)data, size, u8"/", (Char8*)name, 0, NO);
}
_Output VoidPtr HeFileSystemMgr::Read(_Input const Char* name, _Input NodePtr node,
@@ -243,31 +246,38 @@ _Output VoidPtr HeFileSystemMgr::Read(_Input const Char* name, _Input NodePtr no
NE_UNUSED(sz);
NE_UNUSED(name);
- return nullptr;
+ UInt8* retBlob = new UInt8[sz];
+ rt_set_memory(retBlob, 0, sz);
+
+ static IMountpoint mnt;
+ io_construct_main_drive(mnt.A());
+
+ mParser->INodeManip(&mnt.A(), (VoidPtr)retBlob, sz, u8"/", (Char8*)name, 0, YES);
+
+ return retBlob;
}
_Output Bool HeFileSystemMgr::Seek(NodePtr node, SizeT off) {
- if (!node || !off) return false;
-
- return false;
+ if (this->Tell(node) == kFileMgrNPos) return false;
+ return off > 0;
}
/// @brief Tell current offset within catalog.
-/// @param node
+/// @param node The HeFS node we need.
/// @return kFileMgrNPos if invalid, else current offset.
_Output SizeT HeFileSystemMgr::Tell(NodePtr node) {
if (!node) return kFileMgrNPos;
SizeT pos = 0ULL;
+
return pos;
}
/// @brief Rewinds the catalog
-/// @param node
+/// @param node The needed HeFS node.
/// @return False if invalid, nah? calls Seek(node, 0).
_Output Bool HeFileSystemMgr::Rewind(NodePtr node) {
- if (!node) return kFileMgrNPos;
-
- return 0;
+ if (!node) return false;
+ return true;
}
/// @brief Returns the parser of OpenHeFS.
diff --git a/src/kernel/src/Storage/AHCIDeviceInterface.cpp b/src/kernel/src/Storage/AHCIDeviceInterface.cpp
index 1ae4555b..b2af94fb 100644
--- a/src/kernel/src/Storage/AHCIDeviceInterface.cpp
+++ b/src/kernel/src/Storage/AHCIDeviceInterface.cpp
@@ -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
@@ -84,4 +84,4 @@ Void AHCIDeviceInterface::SetIndex(const UInt32& drv) {
this->fDriveIndex = drv;
}
-} // namespace Kernel \ No newline at end of file
+} // namespace Kernel
diff --git a/src/libPOSIX/POSIXKit/unistd.h b/src/libPOSIX/POSIXKit/unistd.h
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/src/libPOSIX/POSIXKit/unistd.h