Changes

Jump to navigation Jump to search
1,488 bytes added ,  21:03, 28 April 2020
→‎Extra data: prior save struct link fix pointed to wrong struct
Line 1: Line 1:  
This page describes the format of save files contained in NAND. These files are stored as completely unencrypted, plaintext data. Save files are not cleared upon creation, resulting in possible garbage data in unused portions of the container.
 
This page describes the format of save files contained in NAND. These files are stored as completely unencrypted, plaintext data. Save files are not cleared upon creation, resulting in possible garbage data in unused portions of the container.
   −
== Main header ==
+
= Main header =
    
The header is 0x4000 bytes long.
 
The header is 0x4000 bytes long.
Line 66: Line 66:  
The additional storage at the end of the header is used to store any extra header data. This data's structure is determined by offsets stored in the main part of the header.
 
The additional storage at the end of the header is used to store any extra header data. This data's structure is determined by offsets stored in the main part of the header.
   −
=== AES CMAC header ===
+
== AES CMAC header ==
 +
 
 +
This is internally referred to as MasterHeaderMac.
 +
 
 
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
Line 84: Line 87:  
The final CMAC key used for this is generated using GenerateAesKek with a kek source and the device key, along with and LoadAesKey and a set key seed.
 
The final CMAC key used for this is generated using GenerateAesKek with a kek source and the device key, along with and LoadAesKey and a set key seed.
   −
=== DISF ===
+
== DISF ==
    
This section contains information about the structure of the save file.
 
This section contains information about the structure of the save file.
Line 291: Line 294:  
|}
 
|}
   −
=== Integrity verification header ===
+
== Integrity verification header ==
    
* Offsets for levels 1-3 come from the metadata remap storage
 
* Offsets for levels 1-3 come from the metadata remap storage
Line 329: Line 332:  
|}
 
|}
   −
==== Level information ====
+
=== Level information ===
    
* 0x18 bytes long
 
* 0x18 bytes long
Line 358: Line 361:  
|}
 
|}
   −
=== Journal header ===
+
== Journal header ==
    
{| class="wikitable"
 
{| class="wikitable"
Line 396: Line 399:  
|}
 
|}
   −
==== Journal map header ====
+
=== Journal map header ===
    
{| class="wikitable"
 
{| class="wikitable"
Line 422: Line 425:  
|}
 
|}
   −
=== Extra data ===
+
== Extra data ==
    
