VirtualBox

source: vbox/trunk/include/iprt/formats/xfs.h@ 103224

Last change on this file since 103224 was 98103, checked in by vboxsync, 22 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: 26.7 KB
Line 
1/* $Id: xfs.h 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * IPRT, XFS format.
4 */
5
6/*
7 * Copyright (C) 2018-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_xfs_h
38#define IPRT_INCLUDED_formats_xfs_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_xfs XFS filesystem structures and definitions
48 * @ingroup grp_rt_formats
49 * @{
50 */
51
52/*
53 * The filesystem structures were retrieved from:
54 * http://xfs.org/docs/xfsdocs-xml-dev/XFS_Filesystem_Structure//tmp/en-US/html/index.html and
55 * https://elixir.bootlin.com/linux/v4.9/source/fs/xfs/libxfs/xfs_format.h and
56 * https://righteousit.wordpress.com/
57 */
58
59/** XFS superblock offset from the beginning of the volume, this is constant. */
60#define XFS_SB_OFFSET UINT64_C(0)
61
62/** @name Common XFS types as defined in the spec.
63 * @{ */
64/** Unsigned 64 bit absolute inode number. */
65typedef uint64_t XFSINO;
66/** Signed 64 bit file offset. */
67typedef int64_t XFSFOFF;
68/** Signed 64 bit disk address. */
69typedef int64_t XFSDADDR;
70/** Unsinged 32 bit allocation group (AG) number. */
71typedef uint32_t XFSAGNUMBER;
72/** Unsigned 32 bit AG relative block number. */
73typedef uint32_t XFSAGBLOCK;
74/** Unsigned 32 bit extent length in blocks. */
75typedef uint32_t XFSEXTLEN;
76/** Signed 32 bit number of extents in a file. */
77typedef int32_t XFSEXTNUM;
78/** Unsigned 32 bit block number for directories and extended attributes. */
79typedef uint32_t XFSDABLK;
80/** Unsigned 32 bit hash of a directory file name or extended attribute name. */
81typedef uint32_t XFSDAHASH;
82/** Unsigned 64 bit filesystem block number combining AG number and block offset into the AG. */
83typedef uint64_t XFSDFSBNO;
84/** Unsigned 64 bit raw filesystem block number. */
85typedef uint64_t XFSDRFSBNO;
86/** Unsigned 64 bit extent number in the real-time device. */
87typedef uint64_t XFSDRTBNO;
88/** Unsigned 64 bit block offset int oa file. */
89typedef uint64_t XFSDFILOFF;
90/** Unsigned 64 bit block count for a file. */
91typedef uint64_t XFSDFILBLKS;
92/** @} */
93
94/**
95 * XFS superblock.
96 */
97#pragma pack(1)
98typedef struct XFSSUPERBLOCK
99{
100 /** 0x00: Magic number to identify the superblock. */
101 uint32_t u32Magic;
102 /** 0x04: Size of smallest allocation unit in bytes. */
103 uint32_t cbBlock;
104 /** 0x04: Number of blocks available for data and metadata. */
105 XFSDRFSBNO cBlocks;
106 /** 0x0c: Number of block in the real-time device. */
107 XFSDRFSBNO cBlocksRtDev;
108 /** 0x14: Number of extents on real-time device. */
109 XFSDRTBNO cExtentsRtDev;
110 /** 0x1c: UUID of the filesystem. */
111 uint8_t abUuid[16];
112 /** 0x2c: First block of the filesystem journal. */
113 XFSDFSBNO uBlockJournal;
114 /** 0x34: Inode number of the root directory. */
115 XFSINO uInodeRoot;
116 /** Inode for the real-time extent bitmap. */
117 XFSINO uInodeBitmapRtExt;
118 /** Inode for the real-time bitmap summary. */
119 XFSINO uInodeBitmapSummary;
120 /** Extent size on the real-time device in blocks. */
121 XFSAGBLOCK cRtExtent;
122 /** Size of an AG in blocks. */
123 XFSAGBLOCK cAgBlocks;
124 /** Number of AGs in hte filesystem. */
125 XFSAGNUMBER cAg;
126 /** Number of real-time bitmap blocks. */
127 XFSEXTLEN cRtBitmapBlocks;
128 /** Number of blocks for the journal. */
129 XFSEXTLEN cJournalBlocks;
130 /** Version number (actually flag bitmaps of features). */
131 uint16_t fVersion;
132 /** Sector size of the underlying medium. */
133 uint16_t cbSector;
134 /** Size of an inode in bytes. */
135 uint16_t cbInode;
136 /** Number of inodes stored in one block. */
137 uint16_t cInodesPerBlock;
138 /** Name of the filesystem. */
139 char achFsName[12];
140 /** Block size as log2 (number of bits to shift left). */
141 uint8_t cBlockSzLog;
142 /** Sector size as log2 (number of bits to shift left). */
143 uint8_t cSectorSzLog;
144 /** Inode size as log2 (number of bits to shift left). */
145 uint8_t cInodeSzLog;
146 /** Number of inodes per block as log2. */
147 uint8_t cInodesPerBlockLog;
148 /** Number of AG blocks as log2 (number of bits to shift left). */
149 uint8_t cAgBlocksLog;
150 /** Number of extent blocks as log2. */
151 uint8_t cExtentsRtDevLog;
152 /** Flag when the filesystem is in the process of being created. */
153 uint8_t fInProgress;
154 /** Maximum percentage of the filesystem usable for inodes. */
155 uint8_t cInodeMaxPct;
156 /** Global number of inodes allocated (only mainted on the first superblock). */
157 uint64_t cInodesGlobal;
158 /** Global number of free inodes (only mainted on the first superblock). */
159 uint64_t cInodesGlobalFree;
160 /** Global count of free data blocks on the filesystem (only mainted on the first superblock). */
161 uint64_t cBlocksFree;
162 /** Global count of free extents on the real-time device (only mainted on the first superblock). */
163 uint64_t cExtentsRtFree;
164 /** Inode containing the user quotas. */
165 XFSINO uInodeQuotaUsr;
166 /** Inode containing the group/project quotas. */
167 XFSINO uInodeQuotaGrp;
168 /** Quota flags. */
169 uint16_t fQuotaFlags;
170 /** Misc flags. */
171 uint8_t fFlagsMisc;
172 /** Reserved MBZ. */
173 uint8_t uSharedVn;
174 /** Number of filesystem blocks for the inode chunk alignment. */
175 XFSEXTLEN cBlocksInodeAlignment;
176 /** Raid stripe size in blocks. */
177 uint32_t cBlocksRaidStripe;
178 /** Raid width in number of blocks. */
179 uint32_t cBlocksRaidWidth;
180 /** Multiplier for determining the allocation size for directory blocks as log2. */
181 uint8_t cDirBlockAllocLog;
182 /** Sub volume sector size as log2 if an external journal device is used. */
183 uint8_t cLogDevSubVolSectorSzLog;
184 /** Sector size of the device an external journal is stored as log2. */
185 uint16_t cLogDevSectorSzLog;
186 /** Log devices stripe size. */
187 uint32_t cLogDevRaidStripe;
188 /** Additional features which may be active. */
189 uint32_t fFeatures2;
190 /** Padding. */
191 uint32_t u32Padding0;
192 /** From here follow data only available from version 5 and later. */
193 /** Read/Write feature flags. */
194 uint32_t fFeaturesRw;
195 /** Read-only feature flags. */
196 uint32_t fFeaturesRo;
197 /** Read/Write incompatible feature flags. */
198 uint32_t fFeaturesIncompatRw;
199 /** Read/Write incompatible feature flags for the journal. */
200 uint32_t fFeaturesJrnlIncompatRw;
201 /** CRC32 checksum for the superblock. */
202 uint32_t u32Chksum;
203 /** Sparse inode alignment. */
204 uint32_t u32SparseInodeAlignment;
205 /** Project quota inode. */
206 XFSINO uInodeProjectQuota;
207 /** Log sequence number of last superblock update. */
208 uint64_t uJrnlSeqSbUpdate;
209 /** UUID used when INCOMPAT_META_UUID is used. */
210 uint8_t abUuidMeta[16];
211 /** Inode if INCOMPATMETA_RMAPBT is used. */
212 XFSINO uInodeRm;
213} XFSSUPERBLOCK;
214#pragma pack()
215AssertCompileSize(XFSSUPERBLOCK, 272);
216/** Pointer to an XFS superblock. */
217typedef XFSSUPERBLOCK *PXFSSUPERBLOCK;
218/** Pointer to a const XFS superblock. */
219typedef const XFSSUPERBLOCK *PCXFSSUPERBLOCK;
220
221/** XFS superblock magic. */
222#define XFS_SB_MAGIC RT_MAKE_U32_FROM_U8('B', 'S', 'F', 'X')
223
224/** @name XFS_SB_VERSION_F_XXX - Version/Feature flags.
225 * @{ */
226/** Retrieves the version part of the field. */
227#define XFS_SB_VERSION_GET(a_fVersion) ((a_fVersion) & 0xf)
228/** Version number for filesystem 5.3, 6.0.1 and 6.1. */
229#define XFS_SB_VERSION_1 1
230/** Version number for filesystem 6.2 - attributes. */
231#define XFS_SB_VERSION_2 2
232/** Version number for filesystem 6.2 - new inode version. */
233#define XFS_SB_VERSION_3 3
234/** Version number for filesystem 6.2+ - new bitmask version. */
235#define XFS_SB_VERSION_4 4
236/** Introduced checksums in the metadata. */
237#define XFS_SB_VERSION_5 5
238/** Extended attributes are used for at least one inode. */
239#define XFS_SB_VERSION_F_ATTR RT_BIT_32(4)
240/** At least one inode use 32-bit nlink values. */
241#define XFS_SB_VERSION_F_NLINK RT_BIT_32(5)
242/** Quotas are enabled on the filesystem. */
243#define XFS_SB_VERSION_F_QUOTA RT_BIT_32(6)
244/** Set if XFSSUPERBLOCK::cBlocksInodeAlignment is used. */
245#define XFS_SB_VERSION_F_ALIGN RT_BIT_32(7)
246/** Set if XFSSUPERBLOCK::cBlocksRaidStripe and XFSSUPERBLOCK::cBlocksRaidWidth are used. */
247#define XFS_SB_VERSION_F_DALIGN RT_BIT_32(8)
248/** Set if XFSSUPERBLOCK::uSharedVn is used. */
249#define XFS_SB_VERSION_F_SHARED RT_BIT_32(9)
250/** Version 2 journaling is used. */
251#define XFS_SB_VERSION_F_LOGV2 RT_BIT_32(10)
252/** Set if sector size is not 512 bytes. */
253#define XFS_SB_VERSION_F_SECTOR RT_BIT_32(11)
254/** Set if unwritten extents are used (always set). */
255#define XFS_SB_VERSION_F_EXTFLG RT_BIT_32(12)
256/** Version 2 directories are used (always set). */
257#define XFS_SB_VERSION_F_DIRV2 RT_BIT_32(13)
258/** Set if XFSSUPERBLOCK::fFeatures2 is used. */
259#define XFS_SB_VERSION_F_FEAT2 RT_BIT_32(14)
260/** @} */
261
262/** @name XFS_SB_QUOTA_F_XXX - Quota flags
263 * @{ */
264/** User quota accounting enabled. */
265#define XFS_SB_QUOTA_F_USR_ACCT RT_BIT(0)
266/** User quotas are enforced. */
267#define XFS_SB_QUOTA_F_USR_ENFD RT_BIT(1)
268/** User quotas have been checked and updated on disk. */
269#define XFS_SB_QUOTA_F_USR_CHKD RT_BIT(2)
270/** Project quota accounting is enabled. */
271#define XFS_SB_QUOTA_F_PROJ_ACCT RT_BIT(3)
272/** Other quotas are enforced. */
273#define XFS_SB_QUOTA_F_OTH_ENFD RT_BIT(4)
274/** Other quotas have been checked and updated on disk. */
275#define XFS_SB_QUOTA_F_OTH_CHKD RT_BIT(5)
276/** Group quota accounting enabled. */
277#define XFS_SB_QUOTA_F_GRP_ACCT RT_BIT(6)
278/** @} */
279
280/** @name XFS_SB_FEATURES2_F_XXX - Additional features
281 * @{ */
282/** Global counters are lazy and are only updated when the filesystem is cleanly unmounted. */
283#define XFS_SB_FEATURES2_F_LAZYSBCOUNT RT_BIT_32(1)
284/** Extended attributes version 2. */
285#define XFS_SB_FEATURES2_F_ATTR2 RT_BIT_32(3)
286/** Parent pointers, inodes must have an extended attribute pointing to the parent inode. */
287#define XFS_SB_FEATURES2_F_PARENT RT_BIT_32(4)
288/** @} */
289
290
291/**
292 * XFS AG free space block.
293 */
294typedef struct XFSAGF
295{
296 /** Magic number. */
297 uint32_t u32Magic;
298 /** Header version number. */
299 uint32_t uVersion;
300 /** AG number for the sector. */
301 uint32_t uSeqNo;
302 /** Length of the AG in filesystem blocks. */
303 uint32_t cLengthBlocks;
304 /** Block numbers for the roots of the free space B+trees. */
305 uint32_t auRoots[3];
306 /** Depths of the free space B+trees. */
307 uint32_t acLvls[3];
308 /** Index of the first free list block. */
309 uint32_t idxFreeListFirst;
310 /** Index of the last free list block. */
311 uint32_t idxFreeListLast;
312 /** Number of blocks in the free list. */
313 uint32_t cFreeListBlocks;
314 /** Current number of free blocks in the AG. */
315 uint32_t cFreeBlocks;
316 /** Longest number of contiguous free blocks in the AG. */
317 uint32_t cFreeBlocksLongest;
318 /** Number of blocks used for the free space B+-trees. */
319 uint32_t cBlocksBTrees;
320 /** UUID of filesystem the AG belongs to. */
321 uint8_t abUuid[16];
322 /** Number of blocks used for the reverse map. */
323 uint32_t cBlocksRevMap;
324 /** Number of blocks used for the refcount B+-tree. */
325 uint32_t cBlocksRefcountBTree;
326 /** Block number for the refcount tree root. */
327 uint32_t uRootRefcount;
328 /** Depth of the refcount B+-tree. */
329 uint32_t cLvlRefcount;
330 /** Reserved contiguous space for future extensions. */
331 uint64_t au64Rsvd[14];
332 /** Last write sequence number. */
333 uint64_t uSeqNoLastWrite;
334 /** CRC of the AGF. */
335 uint32_t uChkSum;
336 /** Padding to 64 bit alignment. */
337 uint32_t uAlignment0;
338} XFSAGF;
339/** Pointer to a AG free space block. */
340typedef XFSAGF *PXFSAGF;
341/** Poiner to a const AG free space block. */
342typedef const XFSAGF *PCXFSAGF;
343
344/** AGF magic. */
345#define XFS_AGF_MAGIC RT_MAKE_U32_FROM_U8('F', 'G', 'A', 'X')
346/** The current valid AGF version. */
347#define XFS_AGF_VERSION 1
348
349
350/**
351 * XFS AG inode information.
352 */
353typedef struct XFSAGI
354{
355 /** Magic number. */
356 uint32_t u32Magic;
357 /** Header version number. */
358 uint32_t uVersion;
359 /** AG number for the sector. */
360 uint32_t uSeqNo;
361 /** Length of the AG in filesystem blocks. */
362 uint32_t cLengthBlocks;
363 /** Count of allocated inodes. */
364 uint32_t cInodesAlloc;
365 /** Block number of the inode tree root. */
366 uint32_t uRootInode;
367 /** Depth of the inode B+-tree. */
368 uint32_t cLvlsInode;
369 /** Newest allocated inode. */
370 uint32_t uInodeNew;
371 /** Last directory inode chunk. */
372 uint32_t uInodeDir;
373 /** Hash table of unlinked but still referenced inodes. */
374 uint32_t au32HashUnlinked[64];
375 /** UUID of filesystem. */
376 uint8_t abUuid[16];
377 /** CRC of the AGI. */
378 uint32_t uChkSum;
379 /** Padding. */
380 uint32_t uAlignment0;
381 /** Last write sequence number. */
382 uint64_t uSeqNoLastWrite;
383 /** Block number of the free inode tree. */
384 uint32_t uRootFreeInode;
385 /** Depth of the free inode B+-tree. */
386 uint32_t cLvlsFreeInode;
387} XFSAGI;
388/** Pointer to a AG inode information. */
389typedef XFSAGI *PXFSAGI;
390/** Pointer to a const AG inode information. */
391typedef const XFSAGI *PCXFSAGI;
392
393/** AGI magic. */
394#define XFS_AGI_MAGIC RT_MAKE_U32_FROM_U8('I', 'G', 'A', 'X')
395/** The current valid AGI version. */
396#define XFS_AGI_VERSION 1
397
398
399/**
400 * XFS timestamp structure.
401 */
402typedef struct XFSTIMESTAMP
403{
404 /** 0x00: The second part of the timestamp since the epoch. */
405 int32_t cSecEpoch;
406 /** 0x04: Nanosecond part of the timestamp. */
407 int32_t cNanoSec;
408} XFSTIMESTAMP;
409/** Pointer to a XFS timestamp. */
410typedef XFSTIMESTAMP *PXFSTIMESTAMP;
411/** Poiner to a const CFS timestamp. */
412typedef const XFSTIMESTAMP *PCXFSTIMESTAMP;
413
414
415/**
416 * The inode core structure.
417 */
418typedef struct XFSINODECORE
419{
420 /** 0x00: Magic value. */
421 uint16_t u16Magic;
422 /** 0x02: File mode and access bits (XFS_INODE_MODE_XXX). */
423 uint16_t fMode;
424 /** 0x04: Inode version. */
425 int8_t iVersion;
426 /** 0x05: The format of the data fork. */
427 int8_t enmFormat;
428 /** 0x06: Number of links to this inode from directories for v1 inodes. */
429 uint16_t cOnLinks;
430 /** 0x08: Owners UID. */
431 uint32_t uUid;
432 /** 0x0c: Owners GID. */
433 uint32_t uGid;
434 /** 0x10: The number of links to this inode for v2 inodes. */
435 uint32_t cLinks;
436 /** 0x14: Project ID for v2 inodes (not used for v1, low 16bits). */
437 uint16_t uProjIdLow;
438 /** 0x16: Project ID for v2 inodes (not used for v1, high 16bits). */
439 uint16_t uProjIdHigh;
440 /** 0x18: Padding. */
441 uint8_t abPad0[6];
442 /** 0x1e: Flush counter. */
443 uint16_t cFlush;
444 /** 0x20: Last accessed timestamp. */
445 XFSTIMESTAMP TsLastAccessed;
446 /** 0x28: Last modified timestamp. */
447 XFSTIMESTAMP TsLastModified;
448 /** 0x30: Inode created/modified timestamp. */
449 XFSTIMESTAMP TsCreatedModified;
450 /** 0x38: Number of bytes in the file. */
451 uint64_t cbInode;
452 /** 0x40: Number of direct and B-Tree blocks used for the forks. */
453 uint64_t cBlocks;
454 /** 0x48: Minimum extent size for the inode. */
455 uint32_t cExtentBlocksMin;
456 /** 0x4c: Number of extents in the data fork. */
457 uint32_t cExtentsData;
458 /** 0x50: Number of extents in the attribute fork. */
459 uint16_t cExtentsAttr;
460 /** 0x52: Offset of the attribute fork from the start of the inode. */
461 uint8_t offAttrFork;
462 /** 0x53: Attribute fork format. */
463 int8_t enmFormatAttr;
464 /** 0x54: DMIG event mask. */
465 uint32_t fEvtMaskDmig;
466 /** 0x58: DMIG state info. */
467 uint16_t uStateDmig;
468 /** 0x5a: Inode flags. */
469 uint16_t fFlags;
470 /** 0x5c: Generation number. */
471 uint32_t cGeneration;
472 /** 0x60: AGI unlinked list pointer. */
473 uint32_t offBlockUnlinkedNext;
474 /** The following fields are for v3 inodes only. */
475 /** 0x64: The CRC of the inode. */
476 uint32_t uChkSum;
477 /** 0x68: Number of attribute changes. */
478 uint64_t cAttrChanges;
479 /** 0x70: Last flush sequence number. */
480 uint64_t uFlushSeqNo;
481 /** 0x78: Additional flags. */
482 uint64_t fFlags2;
483 /** 0x80: Basic COW extent size. */
484 uint32_t cExtentCowMin;
485 /** 0x84: Padding for future expansion. */
486 uint8_t abPad1[12];
487 /** 0x90: Inode creation timestamp. */
488 XFSTIMESTAMP TsCreation;
489 /** 0x98: The inode number. */
490 uint64_t uInode;
491 /** 0x100: Filesystem UUID the inode belongs to. */
492 uint8_t abUuid[16];
493} XFSINODECORE;
494AssertCompileSizeAlignment(XFSINODECORE, 8);
495/** Pointer to a inode core. */
496typedef XFSINODECORE *PXFSINODECORE;
497/** Pointer to a const inode core. */
498typedef const XFSINODECORE *PCXFSINODECORE;
499
500/** Inode magic. */
501#define XFS_INODE_MAGIC RT_MAKE_U16_FROM_U8('N', 'I')
502
503/** @name XFS_INODE_MODE_XXX - File mode
504 * @{ */
505/** Others can execute the file. */
506#define XFS_INODE_MODE_EXEC_OTHER RT_BIT(0)
507/** Others can write to the file. */
508#define XFS_INODE_MODE_WRITE_OTHER RT_BIT(1)
509/** Others can read the file. */
510#define XFS_INODE_MODE_READ_OTHER RT_BIT(2)
511/** Members of the same group can execute the file. */
512#define XFS_INODE_MODE_EXEC_GROUP RT_BIT(3)
513/** Members of the same group can write to the file. */
514#define XFS_INODE_MODE_WRITE_GROUP RT_BIT(4)
515/** Members of the same group can read the file. */
516#define XFS_INODE_MODE_READ_GROUP RT_BIT(5)
517/** Owner can execute the file. */
518#define XFS_INODE_MODE_EXEC_OWNER RT_BIT(6)
519/** Owner can write to the file. */
520#define XFS_INODE_MODE_WRITE_OWNER RT_BIT(7)
521/** Owner can read the file. */
522#define XFS_INODE_MODE_READ_OWNER RT_BIT(8)
523/** Sticky file mode. */
524#define XFS_INODE_MODE_STICKY RT_BIT(9)
525/** File is set GID. */
526#define XFS_INODE_MODE_SET_GROUP_ID RT_BIT(10)
527/** File is set UID. */
528#define XFS_INODE_MODE_SET_USER_ID RT_BIT(11)
529/** @} */
530
531/** @name XFS_INODE_MODE_TYPE_XXX - File type
532 * @{ */
533/** Inode represents a FIFO. */
534#define XFS_INODE_MODE_TYPE_FIFO UINT16_C(0x1000)
535/** Inode represents a character device. */
536#define XFS_INODE_MODE_TYPE_CHAR UINT16_C(0x2000)
537/** Inode represents a directory. */
538#define XFS_INODE_MODE_TYPE_DIR UINT16_C(0x4000)
539/** Inode represents a block device. */
540#define XFS_INODE_MODE_TYPE_BLOCK UINT16_C(0x6000)
541/** Inode represents a regular file. */
542#define XFS_INODE_MODE_TYPE_REGULAR UINT16_C(0x8000)
543/** Inode represents a symlink. */
544#define XFS_INODE_MODE_TYPE_SYMLINK UINT16_C(0xa000)
545/** Inode represents a socket. */
546#define XFS_INODE_MODE_TYPE_SOCKET UINT16_C(0xc000)
547/** Returns the inode type from the combined mode field. */
548#define XFS_INODE_MODE_TYPE_GET_TYPE(a_Mode) ((a_Mode) & 0xf000)
549/** @} */
550
551/** @name XFS_INODE_FORMAT_XXX - Inode data fork format.
552 * @{ */
553/** Device node data. */
554#define XFS_INODE_FORMAT_DEV 0
555/** Inline data. */
556#define XFS_INODE_FORMAT_LOCAL 1
557/** Array of extent descriptors. */
558#define XFS_INODE_FORMAT_EXTENTS 2
559/** Data fork contains root of B-Tree. */
560#define XFS_INODE_FORMAT_BTREE 3
561/** Data fork contains UUID. */
562#define XFS_INODE_FORMAT_UUID 4
563/** @} */
564
565/** @name XFS_INODE_F_XXX - Inode flags.
566 * @{ */
567/** File data blocks are stored in the real-time device area. */
568#define XFS_INODE_F_RTDEV RT_BIT(0)
569/** File space has been pre-allocated. */
570#define XFS_INODE_F_PREALLOC RT_BIT(1)
571/** Use new real-time bitmap format. */
572#define XFS_INODE_F_NEWRTBITMAP RT_BIT(2)
573/** Inode is immutable. */
574#define XFS_INODE_F_IMMUTABLE RT_BIT(3)
575/** Inode is append only. */
576#define XFS_INODE_F_APPEND RT_BIT(4)
577/** Inode is written synchronously. */
578#define XFS_INODE_F_SYNC RT_BIT(5)
579/** The last accessed timestamp is not updated. */
580#define XFS_INODE_F_NOATIME RT_BIT(6)
581/** The inode is not dumpable via dump(1). */
582#define XFS_INODE_F_NODUMP RT_BIT(7)
583/** Create with real-time bit set. */
584#define XFS_INODE_F_RTINHERIT RT_BIT(8)
585/** Create with parents project ID. */
586#define XFS_INODE_F_PROJIDINHERIT RT_BIT(9)
587/** Deny symlink creation. */
588#define XFS_INODE_F_NOSYMLINKS RT_BIT(10)
589/** Inode extent size allocator hint. */
590#define XFS_INODE_F_EXTSIZEHINT RT_BIT(11)
591/** Inode extent size is inherited. */
592#define XFS_INODE_F_EXTSIZEINHERIT RT_BIT(12)
593/** Do not defrag/reorganize the inode. */
594#define XFS_INODE_F_NODEFRAG RT_BIT(13)
595/** Use filestream allocator. */
596#define XFS_INODE_F_FILESTREAM RT_BIT(14)
597/** @} */
598
599/** @name XFS_INODE_F2_XXX - Inode flags number 2 (XFSINODECORE::fFlags2).
600 * @{ */
601/** Use DAX for the inode. */
602#define XFS_INODE_F2_DAX RT_BIT_64(0)
603/** Blocks use reference counting for sharing. */
604#define XFS_INODE_F2_REFLINK RT_BIT_64(1)
605/** Inode COW extent size hint is valid. */
606#define XFS_INODE_F2_COWEXTSIZEHINT RT_BIT_64(2)
607/** @} */
608
609
610/**
611 * Inode B-Tree record.
612 */
613typedef struct XFSINODEBTREEREC
614{
615 /** 0x00: Starting inode number. */
616 uint32_t uInodeStart;
617 /** 0x04: Version dependent data. */
618 union
619 {
620 /** Full (old) version. */
621 struct
622 {
623 /** 0x04: Number of free inodes. */
624 uint32_t cInodesFree;
625 } Full;
626 /** Sparse (new) version. */
627 struct
628 {
629 /** 0x04: Hole mask for sparse chunks. */
630 uint16_t bmHoles;
631 /** 0x06: Total number of inodes. */
632 uint8_t cInodes;
633 /** 0x07: Number of free inodes. */
634 uint8_t cInodesFree;
635 } Sparse;
636 } u;
637 /** 0x08: Free inode mask. */
638 uint64_t bmInodesFree;
639} XFSINODEBTREEREC;
640/** Pointer to an inode B-Tree record. */
641typedef XFSINODEBTREEREC *PXFSINODEBTREEREC;
642/** Pointer to a const inode B-Tree record. */
643typedef const XFSINODEBTREEREC *PCXFSINODEBTREEREC;
644
645
646/**
647 * XFS B+Tree root header.
648 */
649typedef struct XFSBTREEROOTHDR
650{
651 /** 0x00: Tree level. */
652 uint16_t iLvl;
653 /** 0x02: Number of records. */
654 uint16_t cRecs;
655} XFSBTREEROOTHDR;
656/** Pointer to a B+Tree root header */
657typedef XFSBTREEROOTHDR *PXFSBTREEROOTHDR;
658/** Pointer to a const B+Tree root header. */
659typedef const XFSBTREEROOTHDR *PCXFSBTREEROOTHDR;
660
661
662/**
663 * XFS B+Tree intermediate/leave node header.
664 */
665typedef struct XFSBTREENODEHDR
666{
667 /** 0x00: Magic identifying the node. */
668 uint32_t u32Magic;
669 /** 0x04: Tree level. */
670 uint16_t iLvl;
671 /** 0x06: Number of records. */
672 uint16_t cRecs;
673 /** 0x08: Block number of the left sibling. */
674 uint64_t uSibLeft;
675 /** 0x10: Block number of the right sibling. */
676 uint64_t uSibRight;
677} XFSBTREENODEHDR;
678/** Pointer to a B+Tree intermediate/leave node header. */
679typedef XFSBTREENODEHDR *PXFSBTREENODEHDR;
680/** Pointer to a const B+Tree intermediate/leave node header. */
681typedef const XFSBTREENODEHDR *PCXFSBTREENODEHDR;
682
683/** @name XFS_BTREENODEHDR_XXX - B+Tree node related defines.
684 * @{ */
685/** Magic for the tree node header. */
686#define XFS_BTREENODEHDR_MAGIC RT_MAKE_U32_FROM_U8('P', 'A', 'M', 'B')
687/** @} */
688
689
690/**
691 * XFS Extent.
692 */
693typedef struct XFSEXTENT
694{
695 /** 0x00: Low 64 bits. */
696 uint64_t u64Low;
697 /** 0x08: High 64 bits. */
698 uint64_t u64High;
699} XFSEXTENT;
700/** Pointer to an XFS extent. */
701typedef XFSEXTENT *PXFSEXTENT;
702/** Pointer to a const XFS extent. */
703typedef const XFSEXTENT *PCXFSEXTENT;
704
705/** @name XFS_EXTENT_XXX - Extent related getters.
706 * @{ */
707/** Returns whether the extent is allocated but unwritten (true) or a normal extent (false). */
708#define XFS_EXTENT_IS_UNWRITTEN(a_pExtent) (RT_BOOL((a_pExtent)->u64High & RT_BIT_64(63)))
709/** Returns the number of blocks the extent covers. */
710#define XFS_EXTENT_GET_BLOCK_COUNT(a_pExtent) ((a_pExtent)->u64Low & UINT64_C(0x1fffff))
711/** Returns the absolute block number where the data is stored on the disk. */
712#define XFS_EXTENT_GET_DISK_BLOCK(a_pExtent) ( (((a_pExtent)->u64High & UINT64_C(0x1ff)) << 42) \
713 | (((a_pExtent)->u64Low & UINT64_C(0xffffffffffe00000)) >> 21))
714/** Returns the logical inode block offset. */
715#define XFS_EXTENT_GET_LOGICAL_BLOCK(a_pExtent) (((a_pExtent)->u64High & UINT64_C(0x7ffffffffffffe00)) >> 9)
716/** @} */
717
718/** @} */
719
720#endif /* !IPRT_INCLUDED_formats_xfs_h */
721
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