summaryrefslogtreecommitdiffhomepage
path: root/dev/kernel/src/IFS.cc
blob: e975750acaca8f296a7b2f33ace795ef65cbbd3a (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
/* -------------------------------------------

  Copyright (C) 2024-2025, Amlal El Mahrouss, licensed under the Apache 2.0 license.

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

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

/*************************************************************
 *
 * File: IFS.cc
 * Purpose: Filesystem to mountpoint interface.
 * Date: 05/26/2025
 *
 * Copyright (C) 2024-2025, Amlal El Mahrouss, licensed under the Apache 2.0 license.
 *
 *************************************************************/

/// Useful macros regarding the IFS.

#define fsi_ifs_write(DRV, TRAITS, MP) (MP->DRV()).fOutput(TRAITS)
#define fsi_ifs_read(DRV, TRAITS, MP) (MP->DRV()).fInput(TRAITS)

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

  DrvTrait.fPacket.fPacketGood = false;

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

  return DrvTrait.fPacket.fPacketGood ? kErrorSuccess : kErrorDisk;
}

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

  DrvTrait.fPacket.fPacketGood = false;

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

  return DrvTrait.fPacket.fPacketGood ? kErrorSuccess : kErrorDisk;
}
}  // namespace Kernel