Standard Archives: Overview

Description

The FS library mounts several standard archives depending on the type of program that has been booted. This document explains the basics about these archives.

ROM Archives

Within the ROM data region of the DS Game Card, all programs store a single directory tree that was created with the makerom tool. The archive that accesses this directory tree is the ROM archive, and is always mounted using the name rom:. The data to include in the ROM can be specified at build time with the makerom tool. This data is arranged in a data structure known as the NitroROM format. For details about how to include data in the ROM, see the reference for the makerom tool.

The ROM archive can be used without any particular issues for normal card applications. With applications that are booted in other modes, however, there is no certainty that a DS Game Card is actually inserted in the console, so the system behaves as though this directory is empty. For information about the various boot types for programs, see the explanation in the OS_GetBootType page.

If you want to use the ROM archive in a program that has started using DS Download Play in the same way that you would with a card application, we recommend using the WFS library. This library is a utility for reconnecting to the parent that originated the download and accessing ROM data via local wireless communication.

In line with the expanded features of the Nintendo DSi system, major changes have been made to operation of ROM archives on TWL-SDK. The changes from the old package, NITRO-SDK, are summarized below.

NAND Archives

The TWL includes built-in NAND memory. In the documentation, the term NAND archive is used as a collective term for several types of archives that are used to access file systems located in this area. The system NAND memory is actually split into several partitions. The save data files stored by each individual NAND application form independent file systems, but they all use the FAT format as their internal structure. See the TWL Programming Manual for more information on the properties of the system NAND memory.

Depending on the NAND application settings, up to 10 archives can be mounted as NAND archives. Each of these will have a different name, such as photo: or dataPub:. For details about each of these archives, see the NAND Application Development Manual.

SD Memory Card Archives

TWL comes with an SD Memory Card slot, and certain program configurations allow this slot to be accessed. The SD Memory Card archive is mounted using the name sdmc:. SD Memory Cards also use the FAT format, so in general they are used in exactly the same way as NAND archives. That said, some care must be taken because there is wide variation in the data transfer speeds of individual SD Memory Cards, and because there is always a chance that the media could be removed or reinserted during access.

Use the FS_RegisterEventHook function to monitor the removal and insertion of media. To get the current state of the slot or verify write-protection, you can obtain the data as root directory information with an operation such as FS_GetPathInfo("sdmc:/", info). However, if the slot is empty or an unknown device is detected, the function will fail and you need to check the details using the value returned by FS_GetArchiveResultCode. (For example, the return value FS_RESULT_MEDIA_NOTHING indicates that the slot is empty.)

In addition, SD Memory Card recordable media are also used with personal computers and many consumer electronic devices. As a result, when using SD Memory Cards, you must always be aware of the potential danger posed by receiving external data whose content has been tampered with. The use of SD Memory Card archives is prohibited, therefore, with one exception. The SD Memory Card archive is convenient for development purposes, so restricted access is allowed for Debug/Release builds in TWL-SDK version 5.1 PR and later.

Memory File Archives

This archive is a nameless archive that exists in the FS library and is not mounted by the system. Nameless files that have been opened by calls to the FS_CreateFileFromMemory function fall under this category of archive.

Because this archive can treat arbitrary memory spaces just as if they were files, this type of archive can be extremely useful if used properly (for example, by storing frequently used small files in memory).

Internal Formats

The various standard archives described above use internal formats that differ from each other in their characteristics. This section describes the basic characteristics of each of these formats.

NitroROM Format

This is a data archive format unique to TWL-SDK that is used by tools such as nnsarc.exe in the TWL-System package as well as the makerom tool. It has the following characteristics.

An overview of the NitroROM format is given in $TwlSDK/docs/technicalNotes/AboutFileSystem.pdf. However, in general developers do not need to be concerned with this format's specifications.

FAT Format

This specifies the FAT file system that is widely used on SD Memory Cards, hard discs, and other such devices. FAT standards are defined in ISO/IEC 9293. There are various publications and specifications that describe the FAT format, so we have omitted a description here, but following are some characteristics to consider when you use it.

The implementation of the FAT driver used with TWL has the following characteristics.

A fatal timing error exists that will cause inconsistency in the FAT internal state if an SD Card is removed while it is being accessed. The following describes the malfunction that can occur and a countermeasure.

Situation When SD Card Is RemovedSymptom That Could Rarely OccurPossible Workaround in the Program
Changing file size (SetFileLength) The intended addition to file size will be lost from free space.
Or intended reduction in file size will be lost from free space.
(The file itself will be OK.)
There is no way to fix this from the program. You may be able to fix this using a check disk tool from an external environment such as a PC.
Creating an entry (Create)
Moving an entry (Rename)
The internally allocated long file name will be lost, and 13 characters or 32 bytes will be lost from free space.
Deleting an entry (Delete)
Moving and entry (Rename)
All clusters used by the entry being deleted are lost from free space. *1
A long filename will be lost, and the filename will become 8.3 format (short filename). *2 This will not be a problem if the program is not case-sensitive.
When moving an entry (Rename) Both entries will exist. Whichever you reference or change, it will point to the same content.
If you delete one, any operation other that deleting the other one will fail as FS_RESULT_ERROR.
You must delete both the old and new entry and create a new one.
Closing after appending a file (Close) Data integrity problems arise because file size information is updated without allocating memory for the appended file.
Attempted access to the appended memory fails on an FS_RESULT_ERROR.
You must delete the file and create a new one.
Note that *1 and *2 cannot occur at the same time.

