SquashFS

SquashFS is a compressed read-only Linux file system (2002) with fast random access, used for live CD and USB images, firmware of routers and NAS devices, and containers and snap packages. It is actively maintained in the kernel.

Overview

SquashFS packs files, directories and inodes into compressed metadata and data blocks. The superblock records the compression method, block size and the locations of the inode table, directory table, fragment table, ID table and export table. Small file tails are collected into shared fragment blocks. Supported compressors include zlib, LZO, LZMA, XZ, LZ4 and zstd depending on version.

History

  • Written by Phillip Lougher in 2002.
  • Merged into the Linux kernel in 2.6.29 (2009).
  • Later versions added XZ, LZ4 and zstd compression.

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.

Get Children

OffsetSizeTypeFieldNotes
at4u32 LECount
at2u16 LEOffset
at + 22i16 LEDelta
at + 44u32 LEStart Block
at + 42u16 LEType
at + 62u16 LEName Length
at + 84i32 LEBase Number

Read Inode

OffsetSizeTypeFieldNotes
24 + length4u32 LE–
headerLength + i * 44u32 LE–

Read Inode

OffsetSizeTypeFieldNotes
0x02u16 LEType
0x22u16 LEOde
0x108u64 LEStart
0x182u16 LESize
0x188u64 LESize
0x1A2u16 LEOffset
0x222u16 LEOffset
at2u16 LEIndex
at4u32 LE–

Read Xattrs

OffsetSizeTypeFieldNotes
0x02u16 LEType
0x22u16 LEName Length

Squash Fs File System

OffsetSizeTypeFieldNotes
0x08u64 LEXattr Table Start
0x84u32 LECount

Squash Fs File System

OffsetSizeTypeFieldNotes
i * 16 + 84u32 LEI
i * 16 + 124u32 LEI
i * 168u64 LEI

Parse

OffsetSizeTypeFieldNotes
0x04u32 LE–
0x44u32 LEInodes
0x84u32 LEMkfs Time
0xC4u32 LEBlock Size
0x104u32 LEFragments
0x142u16 LECompression
0x182u16 LEFlags
0x1A2u16 LEId Count
0x1C2u16 LEMajor
0x1E2u16 LEMinor
0x208u64 LERoot Inode
0x288i64 LEBytes Used
0x308i64 LEId Table Start
0x388i64 LEXattr Id Table Start
0x408i64 LEInode Table Start
0x488i64 LEDirectory Table Start
0x508i64 LEFragment Table Start

Other fields read

Read inOffsetSizeTypeFieldNotes
Metadata Block0x02u16 LEWord
Read Tablei * 88u64 LEPosition
Read Xattrs4u32 LELength
Read Xattrs4u32 LEValue Length
Read Xattrs0x08u64 LEValue Reference
Squash Fs File Systemi * 44u32 LEI
Probe0x04u32 LEAgic

Constants

Squash Fs Superblock

NameValueTypeNotes
Magic0x73717368uint“hsqs”
Size96int

Squash Fs File System

NameValueTypeNotes
MetadataSize8192int
UncompressedMetadata0x8000ushort
UncompressedData1 << 24uint
NoFragment0xFFFFFFFFuint
Sector512int

Squash Fs File Stream

NameValueTypeNotes
UncompressedData1 << 24uint

Implementation limits

ClassNameValueNotes
Squash Fs File SystemMaxCachedBlocks512
Structures and constants were extracted from the implementation. Prose sections are a summary from public sources; verify details before relying on them.