OpenCore  1.0.4
OpenCore Bootloader
1.0.4
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Apfs.h
Go to the documentation of this file.
1
15#ifndef APFS_H
16#define APFS_H
17
18//
19// APFS object types.
20//
21#define APFS_OBJECT_TYPE_NX_SUPERBLOCK 0x00000001U
22#define APFS_OBJECT_TYPE_BTREE 0x00000002U
23#define APFS_OBJECT_TYPE_BTREE_NODE 0x00000003U
24#define APFS_OBJECT_TYPE_SPACEMAN 0x00000005U
25#define APFS_OBJECT_TYPE_SPACEMAN_CAB 0x00000006U
26#define APFS_OBJECT_TYPE_SPACEMAN_CIB 0x00000007U
27#define APFS_OBJECT_TYPE_SPACEMAN_BITMAP 0x00000008U
28#define APFS_OBJECT_TYPE_SPACEMAN_FREE_QUEUE 0x00000009U
29#define APFS_OBJECT_TYPE_EXTENT_LIST_TREE 0x0000000aU
30#define APFS_OBJECT_TYPE_OMAP 0x0000000bU
31#define APFS_OBJECT_TYPE_CHECKPOINT_MAP 0x0000000cU
32#define APFS_OBJECT_TYPE_FS 0x0000000dU
33#define APFS_OBJECT_TYPE_FSTREE 0x0000000eU
34#define APFS_OBJECT_TYPE_BLOCKREFTREE 0x0000000fU
35#define APFS_OBJECT_TYPE_SNAPMETATREE 0x00000010U
36#define APFS_OBJECT_TYPE_NX_REAPER 0x00000011U
37#define APFS_OBJECT_TYPE_NX_REAP_LIST 0x00000012U
38#define APFS_OBJECT_TYPE_OMAP_SNAPSHOT 0x00000013U
39#define APFS_OBJECT_TYPE_EFI_JUMPSTART 0x00000014U
40#define APFS_OBJECT_TYPE_FUSION_MIDDLE_TREE 0x00000015U
41#define APFS_OBJECT_TYPE_NX_FUSION_WBC 0x00000016U
42#define APFS_OBJECT_TYPE_NX_FUSION_WBC_LIST 0x00000017U
43#define APFS_OBJECT_TYPE_ER_STATE 0x00000018U
44#define APFS_OBJECT_TYPE_GBITMAP 0x00000019U
45#define APFS_OBJECT_TYPE_GBITMAP_TREE 0x0000001aU
46#define APFS_OBJECT_TYPE_GBITMAP_BLOCK 0x0000001bU
47#define APFS_OBJECT_TYPE_INVALID 0x00000000U
48#define APFS_OBJECT_TYPE_TEST 0x000000ffU
49
50//
51// APFS object flags.
52//
53#define APFS_OBJ_VIRTUAL 0x00000000U
54#define APFS_OBJ_EPHEMERAL 0x80000000U
55#define APFS_OBJ_PHYSICAL 0x40000000U
56#define APFS_OBJ_NOHEADER 0x20000000U
57#define APFS_OBJ_ENCRYPTED 0x10000000U
58#define APFS_OBJ_NONPERSISTENT 0x08000000U
59
60//
61// Container Superblock definitions
62//
63#define APFS_NX_SIGNATURE SIGNATURE_32 ('N', 'X', 'S', 'B')
64#define APFS_NX_MAX_FILE_SYSTEMS 100
65#define APFS_NX_EPH_INFO_COUNT 4
66#define APFS_NX_EPH_MIN_BLOCK_COUNT 8
67#define APFS_NX_MAX_FILE_SYSTEM_EPH_STRUCTS 4
68#define APFS_NX_TX_MIN_CHECKPOINT_COUNT 4
69#define APFS_NX_EPH_INFO_VERSION_1 1
70#define APFS_NX_NUM_COUNTERS 32
71#define APFS_NX_MINIMUM_BLOCK_SIZE BASE_4KB
72#define APFS_NX_DEFAULT_BLOCK_SIZE BASE_4KB
73#define APFS_NX_MAXIMUM_BLOCK_SIZE BASE_64KB
74
75//
76// EfiBootRecord block definitions
77//
78#define APFS_NX_EFI_JUMPSTART_MAGIC SIGNATURE_32 ('J', 'S', 'D', 'R')
79#define APFS_NX_EFI_JUMPSTART_VERSION 1
80
81#define APFS_MAX_HIST 8
82#define APFS_MODIFIED_NAMELEN 32
83#define APFS_VOLNAME_LEN 256
84
85//
86// Fusion things
87//
88#define APFS_FUSION_TIER2_DEVICE_BYTE_ADDR 0x4000000000000000ULL
89
90//
91// Driver version
92//
93#define APFS_DRIVER_VERSION_MAGIC SIGNATURE_32 ('A', 'P', 'F', 'S')
94
95#pragma pack(push, 1)
96
100typedef struct APFS_DRIVER_VERSION_ {
104 UINT32 Magic;
112 UINT64 Version;
116 CHAR8 Date[16];
120 CHAR8 Time[16];
122
130
144
148typedef struct {
150 UINT64 Timestamp;
151 UINT64 LastXid;
153
157typedef struct APFS_OBJ_PHYS_ {
158 //
159 // The Fletcher 64 checksum of the object.
160 //
161 UINT64 Checksum;
162 //
163 // The object's identifier.
164 // NXSB=01 00.
165 // APSB=02 04, 06 04, and 08 04.
166 //
167 UINT64 ObjectOid;
168 //
169 // The identifier of the most recent transaction that this object
170 // was modified in.
171 //
172 UINT64 ObjectXid;
173 //
174 // The object's type and flags.
175 //
177 //
178 // The object's subtype.
179 // Subtypes indicate the type of data stored in a data structure such as a
180 // B-tree. For example, a node in a B-tree that contains volume records has
181 // a type of OBJECT_TYPE_BTREE_NODE and a subtype of OBJECT_TYPE_FS.
182 //
185
197typedef struct APFS_NX_SUPERBLOCK_ {
199 //
200 // Magic: NXSB
201 //
202 UINT32 Magic;
203 //
204 // The logical block size used in the Apple File System container.
205 // This size is often the same as the block size used by the underlying
206 // storage device, but it can also be an integer multiple of the deviceʼs block size.
207 //
208 UINT32 BlockSize;
209 //
210 // Number of blocks in the container
211 //
213 UINT64 Features;
216 EFI_GUID Uuid;
217 UINT64 NextOid;
218 UINT64 NextXid;
226 UINT32 XpDescLen;
228 UINT32 XpDataLen;
231 UINT64 ReaperOid;
232 UINT32 TestType;
238 UINT64 Flags;
239 //
240 // Pointer to JSDR block
241 //
243 EFI_GUID FusionUuid;
246 UINT64 TestOid;
251
252STATIC_ASSERT (sizeof (APFS_NX_SUPERBLOCK) == 1384, "APFS_NX_SUPERBLOCK has unexpected size");
253
257typedef struct APFS_APFS_SUPERBLOCK_ {
259 //
260 // Volume Superblock magic
261 // Magic: APSB
262 //
263 UINT32 Magic;
264 //
265 // Volume#. First volume start with 0, (0x00)
266 //
267 UINT32 FsIndex;
268 UINT64 Features;
272 //
273 // Size of volume in blocks. Last volume has no
274 // size set and has available the rest of the blocks
275 //
278 //
279 // Blocks in use in this volume.
280 //
286 UINT64 OmapOid;
292 UINT64 NextObjId;
293 UINT64 NumFiles;
302 UINT64 FsFlags;
306 UINT32 NextDocId;
307 UINT16 Role;
308 UINT16 Reserved;
309 UINT64 RootToXid;
312
318 //
319 // A number that can be used to verify that you're reading an instance of
320 // APFS_EFI_BOOT_RECORD
321 //
322 UINT32 Magic;
323 //
324 // The version of this data structure
325 //
326 UINT32 Version;
327 //
328 // The length in bytes, of the embedded EFI driver
329 //
331 //
332 // Num of extents in the array
333 //
335 //
336 // Reserved
337 // Populate this field with 0 when you create a new instance,
338 // and preserve its value when you modify an existing instance.
339 //
340 UINT64 Reserved[16];
341 //
342 // Apfs driver physical range location
343 //
346
347#pragma pack(pop)
348
349#endif // APFS_H
#define APFS_NX_MAX_FILE_SYSTEMS
Definition Apfs.h:64
#define APFS_NX_EPH_INFO_COUNT
Definition Apfs.h:65
#define APFS_NX_NUM_COUNTERS
Definition Apfs.h:70
struct APFS_DRIVER_VERSION_ APFS_DRIVER_VERSION
STATIC_ASSERT(sizeof(APFS_NX_SUPERBLOCK)==1384, "APFS_NX_SUPERBLOCK has unexpected size")
#define APFS_VOLNAME_LEN
Definition Apfs.h:83
struct APFS_OBJ_PHYS_ APFS_OBJ_PHYS
struct APFS_APFS_SUPERBLOCK_ APFS_APFS_SUPERBLOCK
struct PhysicalRange_ APFS_PHYSICAL_RANGE
struct APFS_NX_SUPERBLOCK_ APFS_NX_SUPERBLOCK
struct APFS_NX_EFI_JUMPSTART_ APFS_NX_EFI_JUMPSTART
#define APFS_MODIFIED_NAMELEN
Definition Apfs.h:82
#define APFS_MAX_HIST
Definition Apfs.h:81
UINT64 TotalBlocksAllocated
Definition Apfs.h:298
UINT64 ReadOnlyCompatibleFeatures
Definition Apfs.h:269
UINT32 RootTreeType
Definition Apfs.h:283
APFS_MODIFIED_BY FormattedBy
Definition Apfs.h:303
UINT8 VolumeName[APFS_VOLNAME_LEN]
Definition Apfs.h:305
UINT64 SnapMetaTreeOid
Definition Apfs.h:289
UINT64 FsReserveBlockCount
Definition Apfs.h:276
APFS_MODIFIED_BY ModifiedBy[APFS_MAX_HIST]
Definition Apfs.h:304
UINT64 NumOtherFsObjects
Definition Apfs.h:296
APFS_WRAPPED_CRYPTO_STATE MetaCrypto
Definition Apfs.h:282
UINT32 ExtentrefTreeType
Definition Apfs.h:284
UINT64 IncompatibleFeatures
Definition Apfs.h:270
APFS_OBJ_PHYS BlockHeader
Definition Apfs.h:258
UINT64 FsQuotaBlockCount
Definition Apfs.h:277
UINT64 NumDirectories
Definition Apfs.h:294
UINT64 RevertToSblockOid
Definition Apfs.h:291
UINT64 ExtentrefTreeOid
Definition Apfs.h:288
UINT32 SnapMetaTreeType
Definition Apfs.h:285
UINT64 NumSnapshots
Definition Apfs.h:297
UINT64 TotalBlocksFreed
Definition Apfs.h:299
UINT64 FsAllocCount
Definition Apfs.h:281
UINT32 ImageVersion
Definition Apfs.h:108
CHAR8 Date[16]
Definition Apfs.h:116
CHAR8 Time[16]
Definition Apfs.h:120
UINT64 Timestamp
Definition Apfs.h:150
UINT64 LastXid
Definition Apfs.h:151
UINT64 Reserved[16]
Definition Apfs.h:340
APFS_PHYSICAL_RANGE RecordExtents[]
Definition Apfs.h:344
APFS_OBJ_PHYS BlockHeader
Definition Apfs.h:317
UINT64 Features
Definition Apfs.h:213
UINT32 XpDescBlocks
Definition Apfs.h:219
UINT32 XpDataLen
Definition Apfs.h:228
UINT32 XpDataNext
Definition Apfs.h:224
UINT64 FusionMtIod
Definition Apfs.h:247
UINT64 ObjectMapOid
Definition Apfs.h:230
UINT64 Counters[APFS_NX_NUM_COUNTERS]
Definition Apfs.h:235
APFS_PHYSICAL_RANGE BlockedOutPhysicalRange
Definition Apfs.h:236
UINT32 XpDataIndex
Definition Apfs.h:227
UINT32 XpDescIndex
Definition Apfs.h:225
UINT64 ReaperOid
Definition Apfs.h:231
APFS_PHYSICAL_RANGE FusionWbc
Definition Apfs.h:249
UINT64 IncompatibleFeatures
Definition Apfs.h:215
UINT64 ReadOnlyCompatibleFeatures
Definition Apfs.h:214
EFI_GUID Uuid
Definition Apfs.h:216
UINT32 XpDescNext
Definition Apfs.h:223
UINT64 TotalBlocks
Definition Apfs.h:212
APFS_OBJ_PHYS BlockHeader
Definition Apfs.h:198
UINT32 MaxFileSystems
Definition Apfs.h:233
UINT32 BlockSize
Definition Apfs.h:208
UINT64 EfiJumpStart
Definition Apfs.h:242
UINT32 XpDescLen
Definition Apfs.h:226
UINT64 FusionWbcOid
Definition Apfs.h:248
UINT64 EphermalInfo[APFS_NX_EPH_INFO_COUNT]
Definition Apfs.h:245
UINT32 XpDataBlocks
Definition Apfs.h:220
UINT64 FileSystemOid[APFS_NX_MAX_FILE_SYSTEMS]
Definition Apfs.h:234
UINT64 EvictMappingTreeOid
Definition Apfs.h:237
APFS_PHYSICAL_RANGE KeyLocker
Definition Apfs.h:244
UINT64 SpacemanOid
Definition Apfs.h:229
UINT32 TestType
Definition Apfs.h:232
EFI_GUID FusionUuid
Definition Apfs.h:243
UINT64 ObjectXid
Definition Apfs.h:172
UINT64 Checksum
Definition Apfs.h:161
UINT64 ObjectOid
Definition Apfs.h:167
UINT32 ObjectType
Definition Apfs.h:176
UINT32 ObjectSubType
Definition Apfs.h:183
INT64 StartPhysicalAddr
Definition Apfs.h:127
UINT64 BlockCount
Definition Apfs.h:128