Operational Comparison of Each Format

The FS library provides functions for manipulating most file systems, and while the various archives are required to be compliant with that interface, it is permissible not to implement operations that cannot be supported due to the nature of the file system. If functions are called for archives of this sort, the error FS_RESULT_UNSUPPORTED is always returned. The support status of each format in relation to main functions is shown in the table below.

UsableNot Usable

Functions NitroROM Format
(ROM Archive)
FAT Format
(NAND Archive /
SD Memory Card Archive)
(Memory File Archive)
FS_OpenFileEx (FS_OpenFile) *3
FS_OpenFileFast *4 *3
FS_ConvertPathToFileID *4 *3
FS_OpenFileDirect *5 *3
FS_GetFileImageTop *5
FS_GetFileImageBottom *5
FS_CloseFile
FS_GetFileLength
FS_SetFileLength
FS_GetFilePosition
FS_SeekFile
, FS_SeekFileToBegin
, FS_SeekFileToEnd
FS_ReadFile
FS_ReadFileAsync
FS_WriteFile *1
FS_WriteFileAsync *1
FS_FlushFile *1
FS_OpenDirectory (FS_FindDir) *3
FS_ReadDirectory (FS_ReadDir) *3
FS_CloseDirectory *3
FS_TellDir *4 *3
FS_SeekDir *4 *3
FS_RewindDir *4 *3
FS_GetPathName *4 *3
FS_GetPathLength *4 *3
FS_CreateFile *2 *3
FS_DeleteFile *2 *3
FS_RenameFile *2 *3
FS_CreateDirectory *2 *3
FS_DeleteDirectory *2 *3
FS_RenameDirectory *2 *3
*1: Commands that overwrite the contents of files are not supported.
*2: Commands that dynamically change directory structures are not supported.
*3: Commands that access directory structures are not supported.
*4: Commands that use file IDs or directory IDs are not supported.
*5: Commands that directly access a device's address space are not supported.

List of Error Codes

The error codes defined by the FS library are incorporated into the internal processing of the archives. A number of the error codes are only returned by certain archives. The following table shows the error codes that can be returned from each archive.

Error Code (FSResult)ROM ArchivesNAND ArchivesSD Memory Card ArchivesMemory File ArchivesComments
FS_RESULT_SUCCESS YesYesYesYes
FS_RESULT_FAILURE YesYesYesYes
FS_RESULT_BUSY YesYesYesYes
FS_RESULT_CANCELED YesYesYesYes
FS_RESULT_UNSUPPORTED YesYesYesYes
FS_RESULT_ERROR YesYesYesYes
FS_RESULT_INVALID_PARAMETER YesYesYesYes
FS_RESULT_NO_MORE_RESOURCE NoYesYesNo
FS_RESULT_ALREADY_DONE NoYesYesNo
FS_RESULT_PERMISSION_DENIED YesYesYesNo
FS_RESULT_MEDIA_FATAL NoYesYesNoError unique to NAND/SD Memory Cards
FS_RESULT_NO_ENTRY YesYesYesNo
FS_RESULT_MEDIA_NOTHING NoNoYesNoError unique to SD Memory Cards
FS_RESULT_MEDIA_UNKNOWN NoNoYesNoError unique to SD Memory Cards
FS_RESULT_BAD_FORMAT NoYesYesNoError unique to the FAT format

See Also

FS Function List

Revision History

2010/07/10 Added note that if the power is disconnected during a command that takes a long time to process, the NAND enters a state that returns FS_RESULT_BAD_FORMAT.
2009/06/08 Added a note about the TWL-specific region and TWL-specific file.
2009/05/13 Explained how to detect insertion/removal of SD Memory Cards and how to determine the state of the slot.
2009/04/13 Corrected document title of the reference material. Added explanation of ROM archive operations in TWL mode.
2009/04/10 Replaced symbols used in the tables with standard notation.
2009/02/27 Added text about the file access behavior of the FAT driver.
2009/01/13 Mentioned that restricted access to SD Memory Card archives is permitted, but only for the Debug and Release builds.
2008/12/08 Added a list of error codes returned by the archives.
2008/10/28 Added note about creating series of files with FAT driver.
2008/10/20 Added mention that ROM verification process is not executed when TLF is loaded.
2008/09/30 Added text about FAT state inconsistencies when SD Memory Card is inserted or removed.
2008/09/26 Added text about insertion and removal of SD Memory cards and the speed of ROM archive access.
2008/09/16 Added text about the FAT driver specification.
2008/09/12 Initial version.


CONFIDENTIAL