libnds
Functions
filesystem.h File Reference

NitroFS filesystem embedded in a NDS ROM. More...

#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>

Functions

void nitroFSExit (void)
 Exits NitroFS.
 
FILE * nitroFSFopenById (uint16_t id, const char *mode)
 Open a NitroFS file directly by its FAT offset ID. More...
 
bool nitroFSInit (const char *basepath)
 Initializes NitroFS. More...
 
int nitroFSInitLookupCache (uint32_t max_buffer_size)
 This function initializes a NitroFS lookup cache. More...
 
int nitroFSOpenById (uint16_t id)
 Open a NitroFS file descriptor directly by its FAT offset ID. More...
 

Detailed Description

NitroFS filesystem embedded in a NDS ROM.

Function Documentation

◆ nitroFSFopenById()

FILE * nitroFSFopenById ( uint16_t  id,
const char *  mode 
)

Open a NitroFS file directly by its FAT offset ID.

This FAT offset ID can be sourced from functions like

See also
stat,
fstat or
readdir - it is equivalent to the st_ino/d_ino value.

In all other functions, this file behaves identically to one sourced from

See also
fopen , and should be closed likewise.
Parameters
idThe FAT offset ID of the file (0x0000..0xEFFF).
modeThe file open mode. Only "r" and "rb" are supported.
Returns
A valid file pointer; NULL on error.

◆ nitroFSInit()

bool nitroFSInit ( const char *  basepath)

Initializes NitroFS.

If basepath or argv[0] is provided, an attempt to read the file system using DLDI will be made first. If that fails, the official cartridge protocol will be used instead.

Parameters
basepathThe .nds file path - NULL to auto-detect.
Returns
It returns true on success, false on error.

◆ nitroFSInitLookupCache()

int nitroFSInitLookupCache ( uint32_t  max_buffer_size)

This function initializes a NitroFS lookup cache.

This lookup cache allows avoiding expensive SD card lookups for large and/or backwards seeks, at the expensive of RAM usage.

This function will return 0 on non-DLDI/SD NitroFS accesses, as lookup caches are unnecessary in these situations.

Parameters
max_buffer_sizeThe maximum buffer size, in bytes.
Returns
0 if the initialization was successful, a non-zero value on error.

◆ nitroFSOpenById()

int nitroFSOpenById ( uint16_t  id)

Open a NitroFS file descriptor directly by its FAT offset ID.

This FAT offset ID can be sourced from functions like

See also
stat,
fstat or
readdir - it is equivalent to the st_ino/d_ino value.

In all other functions, this file descriptor behaves identically to one sourced from

See also
open , and should be closed likewise.
Parameters
idThe FAT offset ID of the file (0x0000..0xEFFF).
Returns
A valid file descriptor; -1 on error.