VirtualBox

source: vbox/trunk/include/iprt/formats/apfs.h@ 98263

Last change on this file since 98263 was 98103, checked in by vboxsync, 23 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.2 KB
Line 
1/* $Id: apfs.h 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * IPRT, APFS (Apple File System) format.
4 */
5
6/*
7 * Copyright (C) 2019-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37#ifndef IPRT_INCLUDED_formats_apfs_h
38#define IPRT_INCLUDED_formats_apfs_h
39#ifndef RT_WITHOUT_PRAGMA_ONCE
40# pragma once
41#endif
42
43#include <iprt/types.h>
44#include <iprt/assertcompile.h>
45
46
47/** @defgroup grp_rt_formats_apfs Apple File System structures and definitions
48 * @ingroup grp_rt_formats
49 * @{
50 */
51
52/*
53 * The filesystem structures were retrieved from:
54 * https://developer.apple.com/support/downloads/Apple-File-System-Reference.pdf
55 */
56
57/** Physical address of an on-disk block. */
58typedef int64_t APFSPADDR;
59/** Object identifier. */
60typedef uint64_t APFSOID;
61/** Transaction identifier. */
62typedef uint64_t APFSXID;
63
64/** Invalid object ID. */
65#define APFS_OID_INVALID UINT64_C(0)
66/** Number of reserved object IDs for special structures. */
67#define APFS_OID_RSVD_CNT 1024
68/** Object ID of a super block. */
69#define APFS_OID_NX_SUPERBLOCK UINT64_C(1)
70
71
72/**
73 * Range of physical addresses.
74 */
75typedef struct
76{
77 /** Start address of the range. */
78 APFSPADDR PAddrStart;
79 /** Size of the range in blocks.*/
80 uint64_t cBlocks;
81} APFSPRANGE;
82/** Pointer to a APFS range. */
83typedef APFSPRANGE *PAPFSPRANGE;
84/** Pointer to a const APFS range. */
85typedef const APFSPRANGE *PCAPFSPRANGE;
86
87/** APFS UUID (compatible with our UUID definition). */
88typedef RTUUID APFSUUID;
89
90/** Maximum object checksum size. */
91#define APFS_OBJ_MAX_CHKSUM_SZ 8
92
93/**
94 * APFS Object header.
95 */
96typedef struct APFSOBJPHYS
97{
98 /** The stored checksum of the object. */
99 uint8_t abChkSum[APFS_OBJ_MAX_CHKSUM_SZ];
100 /** Object ID. */
101 APFSOID Oid;
102 /** Transaction ID. */
103 APFSXID Xid;
104 /** Object type. */
105 uint32_t u32Type;
106 /** Object sub type. */
107 uint32_t u32SubType;
108} APFSOBJPHYS;
109/** Pointer to an APFS object header. */
110typedef APFSOBJPHYS *PAPFSOBJPHYS;
111/** Pointer to a const APFS object header. */
112typedef const APFSOBJPHYS *PCAPFSOBJPHYS;
113
114#define APFS_OBJECT_TYPE_MASK UINT32_C(0x0000ffff)
115#define APFS_OBJECT_TYPE_FLAGS_MASK UINT32_C(0xffff0000)
116
117/**
118 * APFS EFI jumpstart information.
119 */
120typedef struct APFSEFIJMPSTART
121{
122 /** Object header. */
123 APFSOBJPHYS ObjHdr;
124 /** The magic value. */
125 uint32_t u32Magic;
126 /** The version of the structure. */
127 uint32_t u32Version;
128 /** EFI file length in bytes. */
129 uint32_t cbEfiFile;
130 /** Number of extents describing the on disk blocks the file is stored in. */
131 uint32_t cExtents;
132 /** Reserved. */
133 uint64_t au64Rsvd0[16];
134 /** After this comes a variable size of APFSPRANGE extent structures. */
135} APFSEFIJMPSTART;
136/** Pointer to an APFS EFI jumpstart structure. */
137typedef APFSEFIJMPSTART *PAPFSEFIJMPSTART;
138/** Pointer to a const APFS EFI jumpstart structure. */
139typedef const APFSEFIJMPSTART *PCAPFSEFIJMPSTART;
140
141/** EFI jumpstart magic ('RDSJ'). */
142#define APFS_EFIJMPSTART_MAGIC RT_MAKE_U32_FROM_U8('J', 'S', 'D', 'R')
143/** EFI jumpstart version. */
144#define APFS_EFIJMPSTART_VERSION UINT32_C(1)
145
146/** Maximum number of filesystems supported in a single container. */
147#define APFS_NX_SUPERBLOCK_FS_MAX UINT32_C(100)
148/** Maximum number of counters in the superblock. */
149#define APFS_NX_SUPERBLOCK_COUNTERS_MAX UINT32_C(32)
150/** Number of entries in the ephemeral information array. */
151#define APFS_NX_SUPERBLOCK_EPH_INFO_COUNT UINT32_C(4)
152
153/**
154 * APFS super block.
155 */
156typedef struct
157{
158 /** Object header. */
159 APFSOBJPHYS ObjHdr;
160 /** The magic value. */
161 uint32_t u32Magic;
162 /** Block size in bytes. */
163 uint32_t cbBlock;
164 /** Number of blocks in the volume. */
165 uint64_t cBlocks;
166 /** Feature flags of the volume. */
167 uint64_t fFeatures;
168 /** Readonly compatible features. */
169 uint64_t fRdOnlyCompatFeatures;
170 /** Incompatible features. */
171 uint64_t fIncompatFeatures;
172 /** UUID of the volume. */
173 APFSUUID Uuid;
174 /** Next free object identifier to use for new objects. */
175 APFSOID OidNext;
176 /** Next free transaction identifier to use for new transactions. */
177 APFSOID XidNext;
178 /** Number of blocks used by the checkpoint descriptor area. */
179 uint32_t cXpDescBlocks;
180 /** Number of blocks used by the checkpoint data area. */
181 uint32_t cXpDataBlocks;
182 /** Base address of checkpoint descriptor area. */
183 APFSPADDR PAddrXpDescBase;
184 /** Base address of checkpoint data area. */
185 APFSPADDR PAddrXpDataBase;
186 /** Next index to use in the checkpoint descriptor area. */
187 uint32_t idxXpDescNext;
188 /** Next index to use in the checkpoint data area. */
189 uint32_t idxXpDataNext;
190 /** Number of blocks in the checkpoint descriptor area used by the checkpoint that this superblock belongs to. */
191 uint32_t cXpDescLen;
192 /** Index of the first valid item in the checkpoint data area. */
193 uint32_t idxXpDataFirst;
194 /** Number of blocks in the checkpoint data area used by the checkpoint that this superblock belongs to. */
195 uint32_t cXpDataLen;
196 /** Ephemeral object identifer of the space manager. */
197 APFSOID OidSpaceMgr;
198 /** Physical object identifier for the containers object map. */
199 APFSOID OidOMap;
200 /** Ephemeral object identifer for the reaper. */
201 APFSOID OidReaper;
202 /** Reserved for testing should be always zero on disk. */
203 uint32_t u32TestType;
204 /** Maximum number of filesystems which can be stored in this container. */
205 uint32_t cFsMax;
206 /** Array of filesystem object identifiers. */
207 APFSOID aFsOids[APFS_NX_SUPERBLOCK_FS_MAX];
208 /** Array of counters primarily used during debugging. */
209 uint64_t aCounters[APFS_NX_SUPERBLOCK_COUNTERS_MAX];
210 /** Range of blocks where no space will be allocated, used for shrinking a partition. */
211 APFSPRANGE RangeBlocked;
212 /** Physical object identifier of a tree keeping track of objects needing to be moved out of the block range. */
213 APFSOID OidTreeEvictMapping;
214 /** Container flags. */
215 uint64_t fFlags;
216 /** Address of the EFI jumpstart structure. */
217 APFSPADDR PAddrEfiJmpStart;
218 /** UUID of the containers Fusion set if available. */
219 APFSUUID UuidFusion;
220 /** Address of the containers keybag. */
221 APFSPADDR PAddrKeyLocker;
222 /** Array of fields used in the management of ephemeral data. */
223 uint64_t au64EphemeralInfo[APFS_NX_SUPERBLOCK_EPH_INFO_COUNT];
224 /** Reserved for testing. */
225 APFSOID OidTest;
226 /** Physical object identifier of the Fusion middle tree. */
227 APFSOID OidFusionMt;
228 /** Ephemeral object identifier of the Fusion write-back cache state. */
229 APFSOID OidFusionWbc;
230 /** Blocks used for the Fusion write-back cache area. */
231 APFSPRANGE RangeFusionWbc;
232} APFSNXSUPERBLOCK;
233/** Pointer to a APFS super block structure. */
234typedef APFSNXSUPERBLOCK *PAPFSNXSUPERBLOCK;
235/** Pointer to a const APFS super block structure. */
236typedef const APFSNXSUPERBLOCK *PCAPFSNXSUPERBLOCK;
237
238/** Superblock magic value ('BSXN'). */
239#define APFS_NX_SUPERBLOCK_MAGIC RT_MAKE_U32_FROM_U8('N', 'X', 'S', 'B')
240
241/** @} */
242
243#endif /* !IPRT_INCLUDED_formats_apfs_h */
244
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette