Filesystem Reference
Data Structures
-
CTR_FS_MAX_FILENAME_LENGTH
Maximum length of a filename.
-
CTR_FS_THIS
Global Filesystem Context Data.
A thread-safe reference to the global Filesystem context data. This is created automatically during libctr startup, and should NEVER be allocated or freed by the user.
- Note
- If the filesystem is mounted with ctrFsMount(), then users will not need to use this. By default, libctr uses CTR_FS_THIS when mounting the filesystem.
-
enum
CtrFsMode
Mode values.
- See
- ctrFsMkdir()
Values:
-
CTR_FS_MODE_NONE
= 0x00 Default mode.
-
enum
CtrFsOrigin
File position values.
Values:
-
CTR_FS_SEEK_SET
= 0x00 Seek from the beginning.
-
CTR_FS_SEEK_CUR
= 0x01 Seek from the current position.
-
CTR_FS_SEEK_END
= 0x02 Seek from the end.
-
-
enum
CtrFsType
File types.
Values:
-
CTR_FS_TYPE_UNKNOWN
= 0x00 Unrecognized entry.
-
CTR_FS_TYPE_DIRECTORY
= 0x01 Directory entry.
-
CTR_FS_TYPE_REGULAR
= 0x02 Regular file entry.
-
-
struct
CtrFsStat
File status and information.
Public Members
-
uint64_t
st_size
File size.
-
uint64_t
-
struct
CtrFsStatus
Filesystem status and availability.
Public Members
-
uint8_t
available
Is the filesystem usable?
-
uint8_t
writable
Is the filesystem writable?
-
uint8_t
-
struct
CtrFsDirent
Directory entry.
Public Members
-
uint8_t
d_type
File type.
-
uint8_t
d_namelen
Length of string in d_name.
-
char
d_name
[CTR_FS_MAX_FILENAME_LENGTH+1] Filename.
-
uint8_t
-
typedef
CtrFsContextData
Filesystem Context Data.
CtrFsContextData
is an opaque type. It should NEVER be modified by users.
Functions
-
CtrFsContextData *
ctrFsContextDataNew
(void) Create a new filesystem context.
- Warning
- NEVER use this function to initialize CTR_FS_THIS.
- Return
- A newly created Filesystem Context.
-
void
ctrFsContextDataFree
(CtrFsContextData *context) Release a Filesystem context.
- Warning
- NEVER call this function for CTR_FS_THIS.
- Parameters
context
-Filesystem context to release.
-
int
ctrFsOpen
(CtrFsContextData *context, int *fd, const char *path, int flags) Open a file.
- Return
- On success, 0 is returned. On error, -1 is returned.
- Parameters
context
-Filesystem Context Data.
fd
-File descriptor.
path
-Path to file.
flags
-Flags. See CtrFsOpenFlags.
-
int
ctrFsRead
(CtrFsContextData *context, int fd, void *buffer, uint64_t size, uint64_t *osize) Read from a file.
- Return
- On success, 0 is returned. On error, -1 is returned.
- Parameters
context
-Filesystem Context Data.
fd
-File descriptor.
buffer
-Buffer to hold file contents.
size
-Size to read.
osize
-Actual size read from file.
-
int
ctrFsWrite
(CtrFsContextData *context, int fd, const void *buffer, uint64_t size, uint64_t *osize) Write to a file.
- Return
- On success, 0 is returned. On error, -1 is returned.
- Parameters
context
-Filesystem Context Data.
fd
-File descriptor.
buffer
-Buffer to write to file.
size
-Size to write.
osize
-Actual size written to file.
-
int
ctrFsClose
(CtrFsContextData *context, int fd) Close a file.
- Return
- On success, 0 is returned. On error, -1 is returned.
- Parameters
context
-Filesystem Context Data.
fd
-File descriptor.
-
int
ctrFsOpendir
(CtrFsContextData *context, int *fd, const char *path) Open a directory.
- Return
- On success, 0 is returned. On error, -1 is returned.
- Parameters
context
-Filesystem Context Data.
fd
-File descriptor.
path
-Path to directory.
-
int
ctrFsReaddir
(CtrFsContextData *context, int fd, CtrFsDirent *dir) Read a directory entry.
- Return
- On success, 0 is returned. On error, -1 is returned.
- Parameters
context
-Filesystem Context Data.
fd
-File descriptor.
dir
-Directory information.
-
int
ctrFsClosedir
(CtrFsContextData *context, int fd) Close a directory.
- Return
- On success, 0 is returned. On error, -1 is returned.
- Parameters
context
-Filesystem Context Data.
fd
-File descriptor.
-
int
ctrFsStat
(CtrFsContextData *context, const char *path, CtrFsStat *st) Get file status/information (using a filename path).
- Return
- On success, 0 is returned. On error, -1 is returned.
- Parameters
context
-Filesystem Context Data.
path
-Path to a file or directory.
st
-File information.
-
int
ctrFsFstat
(CtrFsContextData *context, int fd, CtrFsStat *st) Get file status/information (using a file descriptor).
- Return
- On success, 0 is returned. On error, -1 is returned.
- Parameters
context
-Filesystem Context Data.
fd
-File descriptor.
st
-File information.
-
int
ctrFsMkdir
(CtrFsContextData *context, const char *path, CtrFsMode mode) Create a new directory.
- Return
- On success, 0 is returned. On error, -1 is returned.
- Parameters
context
-Filesystem Context Data.
path
-Path to directory to be created.
mode
-Mode for the new directory.
-
int
ctrFsRename
(CtrFsContextData *context, const char *source, const char *dest) Change the name of a file.
- Return
- On success, 0 is returned. On error, -1 is returned.
- Parameters
context
-Filesystem Context Data.
source
-Path of an existing filename.
dest
-Path to the new filename.
-
int
ctrFsRmdir
(CtrFsContextData *context, const char *path) Delete a directory.
- Return
- On success, 0 is returned. On error, -1 is returned.
- Parameters
context
-Filesystem Context Data.
path
-Path to a directory.
-
int
ctrFsUnlink
(CtrFsContextData *context, const char *path) Delete a file.
- Return
- On success, 0 is returned. On error, -1 is returned.
- Parameters
context
-Filesystem Context Data.
path
-Path to a file.
-
int
ctrFsLseek
(CtrFsContextData *context, int fd, int64_t offset, CtrFsOrigin origin, uint64_t *pos) Change the current position of a file.
- Return
- On success, 0 is returned. On error, -1 is returned.
- Parameters
context
-Filesystem Context Data.
fd
-File descriptor.
offset
-Offset from the origin.
origin
-Seek mode.
pos
-Current position of file (after seeking).
-
int
ctrFsFsync
(CtrFsContextData *context, int fd) Synchronize a file’s data with the filesystem.
- Return
- On success, 0 is returned. On error, -1 is returned.
- Parameters
context
-Filesystem Context Data.
fd
-File descriptor.
-
int
ctrFsSdmcStatus
(CtrFsContextData *context, CtrFsStatus *status) Get the SD card status.
- Return
- On success, 0 is returned. On error, -1 is returned.
- Parameters
context
-Filesystem Context Data.
status
-Current status.
-
int
ctrFsTruncate
(CtrFsContextData *context, const char *path, uint64_t size) Change file size (using a filename path).
- Return
- On success, 0 is returned. On error, -1 is returned.
- Parameters
context
-Filesystem Context Data.
path
-Path to a file.
size
-New file size.
-
int
ctrFsFtruncate
(CtrFsContextData *context, int fd, uint64_t size) Change file size (using a file descriptor).
- Return
- On success, 0 is returned. On error, -1 is returned.
- Parameters
context
-Filesystem Context Data.
fd
-File descriptor.
size
-New file size.
-
int
ctrFsGetAvailableSize
(CtrFsContextData *context, uint64_t *sdmc_size, uint64_t *nand_size) Get free space on the SD card and NAND filesystem.
- Return
- On success, 0 is returned. On error, -1 is returned.
- Parameters
context
-Filesystem Context Data.
sdmc_size
-Available space on the SD card.
nand_size
-Available space on the NAND filesystem.
-
int
ctrFsMount
(CtrFsContextData *context) Mount the context as the default filesystem.
A context that is mounted is used by newlib. So, calling
ctrFsMount(CTR_FS_THIS)
will allow an application to use the SD card filesystem withfopen
/fclose
.- Return
- On success, 0 is returned. On error, -1 is returned.
- Parameters
context
-Filesystem Context Data.