UFS (Unix File System)

UFS is the Berkeley fast file system and its descendants, used by BSD systems (FreeBSD, NetBSD, OpenBSD), Solaris and older commercial Unix. FreeBSD still uses UFS2 on some installs, but the family is mostly legacy elsewhere, and several on-disk variants differ by byte order and layout.

Overview

UFS divides the volume into cylinder groups, each with a group summary, inode bitmap and block bitmap. The superblock describes geometry and holds fragment and block sizes. UFS1 uses 32-bit block pointers; UFS2 uses 64-bit pointers and extended inodes. Byte order depends on the host that created the volume, so the implementation detects it.

History

  • Marshall Kirk McKusick developed the Fast File System for 4.2BSD (1983).
  • UFS2 appeared in FreeBSD 5.0 (2003).

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.

Parse Directory

OffsetSizeTypeFieldNotes
position4u32 LE/BEInode
position + 42u16 LE/BERecord Length

Scan Inode Tables

OffsetSizeTypeFieldNotes
0x02u16 LE/BEOde
0x22i16 LE/BELinks

Scan Slack

OffsetSizeTypeFieldNotes
position4u32 LE/BEInode
position + 42u16 LE/BERecord Length

Type And Name Length

OffsetSizeTypeFieldNotes
position + 62u16 LE/BE–
position + 61u8–
position + 71u8–

Walk Indirect

OffsetSizeTypeFieldNotes
i * width8i64 LE/BEChild
i * width4i32 LE/BEChild

Backup Index

OffsetSizeTypeFieldNotes
0x44u32 LE/BE–
0xC4u32 LE/BEGroup

Find Backup

OffsetSizeTypeFieldNotes
0x04u32 LELittle
0x04u32 BEBig

Try Parse

OffsetSizeTypeFieldNotes
0x44u32 LE/BE–
0xC4u32 LE/BE–
0x144u32 LE/BEFragments
0x604u32 LE/BEFree Offset
0x784u32 LE/BEInode Blocks Initialized
0x844u32 LE/BE–

Parse

OffsetSizeTypeFieldNotes
0x02u16 LE/BE–
0x02u16 LE/BEMode
0x22i16 LE/BELinks
0x44u32 LE/BEUid
0x84u32 LE/BEGid
0x88u64 LE/BESize
0x108u64 LE/BESize
0x104u32 LE/BEAccessed
0x144i32 LE/BEAccessed
0x188u64 LE/BEBlocks512
0x184u32 LE/BEModified
0x1C4i32 LE/BEModified
0x208i64 LE/BEAccessed
0x204u32 LE/BEChanged
0x244i32 LE/BEChanged
0x288i64 LE/BEModified
0x308i64 LE/BEChanged
0x388i64 LE/BECreated
0x404i32 LE/BEModified
0x444i32 LE/BEAccessed
0x484i32 LE/BEChanged
0x4C4i32 LE/BECreated
0x504u32 LE/BEGeneration
0x584u32 LE/BEFlags
0x5C4u32 LE/BEExt Attribute Size
0x644u32 LE/BEFlags
0x684u32 LE/BEBlocks512
0x6C4u32 LE/BEGeneration
0x704u32 LE/BEUid
0x744u32 LE/BEGid
0xF44u32 LE/BE–
40 + i * 44i32 LE/BE–
88 + i * 44i32 LE/BE–
112 + i * 88i64 LE/BE–
208 + i * 88i64 LE/BE–

Parse

