Jump to content
Setting up an AI agent? ReverseEngineering.wiki skill (works from the command line, no configuration): https://reverseengineering.wiki/skill/rewiki/SKILL.md · setup for every client, including MCP: https://reverseengineering.wiki/llms.txt · REWiki:Connect

Format:PFS0 and HFS0

From ReverseEngineering.wiki
Format
Vendor Nintendo
Magic 50 46 53 30 ("PFS0") or 48 46 53 30 ("HFS0") at offset 0
Extensions .nsp, .nca section, ExeFS
Endianness little
On this wiki Facts · Code · Notes · Topics

Nintendo Switch partition filesystems: PFS0 (magic PFS0; .nsp installable packages, ExeFS, NCA code/logo sections) and HFS0 (magic HFS0; the partitions of an XCI game card, with a SHA-256 per file). Both are a 0x10-byte header, a file entry table and a string table followed by the file data.

Overview

PFS0 ("partition filesystem") and HFS0 ("hashed partition filesystem") are the two flat archive formats of the Switch. A PFS0 is the container of an .nsp package (the NCAs, tickets and certificates are its files), and also the filesystem inside the code (ExeFS) and logo sections of a program NCA. A HFS0 appears inside Format:XCI game card images, where the root HFS0 holds partitions (update, normal, secure, logo) that are themselves HFS0. Both have no directories: names are plain strings in a string table.

Layout

Header (0x10 bytes): magic, file count, string table size, 4 reserved bytes. After it come num_files entries and then the string table; file data starts right after the string table, so the data offset of a file is 0x10 + num_files * entry_size + string_table_size + entry.offset. Entry names are NUL-terminated strings at string_table_offset.

  • PFS0 entry: 0x18 bytes, u64 offset, u64 size, u32 string table offset, u32 reserved.
  • HFS0 entry: 0x40 bytes, u64 offset, u64 size, u32 string table offset, u32 hashed size, 8 reserved bytes, SHA-256 (32 bytes) of the first hashed size bytes of the file. The hash is over the file data, not over the name.

See Fact:PFS0 and HFS0/struct/PFS0 header and entry and Fact:PFS0 and HFS0/struct/HFS0 header and entry.

Recognition

A PFS0 that contains main.npdm (an Format:NPDM whose magic is META) is an ExeFS: the other files are the Format:NSO modules (rtld, main, sdk, subsdk*) of the program. Inside an NCA the PFS0 sits behind a hash layer: the NCA's section header carries a superblock with a master hash, a block size, the hash table offset and size and the PFS0 offset and size (see Fact:PFS0 and HFS0/struct/PFS0 section superblock in an NCA). Encrypted NCA content must be decrypted first; keys are not documented here.

Unverified: the 8 reserved bytes of an HFS0 entry and the reserved field of the header are zero in retail files; hactool does not check them.

Related

Format:XCI, Format:NCA, Format:NPDM, Format:NSO, Platform:Nintendo Switch.

Code & repositories

See the repository listing below.

  • https://github.com/SciresM/hactool @ 1d64a83450e025622f3468c28fc4164dad2c5ef6 · license: ISC
    hactool (ISC): pfs0.h/pfs0.c and hfs0.h/hfs0.c define the PFS0 and HFS0 headers, entries and hash checks; nca.h/npdm.h/xci.h/kip.h cover NCA, NPDM, XCI and KIP1 headers.
    Tested on: source read, not run · checked 2026-10-19; last activity 2023-12-04; Note: the latest release ships binaries; the wiki links only the source, never the binaries