File System

# File System (FS) Overview

- Introduction
- Accessing Files and Directories
- Archives

- Standard Archives

- ROM Archives
- Memory File Archives
- NAND Archives
- SD Card Archives
- Internal Format

- NitroROM Format
- FAT Format

- Overlay

## Introduction

The FS library provides various functions for using file systems and overlay modules.

`FS_Init` must be called before any FS library functions are used.Note that it is not called automatically within `OS_Init`, because the application must explicitly specify which DMA channel the FS library can use internally.

    (Example of initialization)
    void NitroMain(void)
    {
        // Initialize OS immediately after startup.
        OS_Init();
        // Explicitly specify the DMA number and initialize the FS library.
        FS_Init(3);
        // The FS library can be used from this point onward.
    }

## Accessing Files and Directories

The various file systems provided by TWL-SDK are implemented based on a common interface established by the FS library. This makes it unnecessary for game developers and library designers to write their own code to support various file systems with different specifications, thereby reducing the burden during development.

When an application accesses a file system, in most cases file or directory handles must be opened. Prepare `FSFile structures` on the application side to store the opened handles, and note that they must be initialized using the `FS_InitFile` function before use.

File Access Function List
Directory Access Function List

## Archives

Individual file systems that are mounted by the FS library are referred to as "archives." Conceptually, an archive is the same as a "drive" on a personal computer. Also, archives already prepared by the FS library are called "standard archives."

A single directory tree structure is always stored within the ROM region for programs that are booted from DS Game Cards. With the FS library, the archive that is used to access this directory tree is mounted by the system using the name "`rom:`". This archive is called the "ROM Archive," and is the most standard type of archive with regard to programs. Depending on the type of program, the FS library may also prepare several more archives. For details, see the description in Standard Archives (Overview).

In addition to the standard archives provided by the SDK, various APIs are available so that developers can freely implement and mount new archives as necessary.

`Archive Function List
`

## Overlay

Even for huge programs that cannot be completely resident during the boot, it is possible to load only the required parts at runtime by splitting up the individual modules as overlays. The FS library provides functions for the standard features required to load these overlay modules (getting overlay information, loading executable code, and starting constructors/destructors). Within the file system the overlay modules will be treated as a single nameless file, so if necessary, it is also possible to customize the load process with the same tweaks that can be applied when loading files normally.

See FS Library Sample Demos and the description of the `makelcf` tool for information about the procedure for using overlays.

`Overlay Function List
`

## See Also

`FS Function List
`

## Revision History

2009/12/11 Added the definition of a standard archive.
2008/09/26 Corrected an anchor tag formatting mistake.
2008/09/12 Initial version.

CONFIDENTIAL