OffsetSizeTypeFieldNotes
0x84i32 LE/BESblkno
0xC4i32 LE/BECblkno
0x104i32 LE/BEIblkno
0x144i32 LE/BEDblkno
0x184i32 LE/BEOld Cg Offset
0x1C4u32 LE/BEOld Cg Mask
0x204u32 LE/BETime
0x244i32 LE/BESize
0x284i32 LE/BEDsize
0x2C4i32 LE/BENcg
0x304i32 LE/BEBsize
0x344i32 LE/BEFsize
0x384i32 LE/BEFrag
0x684i32 LE/BESbsize
0x744i32 LE/BENindir
0x784i32 LE/BEInopb
0x904u32 LE/BEId High
0x944u32 LE/BEId Low
0xA04i32 LE/BECgsize
0xB84i32 LE/BEIpg
0xBC4i32 LE/BEFpg
0xC04i32 LE/BENdir
0xC44i32 LE/BENbfree
0xC84i32 LE/BENifree
0xCC4i32 LE/BENffree
0xD11u8Clean
0xD31u8Updated
0xD31u8Flags
0xD4468bytesMount Point
0x2A832bytesVolume Name
0x3E08i64 LE/BEActual Location
0x3E88i64 LE/BEPrimary Location
0x3F08i64 LE/BENdir
0x3F88i64 LE/BENbfree
0x4008i64 LE/BENifree
0x4088i64 LE/BENffree
0x4308i64 LE/BETime
0x4388i64 LE/BESize
0x4408i64 LE/BEDsize
0x5184u32 LE/BEStored Check Hash
0x51C4i32 LE/BEMeta Check Hash
0x5204i32 LE/BEFlags
0x5284i32 LE/BEMax Symlink Length
0x52C4i32 LE/BEOld Inode Format
1116 + i * 44u32 LE/BE–

Try Parse

OffsetSizeTypeFieldNotes
MagicOffset4u32 LELittle
MagicOffset4u32 BEBig

Other fields read

Read inOffsetSizeTypeFieldNotes
Has Root Directory0x02u16 LE/BE–

Constants

Ufs File System

NameValueTypeNotes
StrictUtf8new(false, true)UTF8Encoding

Ufs Byte Order

NameValueTypeNotes
Littlenew(false)UfsByteOrder
Bignew(true)UfsByteOrder

Ufs Constants

NameValueTypeNotes
Ufs1Magic0x00011954uint
Ufs2Magic0x19540119uint
CylinderGroupMagic0x00090255uint
MagicOffset1372int
StructSize1376int
SuperblockSpace8192int
SuperblockLocations[65536, 8192, 0, 262144]long[]
Group0BackupLocations[98304, 81920, 73728, 32768, 16384]long[]
DirectBlocks12int
IndirectLevels3int
DirectoryChunk512int
RootInode2uint
WhiteoutInode1uint

fs_flags

NameValueTypeNotes
FlagUnclean0x1int
FlagSoftUpdates0x2int
FlagNeedsFsck0x4int
FlagJournaledSoftUpdates0x8int
FlagAcls0x10int
FlagMultiLabel0x20int
FlagGJournal0x40int
FlagUpdated0x80int
FlagNfs4Acls0x100int
FlagMetaCheckHash0x200int
FlagTrim0x400int

fs_metackhash

NameValueTypeNotes
CheckSuperblock0x1int
CheckCylinderGroup0x2int
CheckInode0x4int

Ufs Inode

NameValueTypeNotes
TypeMask0xF000int
TypeFifo0x1000int
TypeCharDevice0x2000int
TypeDirectory0x4000int
TypeBlockDevice0x6000int
TypeRegular0x8000int
TypeSymlink0xA000int
TypeSocket0xC000int
TypeWhiteout0xE000int

chflags(2)

NameValueTypeNotes
UfImmutable0x2uint
UfAppend0x4uint
UfSystem0x80uint
UfArchive0x800uint
UfReadOnly0x1000uint
UfHidden0x8000uint
SfImmutable0x20000uint
SfAppend0x40000uint
SfSnapshot0x200000uint

Struct

NameValueTypeNotes
TypeDirectory4byte

Ufs Module

NameValueTypeNotes
BackupSearchWindow4 * 1024 * 1024int

FreeBSD 13+ records where each copy was written.

NameValueTypeNotes
step512int

Implementation limits

ClassNameValueNotes
Ufs File SystemMaxDirectoryBytes256L * 1024 * 1024
Ufs File SystemMaxBlocks64L * 1024 * 1024
Ufs File SystemMaxLostEntries200_000
Ufs File SystemMaxDirectoriesScanned1_000_000
Ufs File SystemMaxCachedGroups256
Ufs File SystemMaxSymlinkTarget4096
Ufs ModuleBackupSearchLimit1L << 30

Entry Kind

NameValue
Live(next)
Unlinked(next)
Structures and constants were extracted from the implementation. Prose sections are a summary from public sources; verify details before relying on them.