-
Notifications
You must be signed in to change notification settings - Fork 0
/
HFSPlusFileOps.h
180 lines (159 loc) · 5.05 KB
/
HFSPlusFileOps.h
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
//
// Copyright (c) 2007-Present The PureDarwin Project.
// All rights reserved.
//
// @LICENSE_HEADER_START@
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// @LICENSE_HEADER_END@
//
//
// @FILE
// HfsPlusFileOps.h
// This file is the header for the HFS+ file operations
//
// @AUTHOR
// Created by Cliff Sekel for The PureDarwin Project github.com/PureDarwin
//
#ifndef HFSPLUS_FILE_OPS_H
#define HFSPLUS_FILE_OPS_H
#include <Uefi.h>
#include <Library/UefiLib.h>
#include <Library/DebugLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Protocol/BlockIo.h>
#include <Protocol/SimpleFileSystem.h>
#include <Guid/Gpt.h>
#define HFSPLUS_VOL_JOURNALED 0x00800000 // HFS+ Journaled attribute flag
#define HFSPLUS_SIGNATURE 0x482B // The HFS+ signature ('H+' in ASCII)
#define HFSPLUS_BOOT_FOLDER_ID 0x00000002 // Example folder ID for the boot directory
// Structures for HFS+ extents, catalog keys, volume header, and journal info
typedef struct HFSPlusExtentDescriptor {
UINT32 startBlock;
UINT32 blockCount;
} HFSPlusExtentDescriptor;
typedef struct HFSPlusForkData {
UINT64 logicalSize;
UINT32 clumpSize;
UINT32 totalBlocks;
HFSPlusExtentDescriptor extents[8];
} HFSPlusForkData;
typedef struct HFSPlusCatalogKey {
UINT16 keyLength;
UINT32 parentID;
// Variable-length file/folder name follows
} HFSPlusCatalogKey;
typedef struct BTNodeDescriptor {
UINT32 fLink;
UINT32 bLink;
UINT8 kind;
UINT8 height;
UINT16 numRecords;
UINT16 reserved;
} BTNodeDescriptor;
typedef struct HFSPlusVolumeHeader {
UINT16 signature;
UINT32 attributes;
UINT32 journalInfoBlock;
HFSPlusForkData catalogFile;
HFSPlusForkData allocationFile;
// Additional fields omitted for brevity
} HFSPlusVolumeHeader;
typedef struct HFSPlusJournalInfoBlock {
UINT64 offset;
UINT64 size;
} HFSPlusJournalInfoBlock;
// Function declarations for file system and journal operations
EFI_STATUS WriteFileWithFragmentation(
EFI_HANDLE ImageHandle,
EFI_BLOCK_IO_PROTOCOL *BlockIo,
HFSPlusForkData *ForkData,
UINT32 TotalBlocks,
VOID *Data,
UINT64 DataSize,
HFSPlusForkData *AllocationFile,
HFSPlusForkData *ExtentOverflowFile
);
EFI_STATUS ReadFileWithFragmentation(
EFI_HANDLE ImageHandle,
EFI_BLOCK_IO_PROTOCOL *BlockIo,
HFSPlusForkData *ForkData,
UINT32 TotalBlocks,
VOID **FileData,
HFSPlusForkData *ExtentOverflowFile
);
EFI_STATUS DetectHfsPlusPartitions(
EFI_BLOCK_IO_PROTOCOL **BlockIoProtocol,
UINTN *HfsPartitionCount
);
EFI_STATUS MountHfsPlusVolume(
EFI_BLOCK_IO_PROTOCOL *BlockIo,
HFSPlusForkData *CatalogFile,
HFSPlusForkData *AllocationFile,
BOOLEAN *IsJournaled
);
EFI_STATUS FindAndLoadBootEfi(
EFI_BLOCK_IO_PROTOCOL *BlockIo
);
EFI_STATUS LoadBootEfi(
EFI_BLOCK_IO_PROTOCOL *BlockIo,
HFSPlusForkData *CatalogFile,
HFSPlusForkData *AllocationFile,
VOID **BootEfiData
);
EFI_STATUS TraverseCatalogBTree(
EFI_BLOCK_IO_PROTOCOL *BlockIo,
HFSPlusForkData *CatalogFile,
UINT32 ParentFolderID,
CHAR16 *FileName,
VOID **CatalogRecord
);
EFI_STATUS TraverseBTreeNodeRecursively(
EFI_BLOCK_IO_PROTOCOL *BlockIo,
HFSPlusForkData *CatalogFile,
UINT8 *NodeBuffer,
UINT32 ParentFolderID,
CHAR16 *FileName,
VOID **CatalogRecord
);
EFI_STATUS SearchIndexNodeAndRecurse(
EFI_BLOCK_IO_PROTOCOL *BlockIo,
HFSPlusForkData *CatalogFile,
UINT8 *NodeBuffer,
UINT32 ParentFolderID,
CHAR16 *FileName,
VOID **CatalogRecord
);
EFI_STATUS SearchLeafNodeForFile(
EFI_BLOCK_IO_PROTOCOL *BlockIo,
UINT8 *NodeBuffer,
UINT32 ParentFolderID,
CHAR16 *FileName,
VOID **CatalogRecord
);
BTNodeDescriptor *GetChildNode(
EFI_BLOCK_IO_PROTOCOL *BlockIo,
HFSPlusForkData *CatalogFile,
HFSPlusCatalogKey *CatalogKey
);
#endif // HFSPLUS_FILE_OPS_H