nn::fs Namespace

Description

Namespace for the file system API.

You must first call the nn::fs::Initialize function to initialize the library before using any of the functions or classes in the nn::fs namespace.

The CTR file system is a collection of archives distinguished by their archive names. Files and directories are identified in the various archives by passing an archive path name, after which the specified operation is carried out. Archive types differ in various ways such as their available operations, their restrictions on path names, and the number of files that can be opened, but all types can generally be accessed using the same interface.

The user specifies a path name in the format <archive name>:<archive path> to work with files or directories. The basic maximum length for archive paths is 253 characters, but certain archive types may have their own additional restrictions. For archives with a hierarchical directory structure, slashes ("/") are used as the directory delimiter.

Archives must be mounted before they can be accessed. Each archive type has its own mount function, and the arguments of those functions differ. If you specify an archive name when mounting an archive, you can then access that archive using a path that begins with the archive name. Once you no longer need the archive, you can unmount it by calling Unmount.

ROM archives are read-only archives for referencing the ROMFS that was created at build time. When ROM archives are used, they require a working memory region to be passed by the user application. These archives therefore require that a working memory region be specified when they are mounted by the nn::fs::MountRom function. The numbers of files and directories that can be opened in ROM archives are passed as arguments to the nn::fs::MountRom function, but the only constraint on these numbers is the amount of available memory. We recommend passing values to the nn::fs::MountRom function that are no more than what you need. You can also choose whether to cache metadata such as the ROM filenames and directory names. If you enable caching, a larger working region will be required, but your application will be able to open files and work with directories more quickly.

Save data (SaveData) archives are used for accessing program-specific save data regions. For programs launched from a CTR card (emulation memory), these archives access backup memory on the CTR card. For programs launched from NAND memory, these archives access save data created in NAND memory. Save data archives use a file system with a hierarchical directory structure, so they support the same types of file and directory operations that typical file systems do. Directory and file names in a save data archive are limited to a maximum of 16 characters.

Although the nn::fs::MountSaveData function is used to mount save data archives, you must format the save data region with the nn::fs::FormatSaveData function before you use save data for the first time. When you format a save data region, you can specify the maximum number of files and directories that can be created in it.

The specifications of the save data that can be accessed by save data archives may change in the future; for example, features might be added to prevent data corruption.

Extended save data archives are archives created on an SD Memory Card where the data memory region is managed separately from save data. In order to use an extended save data archive, the application must explicitly create one. File and directory operations are available just as with a save data archive, but there is a limit of 248 characters on path length.

SDMC archives are used for directly accessing SD Memory Cards for debugging purposes. An inserted SD Memory Card can be mounted using the MountSdmc function. To mount a previously mounted SD Memory Card that has been pulled out and then re-inserted, it must first be unmounted using the nn::fs::Unmount function and then the nn::fs::MountSdmc function must be executed again. SDMC archives are only for debugging and cannot be accessed from retail versions.

Namespaces

nn::fs::hio A namespace that includes functions used to directly access files on a computer (PC).

Classes

nn::fs::Directory A class used for directory operations.
nn::fs::FileInputStream Class for reading from files.
nn::fs::FileOutputStream Class for writing to files.
nn::fs::FileStream Class for reading from and writing to files.

Enumerated Types

PositionBase Group of constants that indicate the position of file read/writes.

typedef Definitions

FileReader A typedef for FileInputStream.

Functions

GetRomRequiredMemorySize Gets the size of memory needed to mount a ROM archive.
MountRom Mounts a ROM archive.
FormatSaveData Formats a save data region.
MountSaveData Mounts a save data archive.
CommitSaveData Commits a change to the save data.
(Note: The commit feature has not yet been implemented.)
CreateExtSaveData Creates an extended save data memory region.
MountExtSaveData Mounts extended save data.
CreateAndMountExtSaveData Creates extended save data and then mounts it.
FormatAndMountExtSaveData Formats extended save data and mounts it.
ReadExtSaveDataIcon Reads extended save data icons.
Unmount Unmounts an archive.
MountSdmc Mounts an archive that directly accesses the SD Memory Card (for debugging only).
GetFileSystemSize Gets the total media capacity and amount of free space.
GetArchiveFreeBytes Gets the amount of free space in the archive.
Initialize Initializes the FS library.
RegisterCardInsertedEvent Registers the nn::os::LightEvent object that is signaled when a game card is inserted.
UnregisterCardInsertedEvent Unregisters the nn::fs::RegisterCardInsertedEvent object.
RegisterCardEjectedEvent Registers the nn::os::LightEvent object that is signaled when a game card is pulled out.
UnregisterCardEjectedEvent Unregisters the nn::fs::RegisterCardEjectedEvent object.
IsCardInserted Returns whether a game card has been inserted.
RegisterSdmcInsertedEvent Registers the nn::os::LightEvent object that is signaled when an SD Memory Card is inserted.
UnregisterSdmcInsertedEvent Unregisters the nn::fs::RegisterSdmcInsertedEvent object.
RegisterSdmcEjectedEvent Registers the nn::os::LightEvent object that is signaled when an SD Memory Card is pulled out.
UnregisterSdmcEjectedEvent Unregisters the nn::fs::RegisterSdmcEjectedEvent object.
IsSdmcInserted Returns a value indicating whether an SD Card has been inserted.
IsSdmcWritable Returns a value indicating whether an SD Card is writable.
DeleteFile Deletes a file.
TryDeleteFile Deletes a file.
RenameFile Renames a file.
TryRenameFile Renames a file.
DeleteDirectory Deletes a directory.
TryDeleteDirectory Deletes a directory.
TryDeleteDirectoryRecursively Deletes directories recursively.
CreateDirectory Creates a directory.
TryCreateDirectory Creates a directory.
RenameDirectory Renames a directory.
TryRenameDirectory Renames a directory.

Revision History

2010/09/22
Added a description of extended save data.
2010/09/10
Added the MountSdmc function.
2010/09/09
Deleted the InitializeForFileSystemEvent, WaitForInsertSdmc, and WaitForEjectSdmc functions. Added the RegisterSdmcInsertedEvent, UnregisterSdmcInsertedEvent, RegisterSdmcEjectedEvent, and UnregisterSdmcEjectedEvent functions.
2010/01/07
Initial version.

CONFIDENTIAL