blob: 8578450c1c97b66c2f17fc2194949c76d75dd557 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
/* -------------------------------------------
Copyright (C) 2024-2025 Amlal El Mahrouss , all rights reserved.
------------------------------------------- */
#include <KernelKit/FileMgr.h>
#include <SwapKit/DiskSwap.h>
namespace Kernel {
/***********************************************************************************/
/// @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 DiskSwapInterface::Write(const Char* fork_name, 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(kSwapPageFilePath, kRestrictWRB);
ErrorOr<Int64> 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* DiskSwapInterface::Read(const Char* fork_name, SizeT fork_name_len,
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(kSwapPageFilePath, kRestrictRB);
VoidPtr blob = file.Read(fork_name, sizeof(SWAP_DISK_HEADER) + data_len);
return reinterpret_cast<SWAP_DISK_HEADER*>(blob);
}
} // namespace Kernel
|