summaryrefslogtreecommitdiffhomepage
path: root/tooling/hefs.h
blob: 68e0f906550c4a33fcfeab5de8b62a46a13af0e5 (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
97
98
99
100
101
102
103
104
105
106
107
108
109
/* -------------------------------------------

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

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

#pragma once

#include <cstdint>
#include <cstring>

#define kHeFSVersion (0x0101)
#define kHeFSMagic "  HeFS"
#define kHeFSMagicLen (8)

#define kHeFSFileNameLen (256U)
#define kHeFSPartNameLen (128U)

#define kHeFSDefaultVolumeName u8"HeFS Volume"

namespace mkfs::hefs {

// Drive kinds
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,
};

// Disk status
enum {
  kHeFSStatusUnlocked = 0x18,
  kHeFSStatusLocked,
  kHeFSStatusError,
  kHeFSStatusInvalid,
  kHeFSStatusCount,
};

// Encodings
enum {
  kHeFSEncodingFlagsUTF8 = 0x00,
  kHeFSEncodingFlagsUTF16,
  kHeFSEncodingFlagsUTF32,
  kHeFSEncodingFlagsUTF16BE,
  kHeFSEncodingFlagsUTF16LE,
  kHeFSEncodingFlagsUTF32BE,
  kHeFSEncodingFlagsUTF32LE,
  kHeFSEncodingFlagsUTF8BE,
  kHeFSEncodingFlagsUTF8LE,
  kHeFSEncodingFlagsBinary,
  kHeFSEncodingFlagsCount,
};

// Time type
using ATime = std::uint64_t;

// File kinds
inline constexpr uint16_t kHeFSFileKindRegular      = 0x00;
inline constexpr uint16_t kHeFSFileKindDirectory    = 0x01;
inline constexpr uint16_t kHeFSFileKindBlock        = 0x02;
inline constexpr uint16_t kHeFSFileKindCharacter    = 0x03;
inline constexpr uint16_t kHeFSFileKindFIFO         = 0x04;
inline constexpr uint16_t kHeFSFileKindSocket       = 0x05;
inline constexpr uint16_t kHeFSFileKindSymbolicLink = 0x06;
inline constexpr uint16_t kHeFSFileKindUnknown      = 0x07;
inline constexpr uint16_t kHeFSFileKindCount        = 0x08;

// Red-black tree colors
enum {
  kHeFSInvalidColor = 0,
  kHeFSRed          = 100,
  kHeFSBlack,
  kHeFSColorCount,
};

// Time constants
inline constexpr ATime kHeFSTimeInvalid = 0x0000000000000000;
inline constexpr ATime kHeFSTimeMax     = 0xFFFFFFFFFFFFFFFF - 1;

// Boot Node
struct __attribute__((packed)) BootNode {
  char          magic[kHeFSMagicLen]{};
  char8_t       volumeName[kHeFSPartNameLen]{};
  std::uint32_t version{};
  std::uint64_t badSectors{};
  std::uint64_t sectorCount{};
  std::uint64_t sectorSize{};
  std::uint32_t checksum{};
  std::uint8_t  diskKind{};
  std::uint8_t  encoding{};
  std::uint64_t startIND{};
  std::uint64_t endIND{};
  std::uint64_t indCount{};
  std::uint64_t diskSize{};
  std::uint16_t diskStatus{};
  std::uint16_t diskFlags{};
  std::uint16_t vid{};
  std::uint64_t startIN{};
  std::uint64_t endIN{};
  std::uint64_t startBlock{};
  std::uint64_t endBlock{};
  char          pad[272]{};
};
}  // namespace mkfs::hefs