UBIFS (Unsorted Block Image File System)

UBIFS runs on top of UBI volumes on raw NAND flash and replaced JFFS2 on larger chips (Linux 2.6.27, 2008). It is common in routers, set-top boxes, cameras and other embedded devices, and is a frequent target in chip-off flash recovery.

Overview

UBI maps logical eraseblocks to physical ones, handling wear leveling, and carries an erase-counter header and a volume identifier header per block. UBIFS stores its data in nodes inside those logical blocks and keeps an on-flash B+-tree index, a log and a journal for quick mounting. Nodes have a common header with magic 0x06101831, and data may be compressed (LZO, zlib, zstd).

History

  • Developed by Nokia engineers (Artem Bityutskiy and Adrian Hunter) and merged into Linux 2.6.27 (2008).

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.

Is Ec Header

OffsetSizeTypeFieldNotes
0x01u8–
0x11u8–
0x21u8–
0x31u8–
0x41u8–UBI version
0x104u32 BEVid Offset
0x144u32 BEData Offset

Parse

OffsetSizeTypeFieldNotes
0x104u32 BEVid Offset
0x144u32 BEData Offset

Parse

OffsetSizeTypeFieldNotes
0x84u32 BEVol Id Raw
0xC4u32 BELnum
0x2C8u64 BESqnum

Has Ubifs Node

OffsetSizeTypeFieldNotes
p4u32 LE–
p + 164u32 LELen
p + 201u8Node Type

Constants

Ubi Image

NameValueTypeNotes
InternalVolStart0x7FFFEFFFuint
EcHdrSize64int
VidHdrSize64int

(volId, lnum) -> newest mapping.

NameValueTypeNotes
Step4096int

Ubifs File System Module

NameValueTypeNotes
NodeMagic0x06101831uint

Ubifs Reader

NameValueTypeNotes
NodeMagic0x06101831uint
ChSize24int

node types

NameValueTypeNotes
TypeIno0byte
TypeData1byte
TypeDent2byte

item (dentry) types

NameValueTypeNotes
ItypeReg0byte
ItypeDir1byte
ItypeLnk2byte

compression

NameValueTypeNotes
ComprNone0byte
ComprLzo1byte
ComprZlib2byte
ComprZstd3byte
BlockSize4096int
RootInode1uint
ScanCap256L * 1024 * 1024long
MaxFileBytes512 * 1024 * 1024int
MaxNodeLen2L * 1024 * 1024long
Structures and constants were extracted from the implementation. Prose sections are a summary from public sources; verify details before relying on them.