libdragon
|
EEPROM Filesystem. More...
Go to the source code of this file.
Data Structures | |
struct | eepfs_entry_t |
EEPROM filesystem configuration file entry. More... | |
Functions | |
int | eepfs_init (const eepfs_entry_t *entries, size_t count) |
Initializes the EEPROM filesystem. | |
int | eepfs_close (void) |
De-initializes the EEPROM filesystem. | |
int | eepfs_read (const char *path, void *dest, size_t size) |
Reads an entire file from the EEPROM filesystem. | |
int | eepfs_write (const char *path, const void *src, size_t size) |
Writes an entire file to the EEPROM filesystem. | |
int | eepfs_erase (const char *path) |
Erases a file in the EEPROM filesystem. | |
bool | eepfs_verify_signature (void) |
Validates the first block of EEPROM. | |
void | eepfs_wipe (void) |
Erases all blocks in EEPROM and sets a new signature. | |
EEPROM Filesystem.
struct eepfs_entry_t |
EEPROM filesystem configuration file entry.
int eepfs_init | ( | const eepfs_entry_t * | entries, |
size_t | count | ||
) |
Initializes the EEPROM filesystem.
Creates a lookup table of file descriptors based on the configuration and validates that the current EEPROM data is likely to be compatible with the configured file descriptors.
If the configured filesystem does not fit in the available EEPROM blocks on the cartridge, initialization will fail. Even if your total file size fits in EEPROM, your filesystem may not fit due to overhead and padding. Note that 1 block is reserved for the filesystem signature, and all files must start on a block boundary.
You can mitigate this by ensuring that your files are aligned to the 8-byte block size and minimizing wasted space with packed structs.
Each file will take up a minimum of 1 block, plus the filesystem itself reserves the first block of EEPROM, so the entry count has a practical limit of the number of available EEPROM blocks minus 1:
[in] | entries | An array of file paths and sizes; see eepfs_entry_t |
[in] | count | The number of entries in the array |
int eepfs_close | ( | void | ) |
De-initializes the EEPROM filesystem.
This cleans up the file lookup table.
You probably won't ever need to call this.
int eepfs_read | ( | const char * | path, |
void * | dest, | ||
size_t | size | ||
) |
Reads an entire file from the EEPROM filesystem.
[in] | path | Path of file in EEPROM filesystem to read from |
[out] | dest | Buffer to read into |
[in] | size | Size of the destination buffer (in bytes) |
int eepfs_write | ( | const char * | path, |
const void * | src, | ||
size_t | size | ||
) |
Writes an entire file to the EEPROM filesystem.
Each EEPROM block write takes approximately 15 milliseconds; this operation may block for a while!
[in] | path | Path of file in EEPROM filesystem to write to |
[in] | src | Buffer of data to be written |
[in] | size | Size of the source buffer (in bytes) |
int eepfs_erase | ( | const char * | path | ) |
Erases a file in the EEPROM filesystem.
Note that "erasing" a file just means writing it full of zeroes. All files in the filesystem must always exist at the size specified during eepfs_init
Each EEPROM block write takes approximately 15 milliseconds; this operation may block for a while!
Be advised: this is a destructive operation that cannot be undone!
EEPFS_ESUCCESS | if successful |
EEPFS_ENOFILE | if the path is not a valid file |
EEPFS_EBADINPUT | if the path is NULL |
bool eepfs_verify_signature | ( | void | ) |
Validates the first block of EEPROM.
There are no guarantees that the data in EEPROM actually matches the expected layout of the filesystem. There are many reasons why a mismatch can occur: EEPROM re-used from another game; a brand new EEPROM that has never been initialized and contains garbage data; the filesystem has changed between builds or version of software currently in development; EEPROM failing due to age or write limits.
To mitigate these scenarios, it is a good idea to validate that at least the first block of EEPROM matches some known good value.
If the signature matches, the data in EEPROM is probably what the filesystem expects. If not, the best move is to erase everything and start from zero.
true | if the signature in EEPROM matches the filesystem signature |
false | if the signature in EEPROM does not match the filesystem signature |
void eepfs_wipe | ( | void | ) |
Erases all blocks in EEPROM and sets a new signature.
This is useful when you want to erase all files in the filesystem.
Each EEPROM block write takes approximately 15 milliseconds; this operation may block for a while:
You may want to pause audio in advance of calling this.
Be advised: this is a destructive operation that cannot be undone!