1 | /* $Id: xfs.h 76616 2019-01-02 19:46:01Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT, XFS format.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2018 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * The contents of this file may alternatively be used under the terms
|
---|
18 | * of the Common Development and Distribution License Version 1.0
|
---|
19 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | * CDDL are applicable instead of those of the GPL.
|
---|
22 | *
|
---|
23 | * You may elect to license modified versions of this file under the
|
---|
24 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | */
|
---|
26 |
|
---|
27 | #ifndef ___iprt_formats_xfs_h
|
---|
28 | #define ___iprt_formats_xfs_h
|
---|
29 |
|
---|
30 | #include <iprt/types.h>
|
---|
31 | #include <iprt/assertcompile.h>
|
---|
32 |
|
---|
33 |
|
---|
34 | /** @defgroup grp_rt_formats_xfs XFS filesystem structures and definitions
|
---|
35 | * @ingroup grp_rt_formats
|
---|
36 | * @{
|
---|
37 | */
|
---|
38 |
|
---|
39 | /*
|
---|
40 | * The filesystem structures were retrieved from:
|
---|
41 | * http://xfs.org/docs/xfsdocs-xml-dev/XFS_Filesystem_Structure//tmp/en-US/html/index.html and
|
---|
42 | * https://elixir.bootlin.com/linux/v4.9/source/fs/xfs/libxfs/xfs_format.h and
|
---|
43 | * https://righteousit.wordpress.com/
|
---|
44 | */
|
---|
45 |
|
---|
46 | /** XFS superblock offset from the beginning of the volume, this is constant. */
|
---|
47 | #define XFS_SB_OFFSET UINT64_C(0)
|
---|
48 |
|
---|
49 | /** @name Common XFS types as defined in the spec.
|
---|
50 | * @{ */
|
---|
51 | /** Unsigned 64 bit absolute inode number. */
|
---|
52 | typedef uint64_t XFSINO;
|
---|
53 | /** Signed 64 bit file offset. */
|
---|
54 | typedef int64_t XFSFOFF;
|
---|
55 | /** Signed 64 bit disk address. */
|
---|
56 | typedef int64_t XFSDADDR;
|
---|
57 | /** Unsinged 32 bit allocation group (AG) number. */
|
---|
58 | typedef uint32_t XFSAGNUMBER;
|
---|
59 | /** Unsigned 32 bit AG relative block number. */
|
---|
60 | typedef uint32_t XFSAGBLOCK;
|
---|
61 | /** Unsigned 32 bit extent length in blocks. */
|
---|
62 | typedef uint32_t XFSEXTLEN;
|
---|
63 | /** Signed 32 bit number of extents in a file. */
|
---|
64 | typedef int32_t XFSEXTNUM;
|
---|
65 | /** Unsigned 32 bit block number for directories and extended attributes. */
|
---|
66 | typedef uint32_t XFSDABLK;
|
---|
67 | /** Unsigned 32 bit hash of a directory file name or extended attribute name. */
|
---|
68 | typedef uint32_t XFSDAHASH;
|
---|
69 | /** Unsigned 64 bit filesystem block number combining AG number and block offset into the AG. */
|
---|
70 | typedef uint64_t XFSDFSBNO;
|
---|
71 | /** Unsigned 64 bit raw filesystem block number. */
|
---|
72 | typedef uint64_t XFSDRFSBNO;
|
---|
73 | /** Unsigned 64 bit extent number in the real-time device. */
|
---|
74 | typedef uint64_t XFSDRTBNO;
|
---|
75 | /** Unsigned 64 bit block offset int oa file. */
|
---|
76 | typedef uint64_t XFSDFILOFF;
|
---|
77 | /** Unsigned 64 bit block count for a file. */
|
---|
78 | typedef uint64_t XFSDFILBLKS;
|
---|
79 | /** @} */
|
---|
80 |
|
---|
81 | /**
|
---|
82 | * XFS superblock.
|
---|
83 | */
|
---|
84 | #pragma pack(1)
|
---|
85 | typedef struct XFSSUPERBLOCK
|
---|
86 | {
|
---|
87 | /** 0x00: Magic number to identify the superblock. */
|
---|
88 | uint32_t u32Magic;
|
---|
89 | /** 0x04: Size of smallest allocation unit in bytes. */
|
---|
90 | uint32_t cbBlock;
|
---|
91 | /** 0x04: Number of blocks available for data and metadata. */
|
---|
92 | XFSDRFSBNO cBlocks;
|
---|
93 | /** 0x0c: Number of block in the real-time device. */
|
---|
94 | XFSDRFSBNO cBlocksRtDev;
|
---|
95 | /** 0x14: Number of extents on real-time device. */
|
---|
96 | XFSDRTBNO cExtentsRtDev;
|
---|
97 | /** 0x1c: UUID of the filesystem. */
|
---|
98 | uint8_t abUuid[16];
|
---|
99 | /** 0x2c: First block of the filesystem journal. */
|
---|
100 | XFSDFSBNO uBlockJournal;
|
---|
101 | /** 0x34: Inode number of the root directory. */
|
---|
102 | XFSINO uInodeRoot;
|
---|
103 | /** Inode for the real-time extent bitmap. */
|
---|
104 | XFSINO uInodeBitmapRtExt;
|
---|
105 | /** Inode for the real-time bitmap summary. */
|
---|
106 | XFSINO uInodeBitmapSummary;
|
---|
107 | /** Extent size on the real-time device in blocks. */
|
---|
108 | XFSAGBLOCK cRtExtent;
|
---|
109 | /** Size of an AG in blocks. */
|
---|
110 | XFSAGBLOCK cAgBlocks;
|
---|
111 | /** Number of AGs in hte filesystem. */
|
---|
112 | XFSAGNUMBER cAg;
|
---|
113 | /** Number of real-time bitmap blocks. */
|
---|
114 | XFSEXTLEN cRtBitmapBlocks;
|
---|
115 | /** Number of blocks for the journal. */
|
---|
116 | XFSEXTLEN cJournalBlocks;
|
---|
117 | /** Version number (actually flag bitmaps of features). */
|
---|
118 | uint16_t fVersion;
|
---|
119 | /** Sector size of the underlying medium. */
|
---|
120 | uint16_t cbSector;
|
---|
121 | /** Size of an inode in bytes. */
|
---|
122 | uint16_t cbInode;
|
---|
123 | /** Number of inodes stored in one block. */
|
---|
124 | uint16_t cInodesPerBlock;
|
---|
125 | /** Name of the filesystem. */
|
---|
126 | char achFsName[12];
|
---|
127 | /** Block size as log2 (number of bits to shift left). */
|
---|
128 | uint8_t cBlockSzLog;
|
---|
129 | /** Sector size as log2 (number of bits to shift left). */
|
---|
130 | uint8_t cSectorSzLog;
|
---|
131 | /** Inode size as log2 (number of bits to shift left). */
|
---|
132 | uint8_t cInodeSzLog;
|
---|
133 | /** Number of inodes per block as log2. */
|
---|
134 | uint8_t cInodesPerBlockLog;
|
---|
135 | /** Number of AG blocks as log2 (number of bits to shift left). */
|
---|
136 | uint8_t cAgBlocksLog;
|
---|
137 | /** Number of extent blocks as log2. */
|
---|
138 | uint8_t cExtentsRtDevLog;
|
---|
139 | /** Flag when the filesystem is in the process of being created. */
|
---|
140 | uint8_t fInProgress;
|
---|
141 | /** Maximum percentage of the filesystem usable for inodes. */
|
---|
142 | uint8_t cInodeMaxPct;
|
---|
143 | /** Global number of inodes allocated (only mainted on the first superblock). */
|
---|
144 | uint64_t cInodesGlobal;
|
---|
145 | /** Global number of free inodes (only mainted on the first superblock). */
|
---|
146 | uint64_t cInodesGlobalFree;
|
---|
147 | /** Global count of free data blocks on the filesystem (only mainted on the first superblock). */
|
---|
148 | uint64_t cBlocksFree;
|
---|
149 | /** Global count of free extents on the real-time device (only mainted on the first superblock). */
|
---|
150 | uint64_t cExtentsRtFree;
|
---|
151 | /** Inode containing the user quotas. */
|
---|
152 | XFSINO uInodeQuotaUsr;
|
---|
153 | /** Inode containing the group/project quotas. */
|
---|
154 | XFSINO uInodeQuotaGrp;
|
---|
155 | /** Quota flags. */
|
---|
156 | uint16_t fQuotaFlags;
|
---|
157 | /** Misc flags. */
|
---|
158 | uint8_t fFlagsMisc;
|
---|
159 | /** Reserved MBZ. */
|
---|
160 | uint8_t uSharedVn;
|
---|
161 | /** Number of filesystem blocks for the inode chunk alignment. */
|
---|
162 | XFSEXTLEN cBlocksInodeAlignment;
|
---|
163 | /** Raid stripe size in blocks. */
|
---|
164 | uint32_t cBlocksRaidStripe;
|
---|
165 | /** Raid width in number of blocks. */
|
---|
166 | uint32_t cBlocksRaidWidth;
|
---|
167 | /** Multiplier for determining the allocation size for directory blocks as log2. */
|
---|
168 | uint8_t cDirBlockAllocLog;
|
---|
169 | /** Sub volume sector size as log2 if an external journal device is used. */
|
---|
170 | uint8_t cLogDevSubVolSectorSzLog;
|
---|
171 | /** Sector size of the device an external journal is stored as log2. */
|
---|
172 | uint16_t cLogDevSectorSzLog;
|
---|
173 | /** Log devices stripe size. */
|
---|
174 | uint32_t cLogDevRaidStripe;
|
---|
175 | /** Additional features which may be active. */
|
---|
176 | uint32_t fFeatures2;
|
---|
177 | /** Padding. */
|
---|
178 | uint32_t u32Padding0;
|
---|
179 | /** From here follow data only available from version 5 and later. */
|
---|
180 | /** Read/Write feature flags. */
|
---|
181 | uint32_t fFeaturesRw;
|
---|
182 | /** Read-only feature flags. */
|
---|
183 | uint32_t fFeaturesRo;
|
---|
184 | /** Read/Write incompatible feature flags. */
|
---|
185 | uint32_t fFeaturesIncompatRw;
|
---|
186 | /** Read/Write incompatible feature flags for the journal. */
|
---|
187 | uint32_t fFeaturesJrnlIncompatRw;
|
---|
188 | /** CRC32 checksum for the superblock. */
|
---|
189 | uint32_t u32Chksum;
|
---|
190 | /** Sparse inode alignment. */
|
---|
191 | uint32_t u32SparseInodeAlignment;
|
---|
192 | /** Project quota inode. */
|
---|
193 | XFSINO uInodeProjectQuota;
|
---|
194 | /** Log sequence number of last superblock update. */
|
---|
195 | uint64_t uJrnlSeqSbUpdate;
|
---|
196 | /** UUID used when INCOMPAT_META_UUID is used. */
|
---|
197 | uint8_t abUuidMeta[16];
|
---|
198 | /** Inode if INCOMPATMETA_RMAPBT is used. */
|
---|
199 | XFSINO uInodeRm;
|
---|
200 | } XFSSUPERBLOCK;
|
---|
201 | #pragma pack()
|
---|
202 | AssertCompileSize(XFSSUPERBLOCK, 272);
|
---|
203 | /** Pointer to an XFS superblock. */
|
---|
204 | typedef XFSSUPERBLOCK *PXFSSUPERBLOCK;
|
---|
205 | /** Pointer to a const XFS superblock. */
|
---|
206 | typedef const XFSSUPERBLOCK *PCXFSSUPERBLOCK;
|
---|
207 |
|
---|
208 | /** XFS superblock magic. */
|
---|
209 | #define XFS_SB_MAGIC RT_MAKE_U32_FROM_U8('B', 'S', 'F', 'X')
|
---|
210 |
|
---|
211 | /** @name XFS_SB_VERSION_F_XXX - Version/Feature flags.
|
---|
212 | * @{ */
|
---|
213 | /** Retrieves the version part of the field. */
|
---|
214 | #define XFS_SB_VERSION_GET(a_fVersion) ((a_fVersion) & 0xf)
|
---|
215 | /** Version number for filesystem 5.3, 6.0.1 and 6.1. */
|
---|
216 | #define XFS_SB_VERSION_1 1
|
---|
217 | /** Version number for filesystem 6.2 - attributes. */
|
---|
218 | #define XFS_SB_VERSION_2 2
|
---|
219 | /** Version number for filesystem 6.2 - new inode version. */
|
---|
220 | #define XFS_SB_VERSION_3 3
|
---|
221 | /** Version number for filesystem 6.2+ - new bitmask version. */
|
---|
222 | #define XFS_SB_VERSION_4 4
|
---|
223 | /** Introduced checksums in the metadata. */
|
---|
224 | #define XFS_SB_VERSION_5 5
|
---|
225 | /** Extended attributes are used for at least one inode. */
|
---|
226 | #define XFS_SB_VERSION_F_ATTR RT_BIT_32(4)
|
---|
227 | /** At least one inode use 32-bit nlink values. */
|
---|
228 | #define XFS_SB_VERSION_F_NLINK RT_BIT_32(5)
|
---|
229 | /** Quotas are enabled on the filesystem. */
|
---|
230 | #define XFS_SB_VERSION_F_QUOTA RT_BIT_32(6)
|
---|
231 | /** Set if XFSSUPERBLOCK::cBlocksInodeAlignment is used. */
|
---|
232 | #define XFS_SB_VERSION_F_ALIGN RT_BIT_32(7)
|
---|
233 | /** Set if XFSSUPERBLOCK::cBlocksRaidStripe and XFSSUPERBLOCK::cBlocksRaidWidth are used. */
|
---|
234 | #define XFS_SB_VERSION_F_DALIGN RT_BIT_32(8)
|
---|
235 | /** Set if XFSSUPERBLOCK::uSharedVn is used. */
|
---|
236 | #define XFS_SB_VERSION_F_SHARED RT_BIT_32(9)
|
---|
237 | /** Version 2 journaling is used. */
|
---|
238 | #define XFS_SB_VERSION_F_LOGV2 RT_BIT_32(10)
|
---|
239 | /** Set if sector size is not 512 bytes. */
|
---|
240 | #define XFS_SB_VERSION_F_SECTOR RT_BIT_32(11)
|
---|
241 | /** Set if unwritten extents are used (always set). */
|
---|
242 | #define XFS_SB_VERSION_F_EXTFLG RT_BIT_32(12)
|
---|
243 | /** Version 2 directories are used (always set). */
|
---|
244 | #define XFS_SB_VERSION_F_DIRV2 RT_BIT_32(13)
|
---|
245 | /** Set if XFSSUPERBLOCK::fFeatures2 is used. */
|
---|
246 | #define XFS_SB_VERSION_F_FEAT2 RT_BIT_32(14)
|
---|
247 | /** @} */
|
---|
248 |
|
---|
249 | /** @name XFS_SB_QUOTA_F_XXX - Quota flags
|
---|
250 | * @{ */
|
---|
251 | /** User quota accounting enabled. */
|
---|
252 | #define XFS_SB_QUOTA_F_USR_ACCT RT_BIT(0)
|
---|
253 | /** User quotas are enforced. */
|
---|
254 | #define XFS_SB_QUOTA_F_USR_ENFD RT_BIT(1)
|
---|
255 | /** User quotas have been checked and updated on disk. */
|
---|
256 | #define XFS_SB_QUOTA_F_USR_CHKD RT_BIT(2)
|
---|
257 | /** Project quota accounting is enabled. */
|
---|
258 | #define XFS_SB_QUOTA_F_PROJ_ACCT RT_BIT(3)
|
---|
259 | /** Other quotas are enforced. */
|
---|
260 | #define XFS_SB_QUOTA_F_OTH_ENFD RT_BIT(4)
|
---|
261 | /** Other quotas have been checked and updated on disk. */
|
---|
262 | #define XFS_SB_QUOTA_F_OTH_CHKD RT_BIT(5)
|
---|
263 | /** Group quota accounting enabled. */
|
---|
264 | #define XFS_SB_QUOTA_F_GRP_ACCT RT_BIT(6)
|
---|
265 | /** @} */
|
---|
266 |
|
---|
267 | /** @name XFS_SB_FEATURES2_F_XXX - Additional features
|
---|
268 | * @{ */
|
---|
269 | /** Global counters are lazy and are only updated when the filesystem is cleanly unmounted. */
|
---|
270 | #define XFS_SB_FEATURES2_F_LAZYSBCOUNT RT_BIT_32(1)
|
---|
271 | /** Extended attributes version 2. */
|
---|
272 | #define XFS_SB_FEATURES2_F_ATTR2 RT_BIT_32(3)
|
---|
273 | /** Parent pointers, inodes must have an extended attribute pointing to the parent inode. */
|
---|
274 | #define XFS_SB_FEATURES2_F_PARENT RT_BIT_32(4)
|
---|
275 | /** @} */
|
---|
276 |
|
---|
277 |
|
---|
278 | /**
|
---|
279 | * XFS AG free space block.
|
---|
280 | */
|
---|
281 | typedef struct XFSAGF
|
---|
282 | {
|
---|
283 | /** Magic number. */
|
---|
284 | uint32_t u32Magic;
|
---|
285 | /** Header version number. */
|
---|
286 | uint32_t uVersion;
|
---|
287 | /** AG number for the sector. */
|
---|
288 | uint32_t uSeqNo;
|
---|
289 | /** Length of the AG in filesystem blocks. */
|
---|
290 | uint32_t cLengthBlocks;
|
---|
291 | /** Block numbers for the roots of the free space B+trees. */
|
---|
292 | uint32_t auRoots[3];
|
---|
293 | /** Depths of the free space B+trees. */
|
---|
294 | uint32_t acLvls[3];
|
---|
295 | /** Index of the first free list block. */
|
---|
296 | uint32_t idxFreeListFirst;
|
---|
297 | /** Index of the last free list block. */
|
---|
298 | uint32_t idxFreeListLast;
|
---|
299 | /** Number of blocks in the free list. */
|
---|
300 | uint32_t cFreeListBlocks;
|
---|
301 | /** Current number of free blocks in the AG. */
|
---|
302 | uint32_t cFreeBlocks;
|
---|
303 | /** Longest number of contiguous free blocks in the AG. */
|
---|
304 | uint32_t cFreeBlocksLongest;
|
---|
305 | /** Number of blocks used for the free space B+-trees. */
|
---|
306 | uint32_t cBlocksBTrees;
|
---|
307 | /** UUID of filesystem the AG belongs to. */
|
---|
308 | uint8_t abUuid[16];
|
---|
309 | /** Number of blocks used for the reverse map. */
|
---|
310 | uint32_t cBlocksRevMap;
|
---|
311 | /** Number of blocks used for the refcount B+-tree. */
|
---|
312 | uint32_t cBlocksRefcountBTree;
|
---|
313 | /** Block number for the refcount tree root. */
|
---|
314 | uint32_t uRootRefcount;
|
---|
315 | /** Depth of the refcount B+-tree. */
|
---|
316 | uint32_t cLvlRefcount;
|
---|
317 | /** Reserved contiguous space for future extensions. */
|
---|
318 | uint64_t au64Rsvd[14];
|
---|
319 | /** Last write sequence number. */
|
---|
320 | uint64_t uSeqNoLastWrite;
|
---|
321 | /** CRC of the AGF. */
|
---|
322 | uint32_t uChkSum;
|
---|
323 | /** Padding to 64 bit alignment. */
|
---|
324 | uint32_t uAlignment0;
|
---|
325 | } XFSAGF;
|
---|
326 | /** Pointer to a AG free space block. */
|
---|
327 | typedef XFSAGF *PXFSAGF;
|
---|
328 | /** Poiner to a const AG free space block. */
|
---|
329 | typedef const XFSAGF *PCXFSAGF;
|
---|
330 |
|
---|
331 | /** AGF magic. */
|
---|
332 | #define XFS_AGF_MAGIC RT_MAKE_U32_FROM_U8('F', 'G', 'A', 'X')
|
---|
333 | /** The current valid AGF version. */
|
---|
334 | #define XFS_AGF_VERSION 1
|
---|
335 |
|
---|
336 |
|
---|
337 | /**
|
---|
338 | * XFS AG inode information.
|
---|
339 | */
|
---|
340 | typedef struct XFSAGI
|
---|
341 | {
|
---|
342 | /** Magic number. */
|
---|
343 | uint32_t u32Magic;
|
---|
344 | /** Header version number. */
|
---|
345 | uint32_t uVersion;
|
---|
346 | /** AG number for the sector. */
|
---|
347 | uint32_t uSeqNo;
|
---|
348 | /** Length of the AG in filesystem blocks. */
|
---|
349 | uint32_t cLengthBlocks;
|
---|
350 | /** Count of allocated inodes. */
|
---|
351 | uint32_t cInodesAlloc;
|
---|
352 | /** Block number of the inode tree root. */
|
---|
353 | uint32_t uRootInode;
|
---|
354 | /** Depth of the inode B+-tree. */
|
---|
355 | uint32_t cLvlsInode;
|
---|
356 | /** Newest allocated inode. */
|
---|
357 | uint32_t uInodeNew;
|
---|
358 | /** Last directory inode chunk. */
|
---|
359 | uint32_t uInodeDir;
|
---|
360 | /** Hash table of unlinked but still referenced inodes. */
|
---|
361 | uint32_t au32HashUnlinked[64];
|
---|
362 | /** UUID of filesystem. */
|
---|
363 | uint8_t abUuid[16];
|
---|
364 | /** CRC of the AGI. */
|
---|
365 | uint32_t uChkSum;
|
---|
366 | /** Padding. */
|
---|
367 | uint32_t uAlignment0;
|
---|
368 | /** Last write sequence number. */
|
---|
369 | uint64_t uSeqNoLastWrite;
|
---|
370 | /** Block number of the free inode tree. */
|
---|
371 | uint32_t uRootFreeInode;
|
---|
372 | /** Depth of the free inode B+-tree. */
|
---|
373 | uint32_t cLvlsFreeInode;
|
---|
374 | } XFSAGI;
|
---|
375 | /** Pointer to a AG inode information. */
|
---|
376 | typedef XFSAGI *PXFSAGI;
|
---|
377 | /** Pointer to a const AG inode information. */
|
---|
378 | typedef const XFSAGI *PCXFSAGI;
|
---|
379 |
|
---|
380 | /** AGI magic. */
|
---|
381 | #define XFS_AGI_MAGIC RT_MAKE_U32_FROM_U8('I', 'G', 'A', 'X')
|
---|
382 | /** The current valid AGI version. */
|
---|
383 | #define XFS_AGI_VERSION 1
|
---|
384 |
|
---|
385 |
|
---|
386 | /** @} */
|
---|
387 |
|
---|
388 | #endif
|
---|
389 |
|
---|