XFS

XFS is a high-performance 64-bit journaling file system created by Silicon Graphics for IRIX in 1993 and ported to Linux in the 2000s. It is the default on Red Hat Enterprise Linux and its derivatives and is common on servers, NAS and large-file workloads. It is actively developed in the Linux kernel.

Overview

XFS uses allocation groups, each with its own superblock copy, free space B+-trees and inode B+-tree, which allows parallel operation. Files are mapped by extents; small directories are stored inline in the inode and large ones as B+-trees. Metadata is big-endian. Version 5 adds metadata checksums and a UUID per structure.

History

  • Developed by SGI for IRIX (released 1994).
  • Ported to Linux in 2001 and merged into Linux 2.5.36.
  • The v5 on-disk format with checksums was introduced in Linux 3.10 (2013).

Structures

Offsets are in bytes from the start of the structure named in each heading. Field names are descriptive and are not an official specification. Fixed-width integers are shown as u/i (unsigned/signed) followed by bit width and byte order.

Extents

OffsetSizeTypeFieldNotes
0x02u16 BELevel
0x22u16 BERecords
4 + maxRecords * 8 + i * 88u64 BEChild

Parse Data Block

OffsetSizeTypeFieldNotes
0x04u32 BEAgic
position2u16 BE–
position8u64 BENumber
position + 22u16 BEFree
block.Length – 84u32 BELeaf Count
position + 81u8Name Length

Read Bmap Block

OffsetSizeTypeFieldNotes
0x04u32 BEAgic
0x42u16 BELevel
0x62u16 BERecords
header + maxRecords * 8 + i * 88u64 BEChild

Read Shortform Directory

OffsetSizeTypeFieldNotes
0x01u8Count
0x11u8Wide
0x11u8Total
inodeStart8u64 BENumber
inodeStart4u32 BENumber

Read Symlink

OffsetSizeTypeFieldNotes
0x04u32 BE–
0x84u32 BEBytes

Parse

OffsetSizeTypeFieldNotes
0x02u16 BE–
0x22u16 BEMode
0x41u8Version
0x51u8Format
0x62u16 BE–
0x84u32 BEUid
0xC4u32 BEGid
0x104u32 BE–
0x388u64 BESize
0x408u64 BEBlocks
0x4C4u32 BEExtent Count
0x521u8Fork Offset
0x5A2u16 BEFlags
0x788u64 BE–

Time

OffsetSizeTypeFieldNotes
offset8u64 BEValue
offset + 44u32 BENanoseconds

Try Parse

OffsetSizeTypeFieldNotes
0x04u32 BE–
0x44u32 BEBlock Size
0x88u64 BEData Blocks
0x388u64 BERoot Inode
0x544u32 BEAg Blocks
0x584u32 BEAg Count
0x642u16 BEVersion
0x662u16 BESector Size
0x682u16 BEInode Size
0x781u8Block Log
0x7A1u8Inode Log
0x7B1u8Inodes Per Block Log
0x7C1u8Ag Block Log
0x7E1u8In Progress
0x808u64 BEInode Count
0x888u64 BEFree Inodes
0x908u64 BEFree Data Blocks
0xC01u8Dir Block Log
0xC01u8–
0xC84u32 BEFeatures2
0xD84u32 BE–

Decode

OffsetSizeTypeFieldNotes
0x08u64 BEL0
0x88u64 BEL1

Other fields read

Read inOffsetSizeTypeFieldNotes
Has Inode At0x02u16 BE–

Constants

Directory data block magics

NameValueTypeNotes
DirBlockV40x58443242uintXD2B
DirDataV40x58443244uintXD2D
DirBlockV50x58444233uintXDB3
DirDataV50x58444433uintXDD3
BmapV40x424D4150uintBMAP
BmapV50x424D4133uintBMA3
SymlinkV50x58534C4DuintXSLM
DirLeafOffset32L * 1024 * 1024 * 1024long

Xfs Superblock

NameValueTypeNotes
Magic0x58465342uint“XFSB”

sb_features_incompat (v5) / sb_features2 (v4)

NameValueTypeNotes
IncompatFtype0x1uint
IncompatBigTime0x8uint
Features2Ftype0x200uint

Xfs Inode

NameValueTypeNotes
Magic0x494Eushort“IN”
FormatDevice0byte
FormatLocal1byte
FormatExtents2byte
FormatBtree3byte
FlagRealtime0x0001ushort
FlagImmutable0x0008ushort
FlagAppend0x0010ushort
Flag2BigTime0x0008ulong

Implementation limits

ClassNameValueNotes
Xfs File SystemMaxBtreeDepth10
Xfs File SystemMaxExtents4_000_000
Xfs File SystemMaxDirectoryBytes512L * 1024 * 1024
Xfs File SystemMaxSymlinkLength4096
Structures and constants were extracted from the implementation. Prose sections are a summary from public sources; verify details before relying on them.