libnds
Loading...
Searching...
No Matches
Macros | Functions
fat.h File Reference

Simple replacement of libfat. More...

#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <nds/ndstypes.h>

Macros

#define ATTR_ARCHIVE   0x20
 Archive.
 
#define ATTR_DIRECTORY   0x10
 Directory.
 
#define ATTR_HIDDEN   0x02
 Hidden.
 
#define ATTR_READONLY   0x01
 Read only.
 
#define ATTR_SYSTEM   0x04
 System.
 
#define ATTR_VOLUME   0x08
 Volume (Unused in FatFs)
 

Functions

int FAT_getAttr (const char *file)
 Get FAT attributes of a file.
 
int FAT_setAttr (const char *file, uint8_t attr)
 Set FAT attributes of a file.
 
WARN_UNUSED_RESULT char * fatGetDefaultCwd (void)
 This function returns the default current working directory.
 
const char * fatGetDefaultDrive (void)
 This function returns the default drive ("sd:/" or "fat:/").
 
WARN_UNUSED_RESULT bool fatInit (int32_t cache_size_pages, bool set_as_default_device)
 This function initializes the FAT filesystem with a default cache size.
 
WARN_UNUSED_RESULT bool fatInitDefault (void)
 This function calls fatInit() with the default cache size (5 pages = 20 KB).
 
int fatInitLookupCache (int fd, uint32_t max_buffer_size)
 This function initializes a lookup cache on a given FAT file. For NitroFS, use.
 

Detailed Description

Simple replacement of libfat.

Function Documentation

◆ FAT_getAttr()

int FAT_getAttr ( const char *  file)

Get FAT attributes of a file.

This function works when used on NitroFS.

On error, this function sets errno to an error code.

Parameters
filePath to the file.
Returns
A combination of ATTR_* flags with the attributes of the file. On error, it returns -1.

◆ FAT_setAttr()

int FAT_setAttr ( const char *  file,
uint8_t  attr 
)

Set FAT attributes of a file.

This function fails when used on NitroFS (it's read-only).

On error, this function sets errno to an error code.

Parameters
filePath to the file.
attrA combination of ATTR_* flags with the new attributes of the file.
Returns
0 on success, -1 on error.

◆ fatGetDefaultCwd()

WARN_UNUSED_RESULT char * fatGetDefaultCwd ( void  )

This function returns the default current working directory.

It is extracted from argv[0] if it has been provided by the loader. If the format of the path provided by the loader is incorrect, or if no argv[0] was provided, it will default to the root of the filesystem.

The string is allocated with strdup() internally, so the caller of fatGetDefaultCwd() must use free() to free it.

For example, this function may return "sd:/folder/" or "fat:/".

Returns
Returns a string with the path.

◆ fatGetDefaultDrive()

const char * fatGetDefaultDrive ( void  )

This function returns the default drive ("sd:/" or "fat:/").

It is extracted from argv[0] if it has been provided by the loader.

If the format of the path provided by the loader is incorrect, or if no argv[0] was provided, it will default to the root of the filesystem. In the case of DSi, the default drive is the SD card. In the case of DS, the default drive is DLDI.

The returned string must not be passed to free().

Returns
Returns a string with the path.

◆ fatInit()

WARN_UNUSED_RESULT bool fatInit ( int32_t  cache_size_pages,
bool  set_as_default_device 
)

This function initializes the FAT filesystem with a default cache size.

It works differently in a regular DS than in a DSi:

  • DS: It will try to use DLDI to initialize access to the SD card of the flashcard. If it isn't possible it returns false. If it succeedes, it returns true.
  • DSi: It will try to initialize access to the internal SD slot, and the SD of the flashcard. It will only return false if the internal slot of the DSi can't be accessed, and it will return true if it can.

The initial working directory is "fat:/" on the DS (DLDI), and "sd:/" on DSi. On the DSi it is possible to switch between both filesystems with chdir().

This function can be called multiple times, only the first one has any effect. Any call after the first one returns the value returned the first time.

Parameters
cache_size_pagesThe desired size in pages. One page is made of 8 sectors (512 bytes each, 4KB in total). Values < 0 leave the cache size decision to the FAT filesystem implementation.
set_as_default_deviceIgnored, kept for compatibility with libfat.
Returns
It returns true on success, false on error.

◆ fatInitDefault()

WARN_UNUSED_RESULT bool fatInitDefault ( void  )

This function calls fatInit() with the default cache size (5 pages = 20 KB).

Returns
It returns true on success, false on error.

◆ fatInitLookupCache()

int fatInitLookupCache ( int  fd,
uint32_t  max_buffer_size 
)

This function initializes a lookup cache on a given FAT file. For NitroFS, use.

See also
nitrofsInitLookupCache instead.

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

Note that, if the file is opened for writing, using this function will prevent the file's size from being expanded.

Parameters
fdThe file descriptor to initialize. Use fileno(file) for FILE * inputs.
max_buffer_sizeThe maximum buffer size, in bytes.
Returns
0 if the initialization was successful, a non-zero value on error.