summaryrefslogtreecommitdiffhomepage
path: root/dev/kernel/src/DriveMgr+IO.cc
blob: d46c2a9a0dd0147a510b1929d2239dc16ec068cb (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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/* -------------------------------------------

	Copyright (C) 2024-2025, Amlal EL Mahrouss, all rights reserved.

------------------------------------------- */

#include <KernelKit/DriveMgr.h>
#include <KernelKit/FileMgr.h>

/*************************************************************
 *
 * File: DriveMgr+IO.cc
 * Purpose: Filesystem to mountpoint interface.
 * Date: 3/26/24
 *
 * Copyright (C) 2024-2025, Amlal EL Mahrouss, all rights reserved.
 *
 *************************************************************/

/// Useful macros.

#define rtl_nefs_write(DRV, TRAITS, MP) (MP->DRV()).fOutput(TRAITS)
#define rtl_nefs_read(DRV, TRAITS, MP)	(MP->DRV()).fInput(TRAITS)

namespace Kernel
{
	/// @brief Read from newfs disk.
	/// @param Mnt mounted interface.
	/// @param DrvTrait drive info
	/// @param DrvIndex drive index.
	/// @return
	Int32 fs_ifs_read(MountpointInterface* Mnt, DriveTrait& DrvTrait, Int32 DrvIndex)
	{
		if (!Mnt)
			return 1;

		DrvTrait.fPacket.fPacketGood = false;

		switch (DrvIndex)
		{
		case MountpointInterface::kDriveIndexA: {
			rtl_nefs_read(A, DrvTrait.fPacket, Mnt);
			break;
		}
		case MountpointInterface::kDriveIndexB: {
			rtl_nefs_read(B, DrvTrait.fPacket, Mnt);
			break;
		}
		case MountpointInterface::kDriveIndexC: {
			rtl_nefs_read(C, DrvTrait.fPacket, Mnt);
			break;
		}
		case MountpointInterface::kDriveIndexD: {
			rtl_nefs_read(D, DrvTrait.fPacket, Mnt);
			break;
		}
		}

		return DrvTrait.fPacket.fPacketGood;
	}

	/// @brief Write to newfs disk.
	/// @param Mnt mounted interface.
	/// @param DrvTrait drive info
	/// @param DrvIndex drive index.
	/// @return
	Int32 fs_ifs_write(MountpointInterface* Mnt, DriveTrait& DrvTrait, Int32 DrvIndex)
	{
		if (!Mnt)
			return 1;

		DrvTrait.fPacket.fPacketGood = false;

		switch (DrvIndex)
		{
		case MountpointInterface::kDriveIndexA: {
			rtl_nefs_write(A, DrvTrait.fPacket, Mnt);
			break;
		}
		case MountpointInterface::kDriveIndexB: {
			rtl_nefs_write(B, DrvTrait.fPacket, Mnt);
			break;
		}
		case MountpointInterface::kDriveIndexC: {
			rtl_nefs_write(C, DrvTrait.fPacket, Mnt);
			break;
		}
		case MountpointInterface::kDriveIndexD: {
			rtl_nefs_write(D, DrvTrait.fPacket, Mnt);
			break;
		}
		}

		return DrvTrait.fPacket.fPacketGood;
	}
} // namespace Kernel