summaryrefslogtreecommitdiffhomepage
path: root/dev/kernel/src/Swap
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-03-26 17:02:24 +0100
committerAmlal El Mahrouss <amlal@nekernel.org>2025-03-26 17:02:24 +0100
commit6c09ce86367ef0729a25e58314eefc543aaa83b7 (patch)
tree6181305a9eac8976ebb06d0897b367269281749a /dev/kernel/src/Swap
parent3852d6115bcd5c9ad80451ffac2892d38f604333 (diff)
feat(kernel): SwapKit+kSwap variant type.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'dev/kernel/src/Swap')
-rw-r--r--dev/kernel/src/Swap/SwapDisk.cc67
1 files changed, 67 insertions, 0 deletions
diff --git a/dev/kernel/src/Swap/SwapDisk.cc b/dev/kernel/src/Swap/SwapDisk.cc
new file mode 100644
index 00000000..fbc63b2f
--- /dev/null
+++ b/dev/kernel/src/Swap/SwapDisk.cc
@@ -0,0 +1,67 @@
+/* -------------------------------------------
+
+ Copyright (C) 2024-2025 Amlal EL Mahrouss Labs, all rights reserved.
+
+------------------------------------------- */
+
+#include <SwapKit/SwapDisk.h>
+#include <KernelKit/FileMgr.h>
+
+namespace NeOS
+{
+ /***********************************************************************************/
+ /// @brief Write memory chunk onto disk.
+ /// @param fork_name The swap name to recognize this memory region.
+ /// @param fork_name_len length of fork name.
+ /// @param data the data packet.
+ /// @return Whether the swap was written to disk, or not.
+ /***********************************************************************************/
+ BOOL SwapDiskInterface::Write(const Char* fork_name, const SizeT fork_name_len, SWAP_DISK_HEADER* data)
+ {
+ if (!fork_name || !fork_name_len)
+ return NO;
+
+ if (*fork_name == 0)
+ return NO;
+
+ if (!data)
+ return NO;
+
+ FileStream file(kSwapPageFile, "wb");
+
+ auto ret = file.Write(fork_name, data, sizeof(SWAP_DISK_HEADER) + data->fBlobSz);
+
+ if (ret.Error())
+ return NO;
+
+ return YES;
+ }
+
+ /***********************************************************************************/
+ /// @brief Read memory chunk from disk.
+ /// @param fork_name The swap name to recognize this memory region.
+ /// @param fork_name_len length of fork name.
+ /// @param data the data packet length.
+ /// @return Whether the swap was fetched to disk, or not.
+ /***********************************************************************************/
+ SWAP_DISK_HEADER* SwapDiskInterface::Read(const Char* fork_name, const SizeT fork_name_len, const SizeT data_len)
+ {
+ if (!fork_name || !fork_name_len)
+ return nullptr;
+
+ if (*fork_name == 0)
+ return nullptr;
+
+ if (data_len > kSwapBlockMaxSize)
+ return nullptr;
+
+ if (data_len == 0)
+ return nullptr;
+
+ FileStream file(kSwapPageFile, "rb");
+
+ VoidPtr blob = file.Read(fork_name, sizeof(SWAP_DISK_HEADER) + data_len);
+
+ return reinterpret_cast<SWAP_DISK_HEADER*>(blob);
+ }
+} // namespace NeOS