libdragon
Loading...
Searching...
No Matches
Data Fields
filesystem_t Struct Reference

Filesystem hook structure. More...

#include <system.h>

Data Fields

void *(* open )(char *name, int flags)
 Function to call when performing an open command.
 
int(* fstat )(void *file, struct stat *st)
 Function to call when performing a fstat command.
 
int(* stat )(char *name, struct stat *st)
 Function to call when performing a stat command.
 
int(* lseek )(void *file, int ptr, int dir)
 Function to call when performing an lseek command.
 
int(* read )(void *file, uint8_t *ptr, int len)
 Function to call when performing a read operation.
 
int(* write )(void *file, uint8_t *ptr, int len)
 Function to call when performing a write operation.
 
int(* close )(void *file)
 Function to call when performing a close operation.
 
int(* unlink )(char *name)
 Function to call when performing an unlink operation.
 
int(* findfirst )(char *path, dir_t *dir)
 Function to call when performing a findfirst operation.
 
int(* findnext2 )(const char *path, dir_t *dir)
 Function to call when performing a findnext operation.
 
int(* ftruncate )(void *file, int length)
 Truncate a file to a specified length.
 
int(* mkdir )(char *path, mode_t mode)
 Create a directory.
 
int(* ioctl )(void *file, unsigned long cmd, void *argp)
 Perform IO Control Request.
 

Detailed Description

Filesystem hook structure.

Filesystems that do not support one of more of the following methods should provide null pointers instead of empty functions. The newlib hooks will set errno to ENOSYS and return a proper error to userspace.

All filesystems functions must set errno in case of error, to report the proper error to userspace.

Field Documentation

◆ open

void *(* filesystem_t::open) (char *name, int flags)

Function to call when performing an open command.

Parameters
[in]nameFull path of the file to be opened, relative to the root of the filesystem.
[in]flagsOpen flags, such as binary, append, etc. Follows POSIX flags.
Returns
A pointer to an arbitrary file handle assigned by the filesystem code or NULL on error (and errno is set).

◆ fstat

int(* filesystem_t::fstat) (void *file, struct stat *st)

Function to call when performing a fstat command.

Parameters
[in]fileArbitrary file handle returned by filesystem_t::open
[out]stStat structure to populate with file statistics
Returns
0 on success or a negative value on error (and errno is set).

◆ stat

int(* filesystem_t::stat) (char *name, struct stat *st)

Function to call when performing a stat command.

Parameters
[in]fileFull path of the file to be examined, relative to the root of the filesystem.
[out]stStat structure to populate with file statistics
Returns
0 on success or a negative value on error (and errno is set).

◆ lseek

int(* filesystem_t::lseek) (void *file, int ptr, int dir)

Function to call when performing an lseek command.

Parameters
[in]fileArbitrary file handle returned by filesystem_t::open
[in]ptrAn offset from dir to seek.
[in]dirA direction to see, either SEEK_SET, SEEK_CUR or SEEK_END
Returns
The absolute offset in bytes after the seek or a negative value on failure (and errno is set).

◆ read

int(* filesystem_t::read) (void *file, uint8_t *ptr, int len)

Function to call when performing a read operation.

Parameters
[in]fileArbitrary file handle returned by filesystem_t::open
[out]ptrBuffer to place data read into
[in]lenLength of data that should be read into ptr
Returns
The actual number of bytes read into ptr or a negative value on failure (and errno is set).

◆ write

int(* filesystem_t::write) (void *file, uint8_t *ptr, int len)

Function to call when performing a write operation.

Parameters
[in]fileArbitrary file handle returned by filesystem_t::open
[out]ptrBuffer to grab the data to be written
[in]lenLength of data that should be written out of ptr
Returns
The actual number of bytes written or a negative value on failure (and errno is set).

◆ close

int(* filesystem_t::close) (void *file)

Function to call when performing a close operation.

Parameters
[in]fileArbitrary file handle returned by filesystem_t::open
Returns
0 on success or a negative value on failure (and errno is set).

◆ unlink

int(* filesystem_t::unlink) (char *name)

Function to call when performing an unlink operation.

Parameters
[in]nameFull path of the file to be opened, relative to the root of the filesystem.
Returns
0 on success or a negative value on failure (and errno is set).

◆ findfirst

int(* filesystem_t::findfirst) (char *path, dir_t *dir)

Function to call when performing a findfirst operation.

Parameters
[in]pathFull path of the directory to list files from, relative to the root of the filesystem. It always begins with a slash.
[out]dirDirectory structure to place information on the first file in the directory.
Returns
0 on successful lookup, -1 if the directory existed and is empty, or a different negative value on error (in which case, errno will be set).

◆ findnext2

int(* filesystem_t::findnext2) (const char *path, dir_t *dir)

Function to call when performing a findnext operation.

Parameters
[in]pathFull path of the directory to list files from, relative to the root of the filesystem. It always begins with a slash.
[out]dirDirectory structure to place information on the next file in the directory.
Returns
0 on successful lookup, -1 if the directory existed and is empty, or a different negative value on error (in which case, errno will be set).

◆ ftruncate

int(* filesystem_t::ftruncate) (void *file, int length)

Truncate a file to a specified length.

Parameters
fileArbitrary file handle returned by filesystem_t::open
lengthNew length of the file
Returns
0 on success or a negative value on failure (and errno is set)

◆ mkdir

int(* filesystem_t::mkdir) (char *path, mode_t mode)

Create a directory.

Parameters
[in]pathFull path of the directory to create, relative to the root of the filesystem.
[in]modeDirectory permissions
Returns
0 on success or a negative value on failure (errno must be set)

◆ ioctl

int(* filesystem_t::ioctl) (void *file, unsigned long cmd, void *argp)

Perform IO Control Request.

Parameters
[in]fileFile handle
[in]cmdRequest ioctl command code
[in]argpPointer to a request-specific data structure
Returns
0 on success or a negative value on failure (errno must be set)

The documentation for this struct was generated from the following file: