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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
/* -------------------------------------------
Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
------------------------------------------- */
#pragma once
#include <CompilerKit/CompilerKit.h>
#include <hint/CompilerHint.h>
#include <KernelKit/DriveMgr.h>
#include <NewKit/Defines.h>
#include <NewKit/KString.h>
/// @file HeFS.h
/// @brief HeFS filesystem support.
#define kHeFSVersion (0x0100)
#define kHeFSMagic " HeFS"
#define kHeFSMagicLen (8)
#define kHeFSFileNameLen (256U)
#define kHeFSPartNameLen (128U)
#define kHeFSMinimumDiskSize (gib_cast(4))
struct HeFS_BOOT_NODE;
struct HeFS_INDEX_NODE;
struct HeFS_INDEX_NODE_DIRECTORY;
enum
{
kHeFSHardDrive = 0xC0, // Hard Drive
kHeFSSolidStateDrive = 0xC1, // Solid State Drive
kHeFSOpticalDrive = 0x0C, // Blu-Ray/DVD
kHeFSMassStorageDevice = 0xCC, // USB
kHeFSScsiDrive = 0xC4, // SCSI Hard Drive
kHeFSFlashDrive = 0xC6,
kHeFSUnknown = 0xFF, // Unknown device.
kHeFSDriveCount = 7,
};
enum
{
kHeFSStatusUnlocked = 0x18,
kHeFSStatusLocked,
kHeFSStatusError,
kHeFSStatusInvalid,
kHeFSStatusCount,
};
enum
{
kHeFSEncodingUTF8 = 0x00,
kHeFSEncodingUTF16,
kHeFSEncodingUTF32,
kHeFSEncodingUTF16BE,
kHeFSEncodingUTF16LE,
kHeFSEncodingUTF32BE,
kHeFSEncodingUTF32LE,
kHeFSEncodingUTF8BE,
kHeFSEncodingUTF8LE,
kHeFSEncodingCount,
};
inline constexpr UInt16 kHeFSFileKindRegular = 0x00;
inline constexpr UInt16 kHeFSFileKindDirectory = 0x01;
inline constexpr UInt16 kHeFSFileKindBlock = 0x02;
inline constexpr UInt16 kHeFSFileKindCharacter = 0x03;
inline constexpr UInt16 kHeFSFileKindFIFO = 0x04;
inline constexpr UInt16 kHeFSFileKindSocket = 0x05;
inline constexpr UInt16 kHeFSFileKindSymbolicLink = 0x06;
inline constexpr UInt16 kHeFSFileKindUnknown = 0x07;
inline constexpr UInt16 kHeFSFileKindCount = 0x08;
/// @brief HeFS blocks are array containing sparse blocks of data.
/// @details The blocks are used to store the data of a file. Each block is a pointer to a block of data on the disk.
inline constexpr UInt16 fHeFSBlockCount = 0x06;
struct PACKED HeFS_BOOT_NODE final
{
Kernel::Char fMagic[kHeFSMagicLen];
Kernel::Utf16Char fVolName[kHeFSPartNameLen];
Kernel::UInt32 fVersion;
Kernel::UInt64 fBadSectors;
Kernel::UInt64 fSectorCount;
Kernel::UInt64 fSectorSize;
Kernel::UInt32 fChecksum;
Kernel::UInt8 fDriveKind;
Kernel::UInt8 fEncoding;
Kernel::UInt64 fStartIND;
Kernel::UInt64 fEndIND;
Kernel::UInt64 fINodeCount;
Kernel::UInt64 fDiskSize;
Kernel::UInt16 fDiskStatus;
Kernel::UInt16 fDiskFlags;
Kernel::UInt16 fVID; // virtual identification number within an EPM disk.
};
/// @brief Access time type.
/// @details Used to keep track of the INode, INodeDir allocation status.
typedef Kernel::UInt64 ATime;
inline constexpr ATime kHeFSTimeInvalid = 0x0000000000000000;
inline constexpr ATime kHeFSTimeMax = 0xFFFFFFFFFFFFFFFF;
struct PACKED HeFS_INDEX_NODE final
{
Kernel::Utf16Char fName[kHeFSFileNameLen];
Kernel::UInt32 fFlags;
Kernel::UInt16 fKind;
Kernel::UInt32 fSize;
Kernel::UInt32 fChecksum;
ATime fCreated, fAccessed, fModified, fDeleted;
Kernel::UInt32 fUID, fGID;
Kernel::UInt32 fMode;
Kernel::UInt64 fBlockLinkStart[fHeFSBlockCount];
Kernel::UInt64 fBlockLinkEnd[fHeFSBlockCount];
Kernel::UInt64 fBlockStart[fHeFSBlockCount];
Kernel::UInt64 fBlockEnd[fHeFSBlockCount];
Kernel::UInt64 fBlockRecoveryStart[fHeFSBlockCount];
Kernel::UInt64 fBlockRecoveryEnd[fHeFSBlockCount];
/// @brief Red-black tree pointers.
Kernel::Lba fNext, fPrev, fChild, fParent;
};
struct PACKED HeFS_INDEX_NODE_DIRECTORY final
{
Kernel::Utf16Char fName[kHeFSFileNameLen];
Kernel::UInt32 fFlags;
Kernel::UInt16 fKind;
Kernel::UInt32 fSize;
Kernel::UInt32 fChecksum;
ATime fCreated, fAccessed, fModified, fDeleted;
Kernel::UInt32 fUID, fGID;
Kernel::UInt32 fMode;
Kernel::UInt64 fIndexNodeStart[fHeFSBlockCount];
Kernel::UInt64 fIndexNodeEnd[fHeFSBlockCount];
/// @brief Red-black tree pointers.
Kernel::Lba fNext, fPrev, fChild, fParent;
};
|