In-depth Analysis of F2FS Filesystem Superblock, SIT, NAT, and SSA Structures
The article provides a detailed code-level walkthrough of F2FS’s superblock, Segment Information Table, Node Address Table, Summary Area, and Main Area structures, explaining each field, entry layout, and their roles in managing segments, inodes, and data within the filesystem.
Introduction: This article builds upon a previous overview of the F2FS filesystem organization and dives into the code-level details of various metadata structures.
Superblock structures: The superblock contains fields such as the magic number, version numbers, log sector size, block size parameters, segment counts, and addresses for different regions (CP, SIT, NAT, SSA, MA). Example values and explanations are provided for each field.
struct f2fs_super_block { __le32 magic; __le16 major_ver; __le16 minor_ver; __le32 log_sectorsize; __le32 log_sectors_per_block; __le32 log_blocksize; __le32 log_blocks_per_seg; __le32 segs_per_sec; __le32 secs_per_zone; __le32 checksum_offset; __le64 block_count; __le32 section_count; __le32 segment_count; __le32 segment_count_ckpt; __le32 segment_count_sit; __le32 segment_count_nat; __le32 segment_count_ssa; __le32 segment_count_main; __le32 segment0_blkaddr; __le32 cp_blkaddr; __le32 sit_blkaddr; __le32 nat_blkaddr; __le32 ssa_blkaddr; __le32 main_blkaddr; __le32 root_ino; __le32 node_ino; __le32 meta_ino; __u8 uuid[16]; __le16 volume_name[MAX_VOLUME_NAME]; __le32 extension_count; __u8 extension_list[F2FS_MAX_EXTENSION][F2FS_EXTENSION_LEN]; __le32 cp_payload; __u8 version[VERSION_LEN]; __u8 init_version[VERSION_LEN]; __le32 feature; __u8 encryption_level; __u8 encrypt_pw_salt[16]; struct f2fs_device devs[MAX_DEVICES]; __le32 qf_ino[F2FS_MAX_QUOTAS]; __u8 hot_ext_count; __le16 s_encoding; __le16 s_encoding_flags; __u8 s_stop_reason[MAX_STOP_REASON]; __u8 reserved[274]; __le32 crc; };
SIT (Segment Information Table) structures: The SIT block consists of an array of 55 f2fs_sit_entry structures. Each entry records the number of valid blocks, segment type, a bitmap of block usage, and the last garbage‑collection timestamp.
struct f2fs_sit_entry { __le16 vblocks; // lower 10 bits: valid blocks, upper 6 bits: segment type __u8 valid_map[SIT_VBLOCK_MAP_SIZE]; // 512‑bit bitmap for block usage in a 2 MiB segment __le64 mtime; // last GC time for the segment };
NAT (Node Address Table) structures: The NAT block holds an array of 455 f2fs_nat_entry structures. Each entry stores a version, inode number, and the block address where the corresponding node resides.
struct f2fs_nat_entry { __u8 version; __le32 ino; // inode number __le32 block_addr; // block address of the node };
SSA (Summary Area) structures: The SSA block contains a f2fs_summary_block which includes an array of f2fs_summary entries, a journal, and a footer. The summary entry records the node ID, version, and offset within the node. The footer stores the segment type and checksum.
struct f2fs_summary { __le32 nid; // node ID owning the block __u8 version; __le16 ofs_in_node; // offset inside the node };
MA (Main Area) structures: The MA region stores node and data blocks. Key node structures include f2fs_inode , direct_node , and indirect_node . The inode holds metadata, an array of block addresses ( i_addr ), and an array of node IDs ( i_nid ) pointing to direct, indirect, and double‑indirect nodes.
File layout: Depending on file size, F2FS uses direct, indirect, and double‑indirect nodes. Small files may be stored inline within the inode to save space.
Additional resources: Links to related articles on kernel preemption, the Linux V4L2 subsystem, and the SCHED_EXT scheduling extension are provided.
OPPO Kernel Craftsman
Sharing Linux kernel-related cutting-edge technology, technical articles, technical news, and curated tutorials
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.