Extdata: Difference between revisions
Nuke the old content |
Rework |
||
Line 1: | Line 1: | ||
This page describes the format and encryption of extdata, | This page describes the format and encryption of extdata, "extra data" stored on SD card and NAND, at: | ||
* <code>nand/data/<ID>/extdata/<ExtdataID-High></code> | |||
* <code>sdmc/Nintendo 3DS/<ID0>/<ID1>/extdata/<ExtdataID-High></code> | |||
ExtdataID-High is always 00000000 for SD, and always 00048000 for NAND. Regular apps can only mount SD extdata using the same extdataID which is stored in the CXI exheader. Therefore, regular apps which have the exheader extdataID set to zero can't use extdata. This restriction doesn't apply for shared extdata with extdataID high bitmask 0x48000 stored on NAND. System apps with a certain access right can mount arbitrary extdata. All NAND extdata is shared extdata, while all SD extdata is normal extdata. | |||
All data in this page is little-endian. All "unused / padding" fields can contain uninitialized data unless otherwise specified. | |||
= Format = | |||
To avoid confusion, the terms '''device directory / file''' and '''virtual directory / file''' are used with the following meanings: | |||
* '''Device directory / file''' are the real directory / file stored on SD / NAND that can be seen under path <code>nand/data/<ID>/extdata/</code> or <code>sdmc/Nintendo 3DS/<ID0>/<ID1>/extdata/</code>. | |||
* '''Virtual directory / file''' are directory / file stored inside extdata virtual file system, which can be seen by applications in the mounted extdata archives. | |||
An extdata consists of several device directories and files, which forms a file system consisting of multiple virtual directories and files. | |||
==== VSXE ==== | An extdata with ID <code>ExtdataId</code> has the following device files: | ||
{| class="wikitable" | |||
* <code>.../extdata/<ExtdataID-High>/<ExtdataId-Low>/Quota.dat</code> (optional) | |||
* <code>.../extdata/<ExtdataID-High>/<ExtdataId-Low>/<SubDirID>/<SubFileID></code> | |||
Note: | |||
* All device files are [[DISA and DIFF|DIFF containers]]. '''All format description below is about the inner content of the containers'''. Please unwrap these files first according to the DIFF format description before reading them using the extdata format description below. | |||
* <code>Quota.dat</code> is only observed existing for NAND shared extdata. | |||
* <code><SubDirID></code> and <code><SubFileID></code> are 8-digit hex strings. | |||
* Device file with <code>SubDirID = SubFileID = 00000000</code> doesn't exist. Other ID combinations can exists. | |||
* Device file with <code>SubDirID = 00000000</code> and <code>SubFileID = 00000001</code> is the VSXE metadata file and must exist. | |||
* Other files, besides <code>Quota.dat</code> and <code>00000000/00000001</code>, are normal sub files, are these device files one-to-one correspond to virtual files. | |||
* <code>SubDirID = 00000000</code> is usually the only one device directory that can be seen. See [[#Device Directory Capacity]] for more information. | |||
== Quota File == | |||
The inner data of <code>Quota.dat</code> is 0x48 bytes with the following format. The exact function of this file is unclear. | |||
{| class="wikitable" border="1" | |||
! Offset | |||
! Length | |||
! Description | |||
|- | |||
| 0x00 | |||
| 4 | |||
| Magic "QUOT" | |||
|- | |||
| 0x04 | |||
| 4 | |||
| Magic 0x30000 | |||
|- | |||
| 0x08 | |||
| 4 | |||
| 0x1000, block size? | |||
|- | |||
| 0x0C | |||
| 4 | |||
| Always 126. Probably device directory capacity. See the [[#Device Directory Capacity]] more information. | |||
|- | |- | ||
! | | ... | ||
| | |||
| The meaning of other fields is unknown | |||
|} | |||
== Device Directory Capacity == | |||
A device directory in an extdata (a <code><SubDirID></code> directory) seems to have a maximum number of device files it can contain. For SD extdata, this maximum number seems to be hard-coded as 126. For NAND extdata, the number is probably indicated by a field in Quota.dat, which is, again, always 126 as observed. 3DS FS tries to put all device files in the device directory <code>00000000</code> if possible, and only when more than 126 files needed to add, a second device directory <code>00000001</code> and so on are created. However, few extdata have such amount of files to store, so the behavior lacks of use cases to confirm. | |||
The number 126 is probably from some kind of other capacity of 128 with <code>"."</code> and <code>".."</code> entries reserved. It is theorized that this is to keep a FAT directory table, with 0x20 bytes for each entry, in one 0x1000 cluster. The motivation is unclear. | |||
== VSXE File System Metadata == | |||
The inner data of <code>00000000/00000001</code> consists of the following components | |||
* VSXE header | |||
* Directory Hash Table | |||
* File Hash Table | |||
* File Allocation Table | |||
* Data region | |||
** Directory Entry Table | |||
** File Entry Table | |||
=== VSXE Header === | |||
{| class="wikitable" border="1" | |||
! Offset | |||
! Length | ! Length | ||
! Description | ! Description | ||
|- | |- | ||
| | | 0x00 | ||
| 4 | | 4 | ||
| | | Magic "VSXE" | ||
|- | |- | ||
| | | 0x04 | ||
| 4 | | 4 | ||
| Magic | | Magic 0x30000 | ||
|- | |- | ||
| | | 0x08 | ||
| 8 | | 8 | ||
| | | File system Information offset (0x138) | ||
|- | |- | ||
| 0x10 | | 0x10 | ||
| 8 | | 8 | ||
| | | Image size in blocks | ||
|- | |- | ||
| 0x18 | | 0x18 | ||
| | | 4 | ||
| | | Image block size | ||
|- | |||
| 0x1C | |||
| 4 | |||
| Padding | |||
|- | |- | ||
| 0x20 | | 0x20 | ||
Line 61: | Line 126: | ||
| 0x30 | | 0x30 | ||
| 4 | | 4 | ||
| | | D of most recently mounted Extdata image | ||
|- | |- | ||
| 0x34 | | 0x34 | ||
Line 70: | Line 135: | ||
| 0x100 | | 0x100 | ||
| Mount path, from most recently mounted Extdata image | | Mount path, from most recently mounted Extdata image | ||
| | |- | ||
| | |||
| | |||
| Below is File system Information, which is assumed following the same layout as [[Savegames#SAVE Header | |||
|- | |- | ||
| 0x138 | |||
| 4 | |||
| Unknown | |||
|- | |- | ||
| | | 0x13C | ||
| | | 4 | ||
| | | Data region block size | ||
|- | |- | ||
| | | 0x140 | ||
| 8 | | 8 | ||
| | | Directory hash table offset | ||
| | |- | ||
| 0x148 | |||
| 4 | |||
| Directory hash table bucket count | |||
|- | |||
| 0x14C | |||
| 4 | |||
| Padding | |||
|- | |- | ||
| 0x150 | |||
| 8 | |||
| File hash table offset | |||
|- | |- | ||
| | | 0x158 | ||
| | | 4 | ||
| | | File hash table bucket count | ||
|- | |- | ||
| | | 0x15C | ||
| 4 | | 4 | ||
| | | Padding | ||
|- | |||
| 0x160 | |||
| 8 | |||
| File allocation table offset | |||
|- | |- | ||
| | | 0x168 | ||
| | | 4 | ||
| | | File allocation table entry count | ||
|- | |- | ||
| 0x16C | |||
| 4 | |||
| Padding | |||
|- | |- | ||
| | | 0x170 | ||
| | | 8 | ||
| | | Data region offset | ||
|- | |- | ||
| | | 0x178 | ||
| | | 4 | ||
| | | Data region block count (= File allocation table entry count) | ||
|- | |- | ||
| | | 0x17C | ||
| | | 4 | ||
| | | Padding | ||
|- | |- | ||
| | | 0x180 | ||
| | | 4 | ||
| | | Directory entry table starting block | ||
|- | |- | ||
| | | 0x184 | ||
| | | 4 | ||
| | | Directory entry table block count | ||
|- | |- | ||
| | | 0x188 | ||
| | | 4 | ||
| | | Maximum directory count | ||
|- | |- | ||
| | | 0x18C | ||
| | | 4 | ||
| | | Padding | ||
|- | |- | ||
| 0x190 | |||
| 4 | |||
| File entry table starting block | |||
|- | |- | ||
| | | 0x194 | ||
| | | 4 | ||
| | | File entry table block count | ||
|- | |- | ||
| | | 0x198 | ||
| 4 | | 4 | ||
| | | Maximum file count | ||
|- | |- | ||
| | | 0x19C | ||
| | | 4 | ||
| | | Padding | ||
|} | |} | ||
* All "offsets" are relative to the beginning of VSXE image. All "starting block index" are relative to the beginning of data region. | |||
{| class="wikitable" | |||
=== File Allocation Table & Data Region === | |||
! | |||
These function in the same way as [[Savegames#File Allocation Table|the file allocation in savegames]]. However, the only two "files" allocated in the data region are the directory entry table and file entry table, so the data region is usually pretty small, and the file allocation table is unchanged once created and has no free blocks. Thus, the offset and size of directory / file entry table can be found directly by <code>offset = entry_table_starting block * data_region_block_size + data_region_offset</code> and <code>size = entry_table_block_count * data_region_block_size</code> | |||
=== Directory Hash Table & File Hash Table === | |||
These function in the same way as [[Savegames#Directory Hash Table & File Hash Table|those in savegames]] | |||
=== Directory Entry Table === | |||
This functions in the same way as [[Savegames#Directory Entry Table|the one in savegames]]. It lists all virtual directories in this extdata. | |||
=== File Entry Table === | |||
This functions in a similar way as [[Savegames#File Entry Table|the one in savegames]]. It lists all virtual files in this extdata. However, the format of a (non-dummy) file entry is a little bit modified: | |||
{| class="wikitable" border="1" | |||
! Offset | |||
! Length | ! Length | ||
! Description | ! Description | ||
|- | |- | ||
| | | 0x00 | ||
| | | 4 | ||
| Parent | | Parent directory index in directory entry table | ||
|- | |- | ||
| | | 0x04 | ||
| | | 16 | ||
| | | ASCII file name | ||
|- | |- | ||
| 0x14 | | 0x14 | ||
| | | 4 | ||
| | | Next sibling file index. 0 if this is the last one | ||
|- | |- | ||
| 0x18 | | 0x18 | ||
| | | 4 | ||
| | | Padding | ||
|- | |- | ||
| 0x1C | | 0x1C | ||
| | | 4 | ||
| | | <s>First block index in data region</s> '''Always 0x80000000 because unused''' | ||
|- | |- | ||
| 0x20 | | 0x20 | ||
| | | 8 | ||
| Unique | | <s>File size</s> '''Unique identifier''' | ||
|- | |- | ||
| 0x28 | | 0x28 | ||
| | | 4 | ||
| | | Padding? | ||
|- | |- | ||
| 0x2C | | 0x2C | ||
| | | 4 | ||
| | | Index of the next file in the same hash table bucket. 0 if this is the last one | ||
|} | |} | ||
Each non-dummy file entry corresponds to a device file. The path to the device file is generated by the following computation: | |||
<pre>// See previous section about this capacity | |||
const uint32_t device_dir_capacity = 126; | |||
// entry index is the index in the file entry table, with the first dummy entry as | |||
// index = 0, which is never used for a real file. | |||
// file_index = 1 is reserved for the VSXE Filesystem Metadata itself, so real files | |||
// started from file_index = 2. | |||
uint32_t file_index = entry_index + 1; | |||
uint32_t SubDirID = file_index / device_dir_capacity; | |||
uint32_t SubFileID = file_index % pdevice_dir_capacity; | |||
char extdata_path[...]; // ".../extdata/<ExtdataID-High>/<ExtdataId-Low>" | |||
char device_path[...]; // output path | |||
sprintfdevice_path, "%s/%08x/%08x", extdata_path, SubDirID, SubFileID); | |||
</pre> | |||
When mounting extdata, the unique identifier is used to match the ID stored in subfile's [[DISA and DIFF#DIFF header|DIFF header]]. If the ID doesn't match, mounting will fail. | |||
== Virtual File System Structure == | |||
When extdata is created, these are ''always'' created regardless of whether the title actually uses them. | |||
* <code>/icon</code> This virtual file contains the extdata icon displayed in data management. This icon can only be written to by titles when creating extdata, titles would have to recreate extdata to change the icon. This file can't be read directly, instead it is read via FS:ReadExtSaveDataIcon. | |||
* <code>/user/</code> This virtual directory contains the title's actual extdata files. | |||
* <code>/boss/</code> This virtual directory can contain SpotPass content. SpotPass content can only be downloaded to this <code>/boss</code> virtual directory. | |||
User extdata and SpotPass extdata use separate mount points at <code>/user</code> and <code>/boss</code>. Therefore one mount can't access the other virtual directory, and also can't access <code>/icon</code>.(The title's SpotPass extdata can be mounted by the title itself, if it uses SpotPass) | |||
Other optional but notable directories include: | |||
* <code>/user/ExBanner</code> This virtual directory can optionally store extended banners. When this is available, this banner is displayed instead of the CXI ExeFS banner. <code>COMMON.bin</code> stores the common exbanner, while <code><regionlang_code>.bin</code> stores an optional separate region/language specific banner.(regionlang_code can be "JPN_JP", "USA_EN", etc) | |||
== SD Extdata == | |||
Usually the ExtdataID low is in the format '00<Unique ID>' | Usually the ExtdataID low is in the format '00<Unique ID>' | ||
Line 571: | Line 629: | ||
|} | |} | ||
== NAND Shared Extdata == | |||
{| class="wikitable" border="1" | {| class="wikitable" border="1" | ||
|- | |- |