OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
fsw_hfsplus.h
Go to the documentation of this file.
1
17#ifndef _FSW_HFSPLUS_H_
18#define _FSW_HFSPLUS_H_
19
20#define VOLSTRUCTNAME fsw_hfsplus_volume
21#define DNODESTRUCTNAME fsw_hfsplus_dnode
22
23/* Let debug messages be printed */
24//#define FSW_DEBUG_LEVEL 2
25
26#include "fsw_core.h"
27
28/*============= HFS+ constants and data types from Apple TN1150 =============*/
29#pragma pack(1)
30
31#define kHFSBlockSize 512 // Minimum block size to transfer Vol.Hdr.
32#define kMasterDirectoryBlock 2 // Vol.Hdr. disk offset (x kHFSBlockSize)
33
34#define kHFSPlusSigWord 0x482B // HFS+ volume signature (ASCII for 'H+')
35
36#define kHFSPlusMaxFileNameChars 255 // Max. length of HFS+ folder or filename
37
38#define kHFSPlusExtentDensity 8 // Number of extent descriptors per record
39
40#define kHFSPlusDataFork 0x00 // data fork type
41#define kHFSPlusResourceFork 0xFF // resource fork type
42
43#define kHFSRootParentID 1 // Parent ID of the root folder
44#define kHFSRootFolderID 2 // ID of the root folder
45#define kHFSExtentsFileID 3 // ID of the extent overflow file
46#define kHFSCatalogFileID 4 // ID of the catalog file
47#define kHFSBadBlockFileID 5 // ID of the bad block file
48#define kHFSAllocationFileID 6 // ID of the allocation file
49#define kHFSStartupFileID 7 // ID of the startup file
50#define kHFSAttributesFileID 8 // ID of the attributes file
51#define kHFSRepairCatalogFileID 14 // Used temporarily when rebuilding Catalog B-tree
52#define kHFSBogusExtentFileID 15 // Used temporarily during ExchangeFiles operations
53#define kHFSFirstUserCatalogNodeID 16 // First CNID available for use by user files and folders
54
55#define kHFSPlusFolderRecord 1 // catalog folder record type
56#define kHFSPlusFileRecord 2 // catalog file record type
57#define kHFSPlusFolderThreadRecord 3 // catalog folder thread record type
58#define kHFSPlusFileThreadRecord 4 // catalog file thread record type
59
60#define kHFSPlusHFSPlusCreator 0x6866732B // 'hfs+'
61#define kHFSPlusSymlinkCreator 0x72686170 //'rhap'
62
63#define kHFSPlusHardlinkType 0x686C6E6B // 'hlnk'
64#define kHFSPlusSymlinkType 0x736C6E6B // 'slnk'
65
66#define kBTLeafNode -1 // B-Tree leaf node type
67#define kBTIndexNode 0 // B-Tree index node type
68#define kBTHeaderNode 1 // B-Tree header node type
69
70// file/folder name unicode string type
71typedef struct {
72 fsw_u16 length; // character count
73 fsw_u16 unicode[kHFSPlusMaxFileNameChars]; // character string
75
76// extent descriptor type
77typedef struct {
78 fsw_u32 startBlock; // first allocation block in the extent
79 fsw_u32 blockCount; // extent length, in allocation blocks
81
82// extent record type
84
85// fork-data information type
86typedef struct {
87 fsw_u64 logicalSize; // size of valid fork data, in bytes
88 fsw_u32 clumpSize; // fork-specific clump size
89 fsw_u32 totalBlocks; // total blocks across all extents in fork
90 HFSPlusExtentRecord extents; // initial extents for the fork data
92
93// volume header type
94typedef struct {
95 fsw_u16 signature; // should be kHFSPlusSigWord
96 fsw_u16 version; // should be kHFSPlusVersion
97 fsw_u32 attributes; // volume attributes
98 fsw_u32 lastMountedVersion; // unique ID of software that last wrote volume
99 fsw_u32 journalInfoBlock; // block no. of journal info
100 fsw_u32 createDate; // volume creation timestamp (date and time)
101 fsw_u32 modifyDate; // volume last modification timestamp
102 fsw_u32 backupDate; // timestamp of last backup
103 fsw_u32 checkedDate; // timestamp of last consistency check
104 fsw_u32 fileCount; // total number of files on volume
105 fsw_u32 folderCount; // total number of folders on volume
106 fsw_u32 blockSize; // allocation block size, in bytes
107 fsw_u32 totalBlocks; // total number of allocation blocks
108 fsw_u32 freeBlocks; // total number of unused allocation blocks
109 fsw_u32 nextAllocation; // block number to start next allocation search
110 fsw_u32 rsrcClumpSize; // dflt. resource fork clump size (in bytes)
111 fsw_u32 dataClumpSize; // dflt. data fork clump size (in bytes)
112 fsw_u32 nextCatalogID; // next unused catalog ID
113 fsw_u32 writeCount; // incr. each time volume is write-mounted
114 fsw_u64 encodingsBitmap; // keep track of text encodings used in names
115 fsw_u8 finderInfo[32]; // information used by the OS X Finder
116 HFSPlusForkData allocationFile; // info re. size & location of alloc. file
117 HFSPlusForkData extentsFile; // info re. size & location of extents file
118 HFSPlusForkData catalogFile; // info re. size & location of catalog file
119 HFSPlusForkData attributesFile; // info re. size & location of attr. file
120 HFSPlusForkData startupFile; // info re. size & location of startup file
122
123// file permissions type
124typedef struct {
125 fsw_u32 ownerID; // owner UID (or hard-link previous-link)
126 fsw_u32 groupID; // owner GID (or hard-link next-link)
127 fsw_u8 adminFlags; // flags changeable by root only
128 fsw_u8 ownerFlags; // flags changeable by owner
129 fsw_u16 fileMode; // BSD file type and mode bits
130 union {
131 fsw_u32 iNodeNum; // link reference number, if hard-link
132 fsw_u32 linkCount; // ref-count of hard-links, if indirect node file
133 fsw_u32 rawDevice; // device number, if block/char special dev. file
134 } special; // reserved for directories and most files
136
137// finder info types
138typedef struct {
139 fsw_u32 fdType; // file type
140 fsw_u32 fdCreator; // file creator
141 fsw_u16 fdFlags; // Finder flags
142 struct {
143 fsw_u16 v; // file's location
145 } fdLocation;
148
149typedef struct {
150 struct { // folder's window rectangle
155 } frRect;
156 unsigned short frFlags; // Finder flags
157 struct {
158 fsw_u16 v; // folder's location
160 } frLocation;
163
164typedef struct {
165 fsw_u8 opaque[16];
167
168// catalog folder record type
169typedef struct {
170 fsw_s16 recordType; // should be kHFSPlusFolderRecord
171 fsw_u16 flags; // bit flags about the folder (reserved)
172 fsw_u32 valence; // items directly contained by this folder
173 fsw_u32 folderID; // CNID of this folder
174 fsw_u32 createDate; // folder creation timestamp (date and time)
175 fsw_u32 contentModDate; // folder content last modification timestamp
176 fsw_u32 attributeModDate; // ctime (last change to a catalog record field)
177 fsw_u32 accessDate; // atime (last access timestamp)
178 fsw_u32 backupDate; // timestamp of last backup
179 HFSPlusBSDInfo permissions; // folder permissions
180 FndrDirInfo userInfo; // information used by the OS X Finder
181 FndrOpaqueInfo finderInfo; // additional information for the OS X Finder
182 fsw_u32 textEncoding; // hint re. folder name text encoding
183 fsw_u32 reserved; // reserved field
185
186// catalog file record type
187typedef struct {
188 fsw_s16 recordType; // should be kHFSPlusFileRecord
189 fsw_u16 flags; // bit flags about the file (reserved)
190 fsw_u32 reserved1; // reserved field
191 fsw_u32 fileID; // CNID of this file
192 fsw_u32 createDate; // file creation timestamp (date and time)
193 fsw_u32 contentModDate; // file content last modification timestamp
194 fsw_u32 attributeModDate; // ctime (last change to a catalog record field)
195 fsw_u32 accessDate; // atime (last access timestamp)
196 fsw_u32 backupDate; // timestamp of last backup
197 HFSPlusBSDInfo permissions; // file permissions
198 FndrFileInfo userInfo; // information used by the OS X Finder
199 FndrOpaqueInfo finderInfo; // additional information for the OS X Finder
200 fsw_u32 textEncoding; // hint re. file name text encoding
201 fsw_u32 reserved2; // reserved field
202 HFSPlusForkData dataFork; // info re. size & location of data fork
203 HFSPlusForkData resourceFork; // info re. size & location of resource fork
205
206// catalog thread record type
207typedef struct {
208 fsw_s16 recordType; // should be kHFSPlus[Folder|File]ThreadRecord
209 fsw_u16 reserved; // reserved field
210 fsw_u32 parentID; // CNID of this record's parent
211 HFSUniStr255 nodeName; // basename of file or folder
213
214// generic (union) catalog record type
215typedef union {
216 fsw_s16 recordType; // kHFSPlus[Folder|File][Thread]Record
217 HFSPlusCatalogFolder folderRecord; // catalog folder record fields
218 HFSPlusCatalogFile fileRecord; // catalog file record fields
219 HFSPlusCatalogThread threadRecord; // catalog thread record fields
221
222// B-Tree node descriptor found at the start of each node
223typedef struct {
224 fsw_u32 fLink; // number of next node of this type (0 if we're last)
225 fsw_u32 bLink; // number of prev. node of this type (0 if we're first)
226 fsw_s8 kind; // node type (leaf, index, header, map)
227 fsw_u8 height; // node depth in B-Tree hierarchy (0 for header)
228 fsw_u16 numRecords; // number of records contained in this node
229 fsw_u16 reserved; // reserved field
231
232// B-Tree header record type (first record of a B-Tree header node)
233typedef struct {
234 fsw_u16 treeDepth; // current B-Tree depth (always == rootNode.height)
235 fsw_u32 rootNode; // node number of B-Tree root node
236 fsw_u32 leafRecords; // total number of records across all leaf nodes
237 fsw_u32 firstLeafNode; // node number of first leaf node
238 fsw_u32 lastLeafNode; // node number of last leaf node
239 fsw_u16 nodeSize; // node size (in bytes)
240 fsw_u16 maxKeyLength; // max. length of a key in index/leaf node
241 fsw_u32 totalNodes; // total number of nodes in the B-Tree
242 fsw_u32 freeNodes; // number of unused nodes in the B-Tree
243 fsw_u16 reserved1; // reserved field
244 fsw_u32 clumpSize; // reserved field (deprecated)
245 fsw_u8 btreeType; // reserved (0 for catalog, extents, attrib. file)
246 fsw_u8 keyCompareType; // case-sensitive string comparison (HFSX only)
247 fsw_u32 attributes; // B-Tree attributes
248 fsw_u32 reserved3[16]; // reserved field
250
251// extent overflow file key type
252typedef struct {
253 fsw_u16 keyLength; // key length (excluding this field)
254 fsw_u8 forkType; // data or resource fork
255 fsw_u8 pad; // ensure 32-bit alignment for subsequent fields
256 fsw_u32 fileID; // CNID of file to which this extent record applies
257 fsw_u32 startBlock; // start block of first extent described by this record
259
260// catalog file key type
261typedef struct {
262 fsw_u16 keyLength; // key length (excluding this field)
263 fsw_u32 parentID; // ID of parent folder (or CNID if thread record)
264 HFSUniStr255 nodeName; // basename of file or folder
266
267// generic (union) B-Tree record key type
268typedef union {
269 fsw_u16 keyLength; // key length (excluding this field)
270 HFSPlusExtentKey extKey; // extent key fields
271 HFSPlusCatalogKey catKey; // catalog key fields
273
274typedef struct {
275 fsw_u32 blessedSystemFolderID; // for OpenFirmware systems
276 fsw_u32 blessedSystemFileID; // for EFI systems
277 fsw_u32 openWindowFolderID; // deprecated, first link in linked list of folders to open at mount
278 fsw_u32 blessedAlternateOSID; // currently used for FV2 recovery, inaccessible from UEFI
279 fsw_u32 unused; // formerly PowerTalk Inbox
280 fsw_u32 blessedOSXFolderID; // currently used for normal recovery
283
284#pragma pack()
285/*========= end HFS+ constants and data types from Apple TN1150 =============*/
286
287/* FSW: key comparison procedure type */
289
290// FSW: HFS+ specific dnode
292 struct fsw_dnode g; // Generic (parent) dnode structure
293 fsw_u32 ct, mt, at; // HFS+ create/modify/access timestamps
294 HFSPlusExtentRecord extents; // HFS+ initial extent record
295 fsw_u32 bt_root; // root node index (if B-Tree file)
296 fsw_u16 bt_ndsz; // node size (if B-Tree file)
297
298 // Links stuff
302
303 fsw_u32 parent_id; // parent id used by dnode_fill()
304};
305
306
307// FSW: HFS+ specific volume
309 struct fsw_volume g; // Generic (parent) volume structure
310 HFSPlusVolumeHeader *vh; // Raw HFS+ Volume Header
311 struct fsw_hfsplus_dnode *catf; // Catalog file dnode
312};
313
314#endif // _FSW_HFSPLUS_H_
UINT16 fsw_u16
INT8 fsw_s8
UINT32 fsw_u32
INT16 fsw_s16
UINT64 fsw_u64
UINT8 fsw_u8
int(* k_cmp_t)(HFSPlusBTKey *, HFSPlusBTKey *)
HFSPlusExtentDescriptor HFSPlusExtentRecord[kHFSPlusExtentDensity]
Definition fsw_hfsplus.h:83
#define kHFSPlusExtentDensity
Definition fsw_hfsplus.h:38
#define kHFSPlusMaxFileNameChars
Definition fsw_hfsplus.h:36
fsw_u32 firstLeafNode
fsw_u16 treeDepth
fsw_u16 nodeSize
fsw_u8 keyCompareType
fsw_u32 rootNode
fsw_u16 maxKeyLength
fsw_u32 lastLeafNode
fsw_u8 btreeType
fsw_u16 reserved1
fsw_u32 attributes
fsw_u32 totalNodes
fsw_u32 clumpSize
fsw_u32 leafRecords
fsw_u32 freeNodes
fsw_u16 top
fsw_u16 bottom
fsw_u16 left
fsw_u16 opaque
fsw_u16 right
unsigned short frFlags
fsw_u32 fdCreator
fsw_u32 fdType
fsw_u16 fdFlags
fsw_u16 opaque
fsw_u32 linkCount
fsw_u32 rawDevice
HFSPlusBSDInfo permissions
HFSPlusForkData resourceFork
FndrFileInfo userInfo
FndrOpaqueInfo finderInfo
HFSPlusForkData dataFork
HFSPlusBSDInfo permissions
FndrOpaqueInfo finderInfo
HFSUniStr255 nodeName
HFSUniStr255 nodeName
HFSPlusExtentRecord extents
Definition fsw_hfsplus.h:90
fsw_u64 logicalSize
Definition fsw_hfsplus.h:87
fsw_u32 totalBlocks
Definition fsw_hfsplus.h:89
fsw_u32 clumpSize
Definition fsw_hfsplus.h:88
HFSPlusForkData startupFile
HFSPlusForkData allocationFile
fsw_u32 lastMountedVersion
Definition fsw_hfsplus.h:98
HFSPlusForkData catalogFile
HFSPlusForkData extentsFile
HFSPlusForkData attributesFile
fsw_u16 length
Definition fsw_hfsplus.h:72
struct fsw_dnode g
HFSPlusExtentRecord extents
struct fsw_volume g
HFSPlusVolumeHeader * vh
struct fsw_hfsplus_dnode * catf
HFSPlusExtentKey extKey
fsw_u16 keyLength
HFSPlusCatalogKey catKey
HFSPlusCatalogFolder folderRecord
HFSPlusCatalogThread threadRecord
HFSPlusCatalogFile fileRecord