{| class="wikitable"
 
{| class="wikitable"
Line 432: Line 435:  
| 0x00
 
| 0x00
 
| 0x40
 
| 0x40
| [[Filesystem_services#Save_Struct|Save Struct]]
+
| [[Filesystem_services#SaveDataAttribute|SaveDataAttribute]]
 
|-
 
|-
 
| 0x40
 
| 0x40
Line 467: Line 470:  
|}
 
|}
   −
== Remap Storage ==
+
= Remap Storage =
    
Remap Storage is used to remap segments of data from virtual offsets to physical offsets. This allows extending the save file without having to relocate existing data.
 
Remap Storage is used to remap segments of data from virtual offsets to physical offsets. This allows extending the save file without having to relocate existing data.
Line 483: Line 486:  
Segment index: 0x3 Offset: 0x000000000000100
 
Segment index: 0x3 Offset: 0x000000000000100
   −
=== Remap storage header ===
+
== Remap storage header ==
    
{| class="wikitable"
 
{| class="wikitable"
Line 516: Line 519:  
|}
 
|}
   −
=== Remapping Entry ===
+
== Remapping Entry ==
    
{| class="wikitable"
 
{| class="wikitable"
Line 546: Line 549:  
|}
 
|}
   −
== Duplex Storage ==
+
= Duplex Storage =
    
A Duplex Storage contains four separate elements: [[#Duplex header|a header]], a bitmap, and two identically-sized chunks of data.
 
A Duplex Storage contains four separate elements: [[#Duplex header|a header]], a bitmap, and two identically-sized chunks of data.
Line 552: Line 555:  
As hinted by the name, a Duplex Storage contains two main chunks of data. To store X bytes, two chunks of data each with size X are required.
 
As hinted by the name, a Duplex Storage contains two main chunks of data. To store X bytes, two chunks of data each with size X are required.
   −
=== Bitmap ===
+
== Bitmap ==
    
This main data storage is split into blocks of the size indicated in the duplex header. The bitmap contains as many bits as the main data has blocks. If the main data is 0x40000 bytes long with a block size of 0x4000 bytes, the bitmap would contain 0x10 bits.
 
This main data storage is split into blocks of the size indicated in the duplex header. The bitmap contains as many bits as the main data has blocks. If the main data is 0x40000 bytes long with a block size of 0x4000 bytes, the bitmap would contain 0x10 bits.
Line 558: Line 561:  
The bitmap controls which data chunk is active for each block. e.g. If bit 3 of the bitmap is a 0 then block 3 of data chunk 0 is active and block 3 of data chunk 1 is inactive. This means that when data from block 3 is read, the data from chunk 0 will be returned and the data from chunk 1 will be completely ignored.
 
The bitmap controls which data chunk is active for each block. e.g. If bit 3 of the bitmap is a 0 then block 3 of data chunk 0 is active and block 3 of data chunk 1 is inactive. This means that when data from block 3 is read, the data from chunk 0 will be returned and the data from chunk 1 will be completely ignored.
   −
=== Hierarchical Duplex Storage ===
+
== Hierarchical Duplex Storage ==
    
Multiple Duplex Storages can be chained together to gain various benefits. With a Hierarchical Duplex Storage, the bitmap for the main data is stored inside another Duplex Storage.
 
Multiple Duplex Storages can be chained together to gain various benefits. With a Hierarchical Duplex Storage, the bitmap for the main data is stored inside another Duplex Storage.
Line 566: Line 569:  
This allows for atomic operations on the Hierarchical Duplex Storage. When writing to the storage, data will be written to the inactive blocks and inactive bitmaps. When the data is committed the bit in the save file header is flipped, changing which master bitmap is active.
 
This allows for atomic operations on the Hierarchical Duplex Storage. When writing to the storage, data will be written to the inactive blocks and inactive bitmaps. When the data is committed the bit in the save file header is flipped, changing which master bitmap is active.
   −
=== Duplex header ===
+
== Duplex header ==
    
* Block sizes are stored as powers of 2
 
* Block sizes are stored as powers of 2
Line 622: Line 625:  
|}
 
|}
   −
== Save FS ==
+
= Save FS =
   −
=== Save FS header ===
+
== Save FS header ==
    
* Structure is different than 3DS.
 
* Structure is different than 3DS.
Line 655: Line 658:  
|-
 
|-
 
|}
 
|}
 +
 +
== File allocation table ==
 +
 +
The savedata FS uses an allocation table to keep track of block allocation. This FAT contains doubly-linked lists of the blocks allocated to each file. Each entry in the FAT is 8 bytes in size.
 +
 +
FAT entry 0 is reserved for the list of free blocks. Because of this, the FAT entry for block n is found at FAT index n+1. The indexes stored in FAT entries refer the index of the next/previous FAT entry in the chain, not the index of the next/previous block.
 +
 +
The FAT header is internally called AllocationTableControlArea. The FAT itself is called AllocationTableMeta. The actual save FS data is called AllocationTableData.
    
=== File allocation table header ===
 
=== File allocation table header ===
Line 702: Line 713:  
|}
 
|}
   −
=== Save File Table ===
+
=== File allocation table entry ===
 +
 
 +
{| class="wikitable"
 +
|-
 +
! Start
 +
! Length
 +
! Description
 +
|-
 +
| 0
 +
| 4 (High bit)
 +
| Set if entry is the first entry in the list.
 +
|-
 +
| 0
 +
| 4 (Lower 31 bits)
 +
| Previous entry index. First entry in list if 0.
 +
|-
 +
| 4
 +
| 4 (High bit)
 +
| Set if the allocation segment has multiple blocks.
 +
|-
 +
| 4
 +
| 4 (Lower 31 bits)
 +
| Next entry index. Last entry in list if 0.
 +
|-
 +
|}
 +
 
 +
If the allocation segment has multiple blocks, the first entry will be followed by a range descriptor entry. The last entry in the segment will contain a duplicate of this entry.
 +
 
 +
{| class="wikitable"
 +
|-
 +
! Start
 +
! Length
 +
! Description
 +
|-
 +
| 0
 +
| 4 (High bit)
 +
| Always set.
 +
|-
 +
| 0
 +
| 4 (Lower 31 bits)
 +
| First entry in this segment.
 +
|-
 +
| 4
 +
| 4 (High bit)
 +
| Never set.
 +
|-
 +
| 4
 +
| 4 (Lower 31 bits)
 +
| Last entry in this segment.
 +
|-
 +
|}
 +
 
 +
== Save File Table ==
    
The save file table is similar to the RomFS file table, except the save file table uses linked lists instead of dictionaries.
 
The save file table is similar to the RomFS file table, except the save file table uses linked lists instead of dictionaries.
Line 710: Line 773:  
'''SaveFsList<SaveFileTableEntry<SaveFileInfo>>'''
 
'''SaveFsList<SaveFileTableEntry<SaveFileInfo>>'''
   −
==== Save File Table Entry ====
+
=== Save File Table Entry ===
    
SaveFileTableEntry<class T>
 
SaveFileTableEntry<class T>
Line 730: Line 793:  
|}
 
|}
   −
==== Save File Info ====
+
=== Save File Info ===
    
Holds the information of a single file.
 
Holds the information of a single file.
Line 754: Line 817:  
|}
 
|}
   −
==== Save Directory Info ====
+
=== Save Directory Info ===
    
Holds the information of a single directory.
 
Holds the information of a single directory.
Line 778: Line 841:  
|}
 
|}
   −
=== Save FS List ===
+
== Save FS List ==
    
SaveFsList<class T>
 
SaveFsList<class T>
Line 806: Line 869:  
|}
 
|}
   −
==== Save FS List Key ====
+
=== Save FS List Key ===
    
{| class="wikitable"
 
{| class="wikitable"
Line 824: Line 887:  
|}
 
|}
   −
==== Save FS List Entry ====
+
=== Save FS List Entry ===
    
{| class="wikitable"
 
{| class="wikitable"
77

edits

Navigation menu