summaryrefslogtreecommitdiffhomepage
path: root/dev/kernel/src
diff options
context:
space:
mode:
Diffstat (limited to 'dev/kernel/src')
-rw-r--r--dev/kernel/src/Swap/SwapDisk.cc67
-rw-r--r--dev/kernel/src/System/SwapDisk.cc53
-rw-r--r--dev/kernel/src/Variant.cc2
3 files changed, 69 insertions, 53 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
diff --git a/dev/kernel/src/System/SwapDisk.cc b/dev/kernel/src/System/SwapDisk.cc
deleted file mode 100644
index 80c75684..00000000
--- a/dev/kernel/src/System/SwapDisk.cc
+++ /dev/null
@@ -1,53 +0,0 @@
-/* -------------------------------------------
-
- Copyright (C) 2024-2025 Amlal EL Mahrouss Labs, all rights reserved.
-
-------------------------------------------- */
-
-#include <SystemKit/SwapDisk.h>
-#include <KernelKit/FileMgr.h>
-
-namespace NeOS
-{
- BOOL SwapDisk::Write(const Char* fork_name, const SizeT fork_name_len, SWAP_DISK_HEADER* data, const SizeT data_len)
- {
- if (!fork_name || !fork_name_len)
- return NO;
-
- if (*fork_name == 0)
- return NO;
-
- if (data_len > kSwapBlockMaxSize)
- return NO;
-
- if (!data)
- return NO;
-
- FileStream file(kSwapPageFile, "wb");
-
- auto ret = file.Write(fork_name, data, sizeof(SWAP_DISK_HEADER) + data_len);
-
- if (ret.Error())
- return NO;
-
- return YES;
- }
-
- SWAP_DISK_HEADER* SwapDisk::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;
-
- FileStream file(kSwapPageFile, "rb");
-
- VoidPtr blob = file.Read(fork_name, sizeof(SWAP_DISK_HEADER) + data_len);
-
- return (SWAP_DISK_HEADER*)blob;
- }
-} // namespace NeOS
diff --git a/dev/kernel/src/Variant.cc b/dev/kernel/src/Variant.cc
index cfa29d3a..7b4b0389 100644
--- a/dev/kernel/src/Variant.cc
+++ b/dev/kernel/src/Variant.cc
@@ -22,6 +22,8 @@ namespace NeOS
return ("Class:{Blob}");
case VariantKind::kNull:
return ("Class:{Null}");
+ case VariantKind::kSwap:
+ return ("Class:{Swap}");
default:
return ("Class:{Unknown}");
}