<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.3dbrew.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Aspargas2</id>
	<title>3dbrew - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://www.3dbrew.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Aspargas2"/>
	<link rel="alternate" type="text/html" href="https://www.3dbrew.org/wiki/Special:Contributions/Aspargas2"/>
	<updated>2026-04-15T23:49:37Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.1</generator>
	<entry>
		<id>https://www.3dbrew.org/w/index.php?title=Savegames&amp;diff=21575</id>
		<title>Savegames</title>
		<link rel="alternate" type="text/html" href="https://www.3dbrew.org/w/index.php?title=Savegames&amp;diff=21575"/>
		<updated>2021-09-03T12:15:49Z</updated>

		<summary type="html">&lt;p&gt;Aspargas2: fix typos&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the format and encryption of savegames contained in gamecards, SD and NAND. You can find savegames from various 3DS games on the [[Games]] page.&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
Savegames are stored in [[DISA and DIFF|DISA container format]]. Inside the DISA container, it forms a [[Inner FAT|FAT filesystem]]. &#039;&#039;&#039;Please refer to these pages for how to fully extract save files&#039;&#039;&#039;. This page only describes additional encryption wear leveling on top of the DISA container. These layers only apply to gamecard save games. SD savegames and NAND savegames are DISA containers in plaintext after decrypting the common SD/NAND encryption layer.&lt;br /&gt;
&lt;br /&gt;
== Gamecard savegame Encryption ==&lt;br /&gt;
&lt;br /&gt;
Gamecard encryption is AES-CTR applied on top of DISA container, but below the wear leveling layer (if exists). The same key Y used for encryption is also used for DISA CMAC signing. Several versions of encryption scheme have been introduced over the time.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!  FW Introduced&lt;br /&gt;
!  Old3DS&lt;br /&gt;
!  [[AES#Keyslot|AES Keyslots]] (Encryption / CMAC)&lt;br /&gt;
!  KeyY generation method&lt;br /&gt;
!  Repeating CTR&lt;br /&gt;
|-&lt;br /&gt;
| The initial version&lt;br /&gt;
| style=&amp;quot;background: #ccffbb&amp;quot; | Yes&lt;br /&gt;
| 0x37 / 0x33&lt;br /&gt;
| v1&lt;br /&gt;
| style=&amp;quot;background: #ccffbb&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| [[2.0.0-2]]&lt;br /&gt;
| style=&amp;quot;background: #ccffbb&amp;quot; | Yes&lt;br /&gt;
| 0x37 / 0x33&lt;br /&gt;
| v2&lt;br /&gt;
| style=&amp;quot;background: #ccffbb&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| [[2.2.0-4]]&lt;br /&gt;
| style=&amp;quot;background: #ccffbb&amp;quot; | Yes&lt;br /&gt;
| 0x37 / 0x33&lt;br /&gt;
| v2&lt;br /&gt;
| style=&amp;quot;background: #ffccbb&amp;quot; | No&lt;br /&gt;
|-&lt;br /&gt;
| [[6.0.0-11]]&lt;br /&gt;
| style=&amp;quot;background: #ccffbb&amp;quot; | Yes&lt;br /&gt;
| 0x37 / 0x33&lt;br /&gt;
| v3&lt;br /&gt;
| style=&amp;quot;background: #ffccbb&amp;quot; | No&lt;br /&gt;
|-&lt;br /&gt;
| [[9.6.0-24|9.6.0-X]]&lt;br /&gt;
| style=&amp;quot;background: #ffccbb&amp;quot; | No&lt;br /&gt;
| 0x1A / 0x19&lt;br /&gt;
| v2?&lt;br /&gt;
| style=&amp;quot;background: #ffccbb&amp;quot; | No&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Repeating CTR Fail ===&lt;br /&gt;
On the 3DS savegames are stored much like on the DS, that is on a FLASH chip in the gamecart. On the DS these savegames were stored in plain-text but on the 3DS a layer of encryption was added. This is AES-CTR, as the contents of several savegames exhibit the odd behavior that xor-ing certain parts of the savegame together will result in the plain-text appearing.&lt;br /&gt;
&lt;br /&gt;
The reason this works is because the stream cipher used has a period of 512 bytes. That is to say, it will repeat the same keystream after 512 bytes. The way you encrypt with a stream cipher is you XOR your data with the keystream as it is produced. Unfortunately, if your streamcipher repeats and you are encrypting a known plain-text (in our case, zeros) you are basically giving away your valuable keystream.&lt;br /&gt;
&lt;br /&gt;
So how do you use this to decrypt a savegame on a 3DS? First off, you chunk up the savegame into 512 byte chunks. Then, you bin these chunks by their contents, discarding any that contain only FF. Now look for the most common chunk. This is your keystream. Now XOR the keystream with your original savegame and you should have a fully decrypted savegame. XOR with the keystream again to produce an encrypted savegame.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== KeyY Generation method ===&lt;br /&gt;
&lt;br /&gt;
The [[NCSD]] partition flags determine the method used to generate this keyY.&lt;br /&gt;
&lt;br /&gt;
==== v1 ====&lt;br /&gt;
&lt;br /&gt;
When all of the flags checked by the running NATIVE_FIRM are clear, the keyY is the following:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!  Offset&lt;br /&gt;
!  Size&lt;br /&gt;
!  Description&lt;br /&gt;
|-&lt;br /&gt;
| 0x0&lt;br /&gt;
| 0x8&lt;br /&gt;
| First 8-bytes from the plaintext [[NCCH#CXI|CXI]] accessdesc signature.&lt;br /&gt;
|-&lt;br /&gt;
| 0x8&lt;br /&gt;
| 0x4&lt;br /&gt;
| u32 CardID0 from [[Gamecards|gamecard]] plaintext-mode command 0x90, Process9 reads this with the [[NTRCARD]] hw. The actual cmdID used by Process9 is different since Process9 reads it with the gamecard in encrypted-mode.&lt;br /&gt;
|-&lt;br /&gt;
| 0xC&lt;br /&gt;
| 0x4&lt;br /&gt;
| u32 CardID1 from [[Gamecards|gamecard]] plaintext-mode command 0xA0, Process9 reads this with the [[NTRCARD]] hw. The actual cmdID used by Process9 is different since Process9 reads it with the gamecard in encrypted-mode.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== v2 ====&lt;br /&gt;
&lt;br /&gt;
Key Y is the first 0x10 bytes of SHA-256 calculated over the following data&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!  Offset&lt;br /&gt;
!  Size&lt;br /&gt;
!  Description&lt;br /&gt;
|-&lt;br /&gt;
| 0x0&lt;br /&gt;
| 0x8&lt;br /&gt;
| First 8-bytes from the plaintext [[NCCH#CXI|CXI]] accessdesc signature.&lt;br /&gt;
|-&lt;br /&gt;
| 0x8&lt;br /&gt;
| 0x40&lt;br /&gt;
| read from a gamecard command(this 0x40-byte data is also read by [[Process_Services_PXI|GetRomId]], which is the gamecard-uniqueID)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
This keyY generation method was implemented with [[2.0.0-2]] via NCSD partition flag[3], however the proper CTR wasn&#039;t implemented for flag[7] until [[2.2.0-4]]. The hashed keyY flag[3] implemented with [[2.0.0-2]] was likely never used with retail gamecards.&lt;br /&gt;
&lt;br /&gt;
==== v3 ====&lt;br /&gt;
&lt;br /&gt;
[[6.0.0-11]] implemented support for generating the savegame keyY with a new method, this method is much more complex than previous keyY methods. This is enabled via new [[NCSD]] partition flags, all retail games which have the NCSD image finalized after the [[6.0.0-11]] release(and [[6.0.0-11]]+ in the system update partition) will have these flags set for using this new method.&lt;br /&gt;
&lt;br /&gt;
First, a SHA-256 hash is calculated over the following data&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!  Offset&lt;br /&gt;
!  Size&lt;br /&gt;
!  Description&lt;br /&gt;
|-&lt;br /&gt;
| 0x0&lt;br /&gt;
| 0x8&lt;br /&gt;
| First 8-bytes from the plaintext [[NCCH#CXI|CXI]] accessdesc signature.&lt;br /&gt;
|-&lt;br /&gt;
| 0x8&lt;br /&gt;
| 0x40&lt;br /&gt;
| Same ID as [[Process_Services_PXI|GetRomId]]&lt;br /&gt;
|-&lt;br /&gt;
| 0x48&lt;br /&gt;
| 0x8&lt;br /&gt;
| CXI Program ID&lt;br /&gt;
|-&lt;br /&gt;
| 0x50&lt;br /&gt;
| 0x20&lt;br /&gt;
| ExeFS:/.code hash from the decrypted [[ExeFS]] header&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Then an [[AES]]-CMAC is calculated over this hash. The output CMAC is used for keyY. The key slot for this CMAC is 0x2F.&lt;br /&gt;
&lt;br /&gt;
The 0x2F keyY used for calculating this AES-CMAC (not to be confused with the final keyY for decrypting/signing savegames) is initialized while NATIVE_FIRM is loading, this keyY is generated via the [[RSA]] engine. The RSA slot used here is slot0(key-data for slot0 is initialized by bootrom), this RSA slot0 key-data is overwritten during system boot. This RSA slot0 key-data gets overwritten with the RSA key-data used for verifying RSA signatures, every time Process9 verifies any RSA signatures except for [[NCCH|NCCH]] accessdesc signatures. Starting with [[7.0.0-13]] this key-init function used at boot is also used to initialize a separate keyslot used for the new [[NCCH]] encryption method.&lt;br /&gt;
&lt;br /&gt;
This [[FIRM|Process9]] key-init function first checks if a certain 0x10-byte block in the 0x01FF8000 region is all-zero. When all-zero it immediately returns, otherwise it clears that block then continues to do the key generation. This is likely for supporting launching a v6.0+ NATIVE_FIRM under this FIRM.&lt;br /&gt;
&lt;br /&gt;
== Gamecard wear leveling ==&lt;br /&gt;
&lt;br /&gt;
The 3DS employs a wear leveling scheme on the savegame FLASH chips(only used for CARD1 gamecards). This is done through the usage of blockmaps and a journal. The blockmap is located at offset 0 of the flash chip, and is immediately followed by the journal. The initial state is dictated by the blockmap, and the journal is then applied to that.&lt;br /&gt;
&lt;br /&gt;
There are two versions of wear leveling have been observed. V1 is used for 128KB and 512 KB CARD1 flash chips. V2 is used for 1MB CARD1 flash chips (uncommon. Pokemon Sun/Moon is an example).&lt;br /&gt;
&lt;br /&gt;
First, there are two 32-bit integers whose purposes are currently unknown. They generally increase the value as the savegame is written more times, so probably counter for how many times the journal became full and got flushed into the block map, and/or how many times &amp;lt;code&amp;gt;alloc_cnt&amp;lt;/code&amp;gt; has wrapped around. &lt;br /&gt;
&lt;br /&gt;
Then comes the actual blockmap. The block map contains entries of 10 bytes (V1) or 2 bytes (V2) with total number of &amp;lt;code&amp;gt;(flash_size / 0x1000 - 1)&amp;lt;/code&amp;gt;. &lt;br /&gt;
The blockmap entry is simple:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
struct blockmap_entry_v1 {&lt;br /&gt;
        uint8_t phys_sec; // when bit7 is set, block is initialized and has checksums, otherwise checksums are all zero&lt;br /&gt;
        uint8_t alloc_cnt;&lt;br /&gt;
        uint8_t chksums[8];&lt;br /&gt;
} __attribute__((__packed__));&lt;br /&gt;
&lt;br /&gt;
struct blockmap_entry_v2 {&lt;br /&gt;
        // Note that the phys_sec and alloc_cnt field are swapped in v2, &lt;br /&gt;
        // but the initialized bit is still on the first byte&lt;br /&gt;
        uint8_t alloc_cnt; // when bit7 is set, block is initialized&lt;br /&gt;
        uint8_t phys_sec; &lt;br /&gt;
        // v2 has no chksums&lt;br /&gt;
} __attribute__((__packed__));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There&#039;s one entry per 0x1000-byte sector, counting from physical sector 1 (sector 0 contains the blockmap/journal).&lt;br /&gt;
&lt;br /&gt;
A 2-byte CRC16 follows the block map. For V1 it immediately follows the last block map entry. For V2 it is located at 0x3FE, and bytes before the CRC is padded with zero. The CRC16 checks all the bytes before it, including the two unknown integers, the block map, and the padding bytes for V2. The CRC standard used looks like CRC-16-IBM (modbus). Here is the code in Rust for it&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
fn crc16(data: &amp;amp;[u8]) -&amp;gt; u16 {&lt;br /&gt;
    let poly = 0xA001;&lt;br /&gt;
    let mut crc = 0xFFFFu16;&lt;br /&gt;
    for byte in data {&lt;br /&gt;
        crc ^= &amp;lt;u16&amp;gt;::from(*byte);&lt;br /&gt;
        for _ in 0..8 {&lt;br /&gt;
            let b = crc &amp;amp; 1 != 0;&lt;br /&gt;
            crc &amp;gt;&amp;gt;= 1;&lt;br /&gt;
            if b {&lt;br /&gt;
                crc ^= poly;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    crc&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then comes the journal. The journal contains entries that describes how sectors should be remapped. The rest bytes before 0x1000 after all journal entries are padded with 0xFF&lt;br /&gt;
The journal entry structure is as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
struct journal_entry_half {&lt;br /&gt;
        uint8_t virt_sec;       // Mapped to sector&lt;br /&gt;
        uint8_t prev_virt_sec;  // Physical sector previously mapped to&lt;br /&gt;
        uint8_t phys_sec;       // Mapped from sector&lt;br /&gt;
        uint8_t prev_phys_sec;  // Virtual sector previously mapped to&lt;br /&gt;
        uint8_t phys_realloc_cnt;       // Amount of times physical sector has been remapped&lt;br /&gt;
        uint8_t virt_realloc_cnt;       // Amount of times virtual sector has been remapped&lt;br /&gt;
        uint8_t chksums[8];     // Unused &amp;amp; uninitialized for V2&lt;br /&gt;
} __attribute__((__packed__));&lt;br /&gt;
&lt;br /&gt;
struct journal_entry{&lt;br /&gt;
        struct journal_entry_half entry;&lt;br /&gt;
        struct journal_entry_half dupe; // same data as `entry`. No idea what this is used fore&lt;br /&gt;
        uint32_t uninitialized;         // 0xFFFFFFFF in newer system&lt;br /&gt;
}__attribute__((__packed__));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The checksums in the blockmap/journal entries work as follows:&lt;br /&gt;
* each byte is the checksum of an encrypted 0x200 bytes large block&lt;br /&gt;
* to calculate the checksum, a CRC16 of the block (same CRC16 algorithm as above) is calculated, and the two bytes of the CRC16 are XORed together to produce the 8bit checksum&lt;br /&gt;
&lt;br /&gt;
== Initialization ==&lt;br /&gt;
&lt;br /&gt;
When a save FLASH contains all xFFFF blocks it&#039;s assumed uninitialized by the game cartridges and it initializes default data in place, without prompting the user. The 0xFFFFFFFF blocks are uninitialized data. When creating a non-gamecard savegame and other images/files, it&#039;s initially all 0xFFFFFFFF until it&#039;s formatted where some of the blocks are overwritten with encrypted data.&lt;br /&gt;
&lt;br /&gt;
I got a new game SplinterCell3D-Pal and I downloaded the save and it was 128KB of 0xFF, except the first 0x10 bytes which were the letter &#039;Z&#039; (uppercase) --[[User:Elisherer|Elisherer]] 22:41, 15 October 2011 (CEST)&lt;br /&gt;
&lt;br /&gt;
== Fun Facts ==&lt;br /&gt;
&lt;br /&gt;
If you have facts that you found out by looking at the binary files please share them here:&lt;br /&gt;
&lt;br /&gt;
* From one save to another the game backups the last files that were in the partition and the entire image header in &amp;quot;random&amp;quot; locations.. --[[User:Elisherer|Elisherer]] 22:41, 15 October 2011 (CEST)&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/wwylele/save3ds save3ds] supports reading and modifying savegames, extdata and title database in FUSE filesystem or batch extracting/importing.&lt;br /&gt;
* [https://github.com/3dshax/3ds/tree/master/3dsfuse 3dsfuse] supports reading and modifying savegames. In the mounted FUSE filesystem, the /output.sav is the raw FLASH save-image. When the save was modified, a separate tool to update the CMAC must be used with /clean.sav, prior to writing output.sav to a gamecard. (This is an old tool that doesn&#039;t handle the savegame format correctly. --[[User:Wwylele|Wwylele]] ([[User talk:Wwylele|talk]]) 16:13, 2 December 2019 (CET))&lt;br /&gt;
* [[3DSExplorer]] supports reading of savegames, it doesn&#039;t support reading the new encrypted savegames and maybe in the future it will support modifying (some of the modyfing code is already implemented).&lt;br /&gt;
* [https://github.com/wwylele/3ds-save-tool wwylele&#039;s 3ds-save-tool] supports extracting files from savegames and extdata. It properly reconstructs data from the DPFS tree and extracts files in directories hierarchy.&lt;br /&gt;
&lt;br /&gt;
[[セーブデータ|Japanese]]&lt;/div&gt;</summary>
		<author><name>Aspargas2</name></author>
	</entry>
	<entry>
		<id>https://www.3dbrew.org/w/index.php?title=Inner_FAT&amp;diff=21105</id>
		<title>Inner FAT</title>
		<link rel="alternate" type="text/html" href="https://www.3dbrew.org/w/index.php?title=Inner_FAT&amp;diff=21105"/>
		<updated>2019-11-28T03:15:44Z</updated>

		<summary type="html">&lt;p&gt;Aspargas2: /* Mention which extdata device files use external IVFC level 4 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes a common FAT-like file system used in [[Savegames]], [[Extdata]] and [[Title Database]]. This file system format has several variants depending on which kind of data it stores. All the three kinds of data that use this file system structure also happen to use the [[DISA and DIFF]] container as well, but there is no direct relationship between the file system and the DISA/DIFF container. All data formats described here is in the inner data of the DISA/DIFF container (i.e. IVFC level 4). Please refer to the DISA/DIFF page for how to unwrap it first before trying to extract the file system.&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
&lt;br /&gt;
The file system consists of the following components:&lt;br /&gt;
* header&lt;br /&gt;
* directory hash table&lt;br /&gt;
* file hash table&lt;br /&gt;
* file allocation table&lt;br /&gt;
* directory entry table&lt;br /&gt;
* file entry table&lt;br /&gt;
* data region&lt;br /&gt;
&lt;br /&gt;
The file allocation table (FAT) forms several linked lists inside, each of which represents a &amp;quot;file&amp;quot; allocated in the data region. Please refer to the File Allocation Table section below for more detail. In some variants, the directory entry table and the file entry table are also allocated as two special &amp;quot;files&amp;quot; in the data region, managed by the FAT, while in others they are stand-alone tables located outside the data region.&lt;br /&gt;
&lt;br /&gt;
== Layout Variants ==&lt;br /&gt;
Four variants of the file system layout has been identified. A summary diagram can be found here: [https://github.com/wwylele/3ds-save-tool/raw/master/inner-fat.png]&lt;br /&gt;
&lt;br /&gt;
=== Savegame, &amp;lt;code&amp;gt;duplicate data = true&amp;lt;/code&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
Such savegame is a single DISA container that only has one partition which is always configured as external IVFC level 4 disabled (see [[DISA and DIFF|DISA]] format for details). All components are stored in this partition as&lt;br /&gt;
&lt;br /&gt;
* filesystem header at the beginning&lt;br /&gt;
* directory hash table&lt;br /&gt;
* file hash table&lt;br /&gt;
* file allocation table&lt;br /&gt;
* data region&lt;br /&gt;
** directory entry table is allocated inside data region&lt;br /&gt;
** file entry table as well&lt;br /&gt;
** all file data is also allocated here&lt;br /&gt;
&lt;br /&gt;
In this layout, all data is duplicated by DISA&#039;s DPFS tree, which is what the parameter &amp;lt;code&amp;gt;duplicate data&amp;lt;/code&amp;gt; implies.&lt;br /&gt;
&lt;br /&gt;
=== Savegame, &amp;lt;code&amp;gt;duplicate data = false&amp;lt;/code&amp;gt; === &lt;br /&gt;
Such savegame is a single DISA container that has two partitions. Partition A is always configured as external IVFC level 4 disabled, and partition B is configured as it enabled. Components are stored among the two partitions as&lt;br /&gt;
&lt;br /&gt;
* Partition A&lt;br /&gt;
** filesystem header at the beginning.&lt;br /&gt;
** directory hash table&lt;br /&gt;
** file hash table&lt;br /&gt;
** (stand-alone) file allocation table&lt;br /&gt;
** (stand-alone) directory entry table&lt;br /&gt;
** file entry table&lt;br /&gt;
* Partition B&lt;br /&gt;
** used as data region entirely, and only has file data allocated.&lt;br /&gt;
&lt;br /&gt;
In this layout, all file system metadata is duplicated by partition A DPFS tree, but file data is not as partition B has external IVFC level 4.&lt;br /&gt;
&lt;br /&gt;
=== Extdata ===&lt;br /&gt;
An extdata consists of several DIFF containers (device files), among which the special device file &amp;lt;code&amp;gt;00000000/00000001&amp;lt;/code&amp;gt; contains the inner FAT system, while other devices contains normal subfiles of the extdata. Please refer to [[Extdata]] for detail. The special file &amp;lt;code&amp;gt;00000000/00000001&amp;lt;/code&amp;gt; contists of the following components&lt;br /&gt;
&lt;br /&gt;
* filesystem header at the beginning&lt;br /&gt;
* directory hash table&lt;br /&gt;
* file hash table&lt;br /&gt;
* file allocation table (degenerate, because the data region only has two &amp;quot;files&amp;quot;: the directory entry table and the file entry table)&lt;br /&gt;
* data region&lt;br /&gt;
** directory entry table allocated inside data region&lt;br /&gt;
** file entry table as well&lt;br /&gt;
** normal subfiles are NOT in the data region. They are in their DIFF containers instead.&lt;br /&gt;
&lt;br /&gt;
The special file &amp;lt;code&amp;gt;00000000/00000001&amp;lt;/code&amp;gt; is configured as external IVFC level 4 disabled, and all other device files are configured as it enabled.&lt;br /&gt;
&lt;br /&gt;
=== Title database ===&lt;br /&gt;
All [[Title Database]] files are DIFF containers. Except for &amp;lt;code&amp;gt;certs.db&amp;lt;/code&amp;gt;, all of them uses this filesystem in the DIFF inner data, which consists of&lt;br /&gt;
&lt;br /&gt;
* database-specific pre-header at the beginning (See [[Title Database]])&lt;br /&gt;
* filesystem header&lt;br /&gt;
* directory Hash Table (degenerate and always has only one bucket, as there is only one directory for &amp;quot;root&amp;quot;)&lt;br /&gt;
* file Hash Table&lt;br /&gt;
* file allocation table&lt;br /&gt;
* data region&lt;br /&gt;
** directory entry table allocated inside data region (degenerate, as there is only one directory for &amp;quot;root&amp;quot;)&lt;br /&gt;
** file entry table as well&lt;br /&gt;
** title entries (title info or ticket) are allocated as normal files in the data region as well.&lt;br /&gt;
&lt;br /&gt;
== Filesystem Header ==&lt;br /&gt;
Offsets listed in the table below are all relative to the beginning of the header, while all &amp;quot;starting block index&amp;quot; are relative to the beginning of data region. This is especially important for title database, as the offsets doesn&#039;t count the pre header.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Offset&lt;br /&gt;
! Length&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| 0x00&lt;br /&gt;
| 4&lt;br /&gt;
| Magic (&amp;quot;SAVE&amp;quot; for savegame; &amp;quot;BDRI&amp;quot; for title database; &amp;quot;VSXE&amp;quot; for extdata)&lt;br /&gt;
|-&lt;br /&gt;
| 0x04&lt;br /&gt;
| 4&lt;br /&gt;
| Version (0x40000 for savegame; 0x30000 for title database and extdata)&lt;br /&gt;
|-&lt;br /&gt;
| 0x08&lt;br /&gt;
| 8&lt;br /&gt;
| Filesystem Information offset (Y, =0x20 for savegame and title database, =0x138 for extdata)&lt;br /&gt;
|-&lt;br /&gt;
| 0x10&lt;br /&gt;
| 8&lt;br /&gt;
| Filesystem image size in blocks (including pre header for title database)&lt;br /&gt;
|-&lt;br /&gt;
| 0x18&lt;br /&gt;
| 4&lt;br /&gt;
| Filesystem Image block size&lt;br /&gt;
|-&lt;br /&gt;
| 0x1C&lt;br /&gt;
| 4&lt;br /&gt;
| Padding&lt;br /&gt;
|-&lt;br /&gt;
| 0x20 &lt;br /&gt;
| 0x118 in total&lt;br /&gt;
| Below is additional data for extdata. Not present in savegame or title database&lt;br /&gt;
|-&lt;br /&gt;
| 0x20&lt;br /&gt;
| 8&lt;br /&gt;
| Unknown&lt;br /&gt;
|-&lt;br /&gt;
| 0x28&lt;br /&gt;
| 4&lt;br /&gt;
| &#039;Action&#039; made on most recently mounted Extdata image&lt;br /&gt;
|-&lt;br /&gt;
| 0x2C&lt;br /&gt;
| 4&lt;br /&gt;
| Unknown&lt;br /&gt;
|-&lt;br /&gt;
| 0x30&lt;br /&gt;
| 4&lt;br /&gt;
| ID of most recently mounted Extdata image&lt;br /&gt;
|-&lt;br /&gt;
| 0x34&lt;br /&gt;
| 4&lt;br /&gt;
| Unknown&lt;br /&gt;
|-&lt;br /&gt;
| 0x38&lt;br /&gt;
| 0x100&lt;br /&gt;
| Mount path, from most recently mounted Extdata image&lt;br /&gt;
|-&lt;br /&gt;
| Y &lt;br /&gt;
| 0x68 in total&lt;br /&gt;
| Below is Filesystem Information&lt;br /&gt;
|-&lt;br /&gt;
| Y + 0x00&lt;br /&gt;
| 4&lt;br /&gt;
| Unknown&lt;br /&gt;
|-&lt;br /&gt;
| Y + 0x04&lt;br /&gt;
| 4&lt;br /&gt;
| Data region block size&lt;br /&gt;
|-&lt;br /&gt;
| Y + 0x08&lt;br /&gt;
| 8&lt;br /&gt;
| Directory hash table offset&lt;br /&gt;
|-&lt;br /&gt;
| Y + 0x10&lt;br /&gt;
| 4&lt;br /&gt;
| Directory hash table bucket count (=1 for title database)&lt;br /&gt;
|-&lt;br /&gt;
| Y + 0x14&lt;br /&gt;
| 4&lt;br /&gt;
| Padding&lt;br /&gt;
|-&lt;br /&gt;
| Y + 0x18&lt;br /&gt;
| 8&lt;br /&gt;
| File hash table offset&lt;br /&gt;
|-&lt;br /&gt;
| Y + 0x20&lt;br /&gt;
| 4&lt;br /&gt;
| File hash table bucket count&lt;br /&gt;
|-&lt;br /&gt;
| Y + 0x24&lt;br /&gt;
| 4&lt;br /&gt;
| Padding&lt;br /&gt;
|-&lt;br /&gt;
| Y + 0x28&lt;br /&gt;
| 8&lt;br /&gt;
| File allocation table offset&lt;br /&gt;
|-&lt;br /&gt;
| Y + 0x30&lt;br /&gt;
| 4&lt;br /&gt;
| File allocation table entry count &lt;br /&gt;
(excluding the leading 0th entry. See below)&lt;br /&gt;
|-&lt;br /&gt;
| Y + 0x34&lt;br /&gt;
| 4&lt;br /&gt;
| Padding&lt;br /&gt;
|-&lt;br /&gt;
| Y + 0x38&lt;br /&gt;
| 8&lt;br /&gt;
| Data region offset &lt;br /&gt;
(0 for savegame &amp;lt;code&amp;gt;duplicate data = false&amp;lt;/code&amp;gt; layout, as the data region is in partition B for that layout)&lt;br /&gt;
|-&lt;br /&gt;
| Y + 0x40&lt;br /&gt;
| 4&lt;br /&gt;
| Data region block count &lt;br /&gt;
(= File allocation table entry count)&lt;br /&gt;
|-&lt;br /&gt;
| Y + 0x44&lt;br /&gt;
| 4&lt;br /&gt;
| Padding&lt;br /&gt;
|-&lt;br /&gt;
| Y + 0x48&lt;br /&gt;
| 8&lt;br /&gt;
| for savegame &amp;lt;code&amp;gt;duplicate data = false&amp;lt;/code&amp;gt; layout: directory entry table offset;&lt;br /&gt;
otherwise: u32 directory entry table starting block index + u32 directory entry table block count&lt;br /&gt;
|-&lt;br /&gt;
| Y + 0x50&lt;br /&gt;
| 4&lt;br /&gt;
| Maximum directory count, excluding the mandatory &amp;quot;root&amp;quot; directory &lt;br /&gt;
(=1 for title database, but that 1 free directory slot is never used)&lt;br /&gt;
|-&lt;br /&gt;
| Y + 0x54&lt;br /&gt;
| 4&lt;br /&gt;
| Padding&lt;br /&gt;
|-&lt;br /&gt;
| Y + 0x58&lt;br /&gt;
| 8&lt;br /&gt;
| for savegame &amp;lt;code&amp;gt;duplicate data = false&amp;lt;/code&amp;gt; layout: file entry table offset;&lt;br /&gt;
otherwise: u32 file entry table starting block index + u32 file entry table block count&lt;br /&gt;
|-&lt;br /&gt;
| Y + 0x60&lt;br /&gt;
| 4&lt;br /&gt;
| Maximum file count&lt;br /&gt;
|-&lt;br /&gt;
| Y + 0x64&lt;br /&gt;
| 4&lt;br /&gt;
| Padding&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* For savegames, the file/directory bucket count &amp;amp; maximum count are specified by the parameters of [[FS:FormatSaveData]] or [[FS:CreateSystemSaveData]].&lt;br /&gt;
* For extdata, the maximum file/directory count are specified by the parameters of [[FS:CreateExtSaveData]]. The bucket count is likely calculated by the system.&lt;br /&gt;
* Directory &amp;amp; file entry tables are allocated in the data region as if they are two normal files (except for savegame &amp;lt;code&amp;gt;duplicate data = false&amp;lt;/code&amp;gt; layout). However, only continuous allocation has been observed, so directly reading block_count * block_size bytes from data_region + starting_block_index * block_size should be safe.&lt;br /&gt;
* For title database (except for ticket), the range specified for data region seems overflow the file end by 0x80 bytes, which is exactly the size of the pre header. This makes it as if the data region offset should be relative to the pre header instead of the BDRI header. However, further investigation on the directory/file table allocated inside the data region shows that the data region offset is indeed relative to the BDRI header. It might be a bug in 3DS that the title database files miss 0x80-byte space at the end.&lt;br /&gt;
&lt;br /&gt;
== Directory Entry Table ==&lt;br /&gt;
&lt;br /&gt;
The directory entry table is an array of the entry type shown below. It describes the directory hierarchy of the file system. There are two variants of the directory entry type, and a dummy entry type.&lt;br /&gt;
&lt;br /&gt;
=== Savegame/Extdata Variant===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Offset&lt;br /&gt;
! Length&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| 0x00&lt;br /&gt;
| 4&lt;br /&gt;
| Parent directory index. 0 for root&lt;br /&gt;
|-&lt;br /&gt;
| 0x04&lt;br /&gt;
| 16&lt;br /&gt;
| ASCII directory name in. All zero for root&lt;br /&gt;
|-&lt;br /&gt;
| 0x14&lt;br /&gt;
| 4&lt;br /&gt;
| Next sibling directory index. 0 if this is the last one&lt;br /&gt;
|-&lt;br /&gt;
| 0x18&lt;br /&gt;
| 4&lt;br /&gt;
| First subdirectory index. 0 if not exists&lt;br /&gt;
|-&lt;br /&gt;
| 0x1C&lt;br /&gt;
| 4&lt;br /&gt;
| First file index in file entry table. 0 for empty directory&lt;br /&gt;
|-&lt;br /&gt;
| 0x20&lt;br /&gt;
| 4&lt;br /&gt;
| Padding / zero?&lt;br /&gt;
|-&lt;br /&gt;
| 0x24&lt;br /&gt;
| 4&lt;br /&gt;
| Index of the next directory in the same hash table bucket. 0 if this is the last one&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Title Database Variant===&lt;br /&gt;
Because title database only has one directory for &amp;quot;root&amp;quot;, its directory entry table degenerates into many zeros whose structure is not recognizable. The size of one entry here is guessed.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Offset&lt;br /&gt;
! Length&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| 0x00&lt;br /&gt;
| 4&lt;br /&gt;
| Parent directory index = 0 for root&lt;br /&gt;
|-&lt;br /&gt;
| 0x04&lt;br /&gt;
| 4&lt;br /&gt;
| Next sibling directory index = 0 because this is the last one&lt;br /&gt;
|-&lt;br /&gt;
| 0x08&lt;br /&gt;
| 4&lt;br /&gt;
| First subdirectory index = 0 because there is no subdirectory&lt;br /&gt;
|-&lt;br /&gt;
| 0x0C&lt;br /&gt;
| 4&lt;br /&gt;
| First file index in file entry table. 0 for empty directory&lt;br /&gt;
|-&lt;br /&gt;
| 0x10&lt;br /&gt;
| 12&lt;br /&gt;
| Padding / zero?&lt;br /&gt;
|-&lt;br /&gt;
| 0x1C&lt;br /&gt;
| 4&lt;br /&gt;
| Index of the next directory in the same hash table bucket = 0 because there is no other directory&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Dummy Entry===&lt;br /&gt;
There are also some dummy entries in the array&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Offset&lt;br /&gt;
! Length&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| 0x00&lt;br /&gt;
| 4&lt;br /&gt;
| Current Total entry count&lt;br /&gt;
|-&lt;br /&gt;
| 0x04&lt;br /&gt;
| 4&lt;br /&gt;
| Maximum entry count = maximum directory count + 2&lt;br /&gt;
|-&lt;br /&gt;
| 0x08&lt;br /&gt;
| 28/20&lt;br /&gt;
| Padding / All zero&lt;br /&gt;
|-&lt;br /&gt;
| 0x24/0x1C&lt;br /&gt;
| 4&lt;br /&gt;
| Index of the next dummy entry. 0 if this is the last one&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The 0-th entry of the array is always a dummy entry, which functions as the head of the dummy entry linked list. The 1-st entry of the array is always the root. Therefore maximum entry count is two more than maximum directory count. Dummy entries are left there when deleting directories, and reserved for future use.&lt;br /&gt;
&lt;br /&gt;
== File Entry Table ==&lt;br /&gt;
&lt;br /&gt;
The file entry table is an array of the entry type shown below. It contains information for each file. There are three variants of the file entry type, and a dummy entry type.&lt;br /&gt;
&lt;br /&gt;
=== Savegame Variant ===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Offset&lt;br /&gt;
! Length&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| 0x00&lt;br /&gt;
| 4&lt;br /&gt;
| Parent directory index in directory entry table&lt;br /&gt;
|-&lt;br /&gt;
| 0x04&lt;br /&gt;
| 16&lt;br /&gt;
| ASCII file name&lt;br /&gt;
|-&lt;br /&gt;
| 0x14&lt;br /&gt;
| 4&lt;br /&gt;
| Next sibling file index. 0 if this is the last one&lt;br /&gt;
|-&lt;br /&gt;
| 0x18&lt;br /&gt;
| 4&lt;br /&gt;
| Padding&lt;br /&gt;
|-&lt;br /&gt;
| 0x1C&lt;br /&gt;
| 4&lt;br /&gt;
| First block index in data region. 0x80000000 if the file is just created and has no data.&lt;br /&gt;
|-&lt;br /&gt;
| 0x20&lt;br /&gt;
| 8&lt;br /&gt;
| File Size&lt;br /&gt;
|-&lt;br /&gt;
| 0x28&lt;br /&gt;
| 4&lt;br /&gt;
| Padding?&lt;br /&gt;
|-&lt;br /&gt;
| 0x2C&lt;br /&gt;
| 4&lt;br /&gt;
| Index of the next file in the same hash table bucket. 0 if this is the last one&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Extdata Variant ===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Offset&lt;br /&gt;
! Length&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| 0x00&lt;br /&gt;
| 4&lt;br /&gt;
| Parent directory index in directory entry table&lt;br /&gt;
|-&lt;br /&gt;
| 0x04&lt;br /&gt;
| 16&lt;br /&gt;
| ASCII file name&lt;br /&gt;
|-&lt;br /&gt;
| 0x14&lt;br /&gt;
| 4&lt;br /&gt;
| Next sibling file index. 0 if this is the last one&lt;br /&gt;
|-&lt;br /&gt;
| 0x18&lt;br /&gt;
| 4&lt;br /&gt;
| Padding&lt;br /&gt;
|-&lt;br /&gt;
| 0x1C&lt;br /&gt;
| 4&lt;br /&gt;
| Always 0x80000000&lt;br /&gt;
|-&lt;br /&gt;
| 0x20&lt;br /&gt;
| 8&lt;br /&gt;
| Unique identifier. See [[Extdata]]&lt;br /&gt;
|-&lt;br /&gt;
| 0x28&lt;br /&gt;
| 4&lt;br /&gt;
| Padding?&lt;br /&gt;
|-&lt;br /&gt;
| 0x2C&lt;br /&gt;
| 4&lt;br /&gt;
| Index of the next file in the same hash table bucket. 0 if this is the last one&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Title database Variant ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Offset&lt;br /&gt;
! Length&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| 0x00&lt;br /&gt;
| 4&lt;br /&gt;
| Parent directory index in directory entry table&lt;br /&gt;
|-&lt;br /&gt;
| 0x04&lt;br /&gt;
| 8&lt;br /&gt;
| Title ID&lt;br /&gt;
|-&lt;br /&gt;
| 0x0C&lt;br /&gt;
| 4&lt;br /&gt;
| Next sibling file index. 0 if this is the last one&lt;br /&gt;
|-&lt;br /&gt;
| 0x10&lt;br /&gt;
| 4&lt;br /&gt;
| Padding&lt;br /&gt;
|-&lt;br /&gt;
| 0x14&lt;br /&gt;
| 4&lt;br /&gt;
| First block index in data region.&lt;br /&gt;
|-&lt;br /&gt;
| 0x18&lt;br /&gt;
| 8&lt;br /&gt;
| File size&lt;br /&gt;
|-&lt;br /&gt;
| 0x20&lt;br /&gt;
| 8&lt;br /&gt;
| Padding?&lt;br /&gt;
|-&lt;br /&gt;
| 0x28&lt;br /&gt;
| 4&lt;br /&gt;
| Index of the next file in the same hash table bucket. 0 if this is the last one&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Dummy Entry ===&lt;br /&gt;
Like directory entry table, file entry table also has some dummy entries:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Offset&lt;br /&gt;
! Length&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| 0x00&lt;br /&gt;
| 4&lt;br /&gt;
| Current total entry count&lt;br /&gt;
|-&lt;br /&gt;
| 0x04&lt;br /&gt;
| 4&lt;br /&gt;
| Maximum entry count = maximum file count + 1&lt;br /&gt;
|-&lt;br /&gt;
| 0x08&lt;br /&gt;
| 36/32&lt;br /&gt;
| Padding / All zero&lt;br /&gt;
|-&lt;br /&gt;
| 0x2C/0x28&lt;br /&gt;
| 4&lt;br /&gt;
| Index of the next dummy entry. 0 if this is the last one&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The 0-th entry of the array is always a dummy entry, which functions as the head of the dummy entry linked list. Therefore maximum entry count is one more than maximum file count. Dummy entries are left there when deleting files, and reserved for future use.&lt;br /&gt;
&lt;br /&gt;
== Directory Hash Table &amp;amp;amp; File Hash Table ==&lt;br /&gt;
&lt;br /&gt;
This is a u32 array of size = bucket count, each of which is an index to the directory / file entry table. The directory / file name is hashed and its entry index is put to the corresponding bucket. If there is already a directory/file entry in the bucket, then it appends to the linked list formed by &amp;lt;code&amp;gt;Index of the next directory/file in the same hash table bucket&amp;lt;/code&amp;gt; field in the directory/file entry table. i.e. this is a hash table using separate chaining with linked lists&lt;br /&gt;
&lt;br /&gt;
The hash function takes the parent index and the ASCII name (or title ID for title database) as key. The function is equivalent to&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;uint32_t GetBucket(&lt;br /&gt;
    char name[16 or 8], // For savegame/extdata, this takes all 16 bytes including trailing zeros; For title database, this is the 8-byte title ID&lt;br /&gt;
    uint32_t parent_dir_index,&lt;br /&gt;
    uint32_t bucket_count&lt;br /&gt;
) {&lt;br /&gt;
    uint32_t hash = parent_dir_index ^ 0x091A2B3C;&lt;br /&gt;
    for (int i = 0; i &amp;amp;lt; 4 or 2; ++i) {&lt;br /&gt;
        hash = (hash &amp;amp;gt;&amp;amp;gt; 1) | (hash &amp;amp;lt;&amp;amp;lt; 31);&lt;br /&gt;
        hash ^= (uint32_t)name[i * 4]&lt;br /&gt;
        hash ^= (uint32_t)name[i * 4 + 1] &amp;amp;lt;&amp;amp;lt; 8&lt;br /&gt;
        hash ^= (uint32_t)name[i * 4 + 2] &amp;amp;lt;&amp;amp;lt; 16&lt;br /&gt;
        hash ^= (uint32_t)name[i * 4 + 3] &amp;amp;lt;&amp;amp;lt; 24&lt;br /&gt;
    }&lt;br /&gt;
    return hash % bucket_count;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== File Allocation Table ==&lt;br /&gt;
&lt;br /&gt;
The file allocation table is an array of a 8-byte entry shown below. The array size is actually &#039;&#039;one larger than&#039;&#039; the size recorded in the filesystem header. Each entry corresponds to a block in the data region (the block size is defined in filesystem header). However, the 0th entry corresponds to nothing, so the corresponding block index is off by one. e.g. entry 31 in this table corresponds to block 30 in the data region.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Offset&lt;br /&gt;
! Length&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| 0x00&lt;br /&gt;
| 4&lt;br /&gt;
| bit[0:30]: Index U; bit[31]: Flag U&lt;br /&gt;
|-&lt;br /&gt;
| 0x04&lt;br /&gt;
| 4&lt;br /&gt;
| bit[0:30]: Index V; bit[31]: Flag V&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Entries in this table forms several chains, representing how blocks in the data region should be linked together. However, unlike normal FAT systems, which uses chains of entries, 3DS savegames use chain of &#039;&#039;nodes&#039;&#039;. Each node spans one or multiple entries.&lt;br /&gt;
&lt;br /&gt;
One node spanning &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; entries starting from &amp;lt;code&amp;gt;FAT[k]&amp;lt;/code&amp;gt; is in the following format:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;FAT[k + 0]:&lt;br /&gt;
    Index_U = index of the first entry of the previous node. 0 if this is the first node.&lt;br /&gt;
    Index_V = index of the first entry of the next node. 0 if this is the last node.&lt;br /&gt;
    Flag_U set if this is the first node.&lt;br /&gt;
    Flag_V set if this node has multiple entries.&lt;br /&gt;
&lt;br /&gt;
FAT[k + 1]:&lt;br /&gt;
    Index_U = k (the first entry index of this node)&lt;br /&gt;
    Index_V = k + n - 1 (the last entry index of this node)&lt;br /&gt;
    Flag_U always set&lt;br /&gt;
    Flag_V always clear&lt;br /&gt;
&lt;br /&gt;
FAT[k + 2] ~ FAT[k + n - 2]:&lt;br /&gt;
    All these entries are uninitialized&lt;br /&gt;
&lt;br /&gt;
FAT[k + n - 1]:&lt;br /&gt;
    Index_U = k&lt;br /&gt;
    Index_V = k + n - 1&lt;br /&gt;
    Flag_U always set&lt;br /&gt;
    Flag_V always clear&lt;br /&gt;
    (Same values as FAT[k + 1])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Note: all indices above are entry indices (block index + 1)&lt;br /&gt;
&lt;br /&gt;
All free blocks that are not allocated to any files also form a node chain in the allocation table. The head index of this &amp;amp;quot;free chain&amp;amp;quot; is recorded in &amp;lt;code&amp;gt;FAT[0].Index_V&amp;lt;/code&amp;gt;. Other fields of &amp;lt;code&amp;gt;FAT[0]&amp;lt;/code&amp;gt; are all zero&lt;br /&gt;
&lt;br /&gt;
Here is an example: [https://raw.githubusercontent.com/wwylele/3ds-save-tool/master/disa-fat.png]&lt;br /&gt;
&lt;br /&gt;
For extdata, because only two &amp;quot;files&amp;quot; (directory and file entry tables) are allocated in the data region, and their size never changes once the extdata is created, they are guaranteed continuous in the data region, and the FAT degenerates to two big nodes. Therefore, instead of going through FAT, the offset and size of directory / file entry table can be found directly by offset = entry_table_starting block * data_region_block_size + data_region_offset and size = entry_table_block_count * data_region_block_size.&lt;/div&gt;</summary>
		<author><name>Aspargas2</name></author>
	</entry>
</feed>