#include "ctr_io_interface.h"
#include "sdmmc/sdmmc.h"
#include "fatfs/ff.h"
Go to the source code of this file.
|
int | ctr_fatfs_interface_initialize (ctr_fatfs_interface *io, FIL *file) |
| Initialize the given fatfs io interface object. More...
|
|
void | ctr_fatfs_interface_destroy (ctr_fatfs_interface *io) |
| Destroys the given fatfs io interface object. More...
|
|
int | ctr_fatfs_interface_read (void *io, void *buffer, size_t buffer_size, uint64_t position, size_t count) |
| Reads bytes from the given io interface. More...
|
|
int | ctr_fatfs_interface_write (void *io, const void *buffer, size_t buffer_size, uint64_t position) |
| Writes bytes to the given io interface. More...
|
|
int | ctr_fatfs_interface_read_sector (void *io, void *buffer, size_t buffer_size, size_t sector, size_t count) |
| Reads sectors from the given io interface. More...
|
|
int | ctr_fatfs_interface_write_sector (void *io, const void *buffer, size_t buffer_size, size_t sector) |
| Writes sectors from the given io interface. More...
|
|
uint64_t | ctr_fatfs_interface_disk_size (void *io) |
| Returns the size of the underlying disk for the given io interface. More...
|
|
size_t | ctr_fatfs_interface_sector_size (void *io) |
| Returns the size of the sectors used by the io interface, which is 512 bytes for fatfs due to how it is configured. More...
|
|
Destroys the given fatfs io interface object.
- Parameters
-
[in,out] | io | fatfs io interface to deinitialize. |
- Postcondition
- The io interface has been destroyed and cannot be used for accessing the fatfs file as a disk without being re-initialized.
uint64_t ctr_fatfs_interface_disk_size |
( |
void * |
io | ) |
|
Returns the size of the underlying disk for the given io interface.
- Returns
- The size of the file used as the backing for the given io interface.
Initialize the given fatfs io interface object.
Note that any size file greater or equal than a single sector will be accepted by the constructor, but the io operations will ignore the trailing data on the file if the file size isn't divisible by the sector size. In other words, the effective size of the disk is f_size(file)/0x200, using integer arithmetic. In order for reads to work the file must have been opened using FA_READ, and for writes to work both FA_READ and FA_WRITE.
- Parameters
-
[out] | io | fatfs io interface to initialize. |
[in,out] | file | File to set up as a disk. |
- Returns
- 0 on success, anything else on a failure.
int ctr_fatfs_interface_read |
( |
void * |
io, |
|
|
void * |
buffer, |
|
|
size_t |
buffer_size, |
|
|
uint64_t |
position, |
|
|
size_t |
count |
|
) |
| |
Reads bytes from the given io interface.
- Parameters
-
[in,out] | io | The io interface to use for reading. |
[out] | buffer | Pointer to the buffer. |
[in] | buffer_size | The size of the buffer in bytes. |
[in] | position | Position/address in the io interface to read from. |
[in] | count | The number of bytes to read. |
- Returns
- 0 upon success, anything else means an error.
int ctr_fatfs_interface_read_sector |
( |
void * |
io, |
|
|
void * |
buffer, |
|
|
size_t |
buffer_size, |
|
|
size_t |
sector, |
|
|
size_t |
count |
|
) |
| |
Reads sectors from the given io interface.
fatfs is configured to only use 512 byte sectors.
- Parameters
-
[in,out] | io | The io interface to use for reading. |
[out] | buffer | Pointer to the buffer. |
[in] | buffer_size | The size of the buffer in bytes. |
[in] | sector | Sector position in the io interface to read from. |
[in] | count | The number of sectors to read. |
- Returns
- 0 upon success, anything else means an error.
size_t ctr_fatfs_interface_sector_size |
( |
void * |
io | ) |
|
Returns the size of the sectors used by the io interface, which is 512 bytes for fatfs due to how it is configured.
- Returns
- 512 bytes as the sector size for NAND.
int ctr_fatfs_interface_write |
( |
void * |
io, |
|
|
const void * |
buffer, |
|
|
size_t |
buffer_size, |
|
|
uint64_t |
position |
|
) |
| |
Writes bytes to the given io interface.
- Parameters
-
[in,out] | io | The io interface to use for writing. |
[in] | buffer | Pointer to the buffer. |
[in] | buffer_size | The size of the buffer, and the number of bytes to write. |
[in] | position | Position/address in the io interface to write to. |
- Returns
- 0 upon success, anything else means an error.
int ctr_fatfs_interface_write_sector |
( |
void * |
io, |
|
|
const void * |
buffer, |
|
|
size_t |
buffer_size, |
|
|
size_t |
sector |
|
) |
| |
Writes sectors from the given io interface.
fatfs is configured to only use 512 byte sectors.
- Parameters
-
[in,out] | io | The io interface to use for writing. |
[in] | buffer | Pointer to the buffer. |
[in] | buffer_size | The size of the buffer, and the number of bytes to write. If the number is not a multiple of the sector size, this function will only write all the full sectors it can, ignoring the end of the buffer that doesn't fit a sector. |
[in] | sector | Sector Position in the io interface to write to. |
- Returns
- 0 upon success, anything else means an error.