libdragon
|
DragonFS. More...
Go to the source code of this file.
Macros | |
#define | DFS_DEFAULT_LOCATION 0 |
Default filesystem location. | |
#define | MAX_FILENAME_LEN 243 |
Maximum filename length. | |
#define | MAX_DIRECTORY_DEPTH 100 |
Maximum depth of directories supported. | |
#define | FILETYPE(x) ((x) & 3) |
Macro to extract the file type from a DragonFS file flag. | |
DragonFS Return values | |
#define | DFS_ESUCCESS 0 |
Success. | |
#define | DFS_EBADINPUT -1 |
Input parameters invalid. | |
#define | DFS_ENOFILE -2 |
File does not exist. | |
#define | DFS_EBADFS -3 |
Bad filesystem. | |
#define | DFS_ENFILE -4 |
Too many open files. | |
#define | DFS_EBADHANDLE -5 |
Invalid file handle. | |
DragonFS file type flags | |
#define | FLAGS_FILE 0x0 |
This is a file entry. | |
#define | FLAGS_DIR 0x1 |
This is a directory entry. | |
#define | FLAGS_EOF 0x2 |
This is the end of a directory list. | |
Functions | |
int | dfs_init (uint32_t base_fs_loc) |
Initialize the filesystem. | |
int | dfs_chdir (const char *const path) |
Change directories to the specified path. | |
int | dfs_dir_findfirst (const char *const path, char *buf) |
Find the first file or directory in a directory listing. | |
int | dfs_dir_findnext (char *buf) |
Find the next file or directory in a directory listing. | |
int | dfs_open (const char *const path) |
Open a file given a path. | |
int | dfs_read (void *const buf, int size, int count, uint32_t handle) |
Read data from a file. | |
int | dfs_seek (uint32_t handle, int offset, int origin) |
Seek to an offset in the file. | |
int | dfs_tell (uint32_t handle) |
Return the current offset into a file. | |
int | dfs_close (uint32_t handle) |
Close an already open file handle. | |
int | dfs_eof (uint32_t handle) |
Return whether the end of file has been reached. | |
int | dfs_size (uint32_t handle) |
Return the file size of an open file. | |
uint32_t | dfs_rom_addr (const char *path) |
Return the physical address of a file (in ROM space) | |
const char * | dfs_strerror (int error) |
Convert DFS error code into an error string. | |
DragonFS.
int dfs_init | ( | uint32_t | base_fs_loc | ) |
Initialize the filesystem.
Given a base offset where the filesystem should be found, this function will initialize the filesystem to read from cartridge space. This function will also register DragonFS with newlib so that standard POSIX/C file operations work with DragonFS, using the "rom:/" prefix".
The function needs to know where the DFS image is located within the cartridge space. To simplify this, you can pass DFS_DEFAULT_LOCATION which tells dfs_init to search for the DFS image by itself, using the rompak TOC (see rompak_internal.h). Most users should use this option.
Otherwise, if the ROM cannot be built with a rompak TOC for some reason, a virtual address should be passed. This is normally 0xB0000000 + the offset used when building your ROM + the size of the header file used (typically 0x1000).
[in] | base_fs_loc | Virtual address in cartridge space at which to find the filesystem, or DFS_DEFAULT_LOCATION to automatically search for the filesystem in the cartridge (using the rompak). |
int dfs_chdir | ( | const char *const | path | ) |
Change directories to the specified path.
Supports absolute and relative
[in] | path | Relative or absolute path to change directories to |
int dfs_dir_findfirst | ( | const char *const | path, |
char * | buf | ||
) |
Find the first file or directory in a directory listing.
Supports absolute and relative. If the path is invalid, returns a negative DFS_errno. If a file or directory is found, returns the flags of the entry and copies the name into buf.
[in] | path | The path to look for files in |
[out] | buf | Buffer to place the name of the file or directory found |
int dfs_dir_findnext | ( | char * | buf | ) |
Find the next file or directory in a directory listing.
[out] | buf | Buffer to place the name of the next file or directory found |
int dfs_open | ( | const char *const | path | ) |
Open a file given a path.
Check if we have any free file handles, and if we do, try to open the file specified. Supports absolute and relative paths
[in] | path | Path of the file to open |
int dfs_read | ( | void *const | buf, |
int | size, | ||
int | count, | ||
uint32_t | handle | ||
) |
Read data from a file.
Note that no caching is performed: if you need to read small amounts (eg: one byte at a time), consider using standard C API instead (fopen()) which performs internal buffering to avoid too much overhead.
[out] | buf | Buffer to read into |
[in] | size | Size of each element to read |
[in] | count | Number of elements to read |
[in] | handle | A valid file handle as returned from dfs_open. |
int dfs_seek | ( | uint32_t | handle, |
int | offset, | ||
int | origin | ||
) |
Seek to an offset in the file.
[in] | handle | A valid file handle as returned from dfs_open. |
[in] | offset | A byte offset from the origin to seek from. |
[in] | origin | An offset to seek from. Either SEEK_SET , SEEK_CUR or SEEK_END . |
int dfs_tell | ( | uint32_t | handle | ) |
Return the current offset into a file.
[in] | handle | A valid file handle as returned from dfs_open. |
int dfs_close | ( | uint32_t | handle | ) |
Close an already open file handle.
[in] | handle | A valid file handle as returned from dfs_open. |
int dfs_eof | ( | uint32_t | handle | ) |
Return whether the end of file has been reached.
[in] | handle | A valid file handle as returned from dfs_open. |
int dfs_size | ( | uint32_t | handle | ) |
Return the file size of an open file.
[in] | handle | A valid file handle as returned from dfs_open. |
uint32_t dfs_rom_addr | ( | const char * | path | ) |
Return the physical address of a file (in ROM space)
This function should be used for highly-specialized, high-performance use cases. Using dfs_open / dfs_read is generally acceptable performance-wise, and is easier to use rather than managing direct access to PI space.
Direct access to ROM data must go through io_read or dma_read. Do not dereference directly as the console might hang if the PI is busy.
[in] | path | Name of the file |