summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-07-08 09:35:45 +0200
committerAmlal El Mahrouss <amlal@nekernel.org>2025-07-08 09:36:50 +0200
commit3616886fed21351949865ba0f57011624a172e74 (patch)
tree3ff4f3f64c1fa6bc08d2111ca66056e1f7877db8
parentf6a7873714c73b8f3d3190669f8a3181d6679b9d (diff)
feat: Reinforce code inside PEFCodeMgr and mkfs.hefs, extend fsck.hefs
and libmkfs. fix: Fix UserMgr FNV hashing. Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
-rw-r--r--dev/kernel/src/PEFCodeMgr.cc9
-rw-r--r--dev/kernel/src/UserMgr.cc6
-rw-r--r--dev/kernel/src/UserProcessTeam.cc1
-rw-r--r--dev/kernel/src/UtfUtils.cc2
-rw-r--r--tooling/fsck.hefs.cc10
-rw-r--r--tooling/libmkfs/mkfs.h3
-rw-r--r--tooling/mkfs.hefs.cc8
7 files changed, 30 insertions, 9 deletions
diff --git a/dev/kernel/src/PEFCodeMgr.cc b/dev/kernel/src/PEFCodeMgr.cc
index f5f0eeb5..db24336e 100644
--- a/dev/kernel/src/PEFCodeMgr.cc
+++ b/dev/kernel/src/PEFCodeMgr.cc
@@ -17,6 +17,10 @@
#include <NeKit/OwnPtr.h>
#include <NeKit/Utils.h>
+/// @author Amlal El Mahrouss (amlal@nekernel.org)
+/// @brief PEF backend for the Code Manager.
+/// @file PEFCodeMgr.cc
+
/// @brief PEF stack size symbol.
#define kPefStackSizeSymbol "__PEFSizeOfReserveStack"
#define kPefHeapSizeSymbol "__PEFSizeOfReserveHeap"
@@ -61,9 +65,10 @@ PEFLoader::PEFLoader(const Char* path) : fCachedBlob(nullptr), fFatBinary(false)
fFile.New(const_cast<Char*>(path), kRestrictRB);
fPath = KStringBuilder::Construct(path).Leak();
- auto kPefHeader = "PEF_CONTAINER";
+ constexpr auto kPefHeader = "PEF_CONTAINER";
- fCachedBlob = fFile->Read(kPefHeader, mib_cast(16));
+ /// @note zero here means that the FileMgr will read every container header inside the file.
+ fCachedBlob = fFile->Read(kPefHeader, 0UL);
PEFContainer* container = reinterpret_cast<PEFContainer*>(fCachedBlob);
diff --git a/dev/kernel/src/UserMgr.cc b/dev/kernel/src/UserMgr.cc
index 2b0b06ba..8e4ba540 100644
--- a/dev/kernel/src/UserMgr.cc
+++ b/dev/kernel/src/UserMgr.cc
@@ -33,8 +33,8 @@ namespace Detail {
/// \return the hashed password
////////////////////////////////////////////////////////////
STATIC UInt64 user_fnv_generator(const Char* password, User* user) {
- if (!password || !user) return 1;
- if (*password == 0) return 1;
+ if (!password || !user) return 0;
+ if (*password == 0) return 0;
kout << "user_fnv_generator: Hashing user password...\r";
@@ -50,7 +50,7 @@ namespace Detail {
kout << "user_fnv_generator: Hashed user password.\r";
- return 0;
+ return hash;
}
} // namespace Detail
diff --git a/dev/kernel/src/UserProcessTeam.cc b/dev/kernel/src/UserProcessTeam.cc
index dd21ac49..73ba7285 100644
--- a/dev/kernel/src/UserProcessTeam.cc
+++ b/dev/kernel/src/UserProcessTeam.cc
@@ -7,6 +7,7 @@
/***********************************************************************************/
/// @file UserProcessTeam.cc
/// @brief Process teams implementation.
+/// @author Amlal El Mahrouss (amlal@nekernel.org)
/***********************************************************************************/
#include <KernelKit/UserProcessScheduler.h>
diff --git a/dev/kernel/src/UtfUtils.cc b/dev/kernel/src/UtfUtils.cc
index ae17aed7..a5c03b85 100644
--- a/dev/kernel/src/UtfUtils.cc
+++ b/dev/kernel/src/UtfUtils.cc
@@ -6,6 +6,8 @@
#include <NeKit/Utils.h>
+/// @author Amlal El Mahrouss (amlal@nekernel.org)
+
namespace Kernel {
Size urt_string_len(const Utf8Char* str) {
SizeT len{0};
diff --git a/tooling/fsck.hefs.cc b/tooling/fsck.hefs.cc
index 0fa697be..950a709b 100644
--- a/tooling/fsck.hefs.cc
+++ b/tooling/fsck.hefs.cc
@@ -34,14 +34,20 @@ int main(int argc, char** argv) {
}
mkfs::hefs::BootNode boot_node;
+
std::memset(&boot_node, 0, sizeof(boot_node));
- if (strncmp(boot_node.magic, kHeFSMagic, kHeFSMagicLen) != 0) {
+ if (strncmp(boot_node.magic, kHeFSMagic, kHeFSMagicLen) != 0 || boot_node.sectorCount < 1 ||
+ boot_node.sectorSize < kMkFsSectorSz) {
mkfs::console_out() << "hefs: error: Device is not an HeFS disk: " << opt_disk << "\n";
return EXIT_FAILURE;
}
- mkfs::console_out() << "hefs: HeFS partition is is healthy, exiting...\r";
+ if (boot_node.badSectors >= kMkFsMaxBadSectors) {
+ mkfs::console_out() << "hefs: error: HeFS disk has too much bad sectors: " << opt_disk << "\n";
+ return EXIT_FAILURE;
+ }
+ mkfs::console_out() << "hefs: HeFS partition is is healthy, exiting...\r";
return EXIT_SUCCESS;
} \ No newline at end of file
diff --git a/tooling/libmkfs/mkfs.h b/tooling/libmkfs/mkfs.h
index d954624c..d87060da 100644
--- a/tooling/libmkfs/mkfs.h
+++ b/tooling/libmkfs/mkfs.h
@@ -10,6 +10,9 @@
#include <iostream>
#include <string>
+#define kMkFsSectorSz (512U)
+#define kMkFsMaxBadSectors (128U)
+
/// @internal
namespace mkfs {
diff --git a/tooling/mkfs.hefs.cc b/tooling/mkfs.hefs.cc
index c1cf9bca..3c2727fd 100644
--- a/tooling/mkfs.hefs.cc
+++ b/tooling/mkfs.hefs.cc
@@ -150,12 +150,16 @@ int main(int argc, char** argv) {
boot_node.magic[magic_copy] = 0;
constexpr size_t vol_slots = kHeFSPartNameLen;
+
std::memset(boot_node.volumeName, 0, sizeof(boot_node.volumeName));
+
size_t label_units = std::min(kLabel.size(), vol_slots - 1);
+
for (size_t i = 0; i < label_units; ++i) {
- boot_node.volumeName[i] = static_cast<char16_t>(kLabel[i]);
+ boot_node.volumeName[i] = static_cast<char8_t>(kLabel[i]);
}
- boot_node.volumeName[label_units] = 0;
+
+ boot_node.volumeName[label_units] = 0U;
output_device.seekp(static_cast<std::streamoff>(start_ind));
if (!output_device.good()) {