libctr9
Nintendo 3DS ARM9 library
ctr_io_interface.h File Reference
#include <stddef.h>
#include <stdint.h>

Go to the source code of this file.

Data Structures

struct  ctr_io_interface
 Virtual table for io interface dispatching. More...
 

Typedefs

typedef int(* ctr_io_interface_read) (void *io, void *buffer, size_t buffer_size, uint64_t position, size_t count)
 Pointer to an io interface function used to read. More...
 
typedef int(* ctr_io_interface_write) (void *io, const void *buffer, size_t buffer_size, uint64_t position)
 Pointer to an io interface function used to write. More...
 
typedef int(* ctr_io_interface_read_sector) (void *io, void *buffer, size_t buffer_size, size_t sector, size_t count)
 Pointer to an io interface function used to read sectors. More...
 
typedef int(* ctr_io_interface_write_sector) (void *io, const void *buffer, size_t buffer_size, size_t sector)
 Pointer to an io interface function used to write sectors. More...
 
typedef uint64_t(* ctr_io_interface_disk_size) (void *io)
 Pointer to an io interface function used to get the size of the disk. More...
 
typedef size_t(* ctr_io_interface_sector_size) (void *io)
 Pointer to an io interface function used to get the sector size in bytes. More...
 

Functions

int ctr_io_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_io_write (void *io, const void *buffer, size_t buffer_size, uint64_t position)
 Writes bytes to the given io interface. More...
 
int ctr_io_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_io_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_io_disk_size (void *io)
 Returns the size of the underlying disk for the given io interface. More...
 
size_t ctr_io_sector_size (void *io)
 Returns the size of the sectors used by the io interface. More...
 

Typedef Documentation

typedef uint64_t(* ctr_io_interface_disk_size) (void *io)

Pointer to an io interface function used to get the size of the disk.

Returns
The size of the io interface's underlying disk storage in bytes.
typedef int(* ctr_io_interface_read) (void *io, void *buffer, size_t buffer_size, uint64_t position, size_t count)

Pointer to an io interface function used to read.

Parameters
[in,out]ioThe io interface to use for reading.
[out]bufferPointer to the buffer.
[in]buffer_sizeThe size of the buffer in bytes.
[in]positionPosition/address in the io interface to read from.
[in]countThe number of bytes to read.
Returns
0 upon success, anything else means an error.
typedef int(* ctr_io_interface_read_sector) (void *io, void *buffer, size_t buffer_size, size_t sector, size_t count)

Pointer to an io interface function used to read sectors.

The definition of a sector is left to the io interface being used. Refer to ctr_io_sector_size as a way to poll how many bytes constitute a sector.

Parameters
[in,out]ioThe io interface to use for reading.
[out]bufferPointer to the buffer.
[in]buffer_sizeThe size of the buffer in bytes.
[in]sectorSector position in the io interface to read from.
[in]countThe number of sectors to read.
Returns
0 upon success, anything else means an error.
typedef size_t(* ctr_io_interface_sector_size) (void *io)

Pointer to an io interface function used to get the sector size in bytes.

Returns
The size of the io interface's sector size in bytes.
typedef int(* ctr_io_interface_write) (void *io, const void *buffer, size_t buffer_size, uint64_t position)

Pointer to an io interface function used to write.

Parameters
[in,out]ioThe io interface to use for writing.
[in]bufferPointer to the buffer.
[in]buffer_sizeThe size of the buffer, and the number of bytes to write.
[in]positionPosition/address in the io interface to write to.
Returns
0 upon success, anything else means an error.
typedef int(* ctr_io_interface_write_sector) (void *io, const void *buffer, size_t buffer_size, size_t sector)

Pointer to an io interface function used to write sectors.

Parameters
[in,out]ioThe io interface to use for writing.
[in]bufferPointer to the buffer.
[in]buffer_sizeThe 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]sectorSector Position in the io interface to write to.
Returns
0 upon success, anything else means an error.

Function Documentation

uint64_t ctr_io_disk_size ( void *  io)

Returns the size of the underlying disk for the given io interface.

This function uses the virtual table in the io interface given to call the correct function to handle the read request.

Returns
The size of the io interface's underlying disk storage in bytes.
int ctr_io_read ( void *  io,
void *  buffer,
size_t  buffer_size,
uint64_t  position,
size_t  count 
)

Reads bytes from the given io interface.

This function uses the virtual table in the io interface given to call the correct function to handle the read request.

Parameters
[in,out]ioThe io interface to use for reading.
[out]bufferPointer to the buffer.
[in]buffer_sizeThe size of the buffer in bytes.
[in]positionPosition/address in the io interface to read from.
[in]countThe number of bytes to read.
Returns
0 upon success, anything else means an error.
int ctr_io_read_sector ( void *  io,
void *  buffer,
size_t  buffer_size,
size_t  sector,
size_t  count 
)

Reads sectors from the given io interface.

This function uses the virtual table in the io interface given to call the correct function to handle the read sectors request.

The definition of a sector is left to the io interface being used. Refer to ctr_io_sector_size as a way to poll how many bytes constitute a sector.

Parameters
[in,out]ioThe io interface to use for reading.
[out]bufferPointer to the buffer.
[in]buffer_sizeThe size of the buffer in bytes.
[in]sectorSector position in the io interface to read from.
[in]countThe number of sectors to read.
Returns
0 upon success, anything else means an error.
size_t ctr_io_sector_size ( void *  io)

Returns the size of the sectors used by the io interface.

This function uses the virtual table in the io interface given to call the correct function to handle the read request.

Returns
The size of the io interface's sector size in bytes.
int ctr_io_write ( void *  io,
const void *  buffer,
size_t  buffer_size,
uint64_t  position 
)

Writes bytes to the given io interface.

This function uses the virtual table in the io interface given to call the correct function to handle the write request.

Parameters
[in,out]ioThe io interface to use for writing.
[in]bufferPointer to the buffer.
[in]buffer_sizeThe size of the buffer, and the number of bytes to write.
[in]positionPosition/address in the io interface to write to.
Returns
0 upon success, anything else means an error.
int ctr_io_write_sector ( void *  io,
const void *  buffer,
size_t  buffer_size,
size_t  sector 
)

Writes sectors from the given io interface.

This function uses the virtual table in the io interface given to call the correct function to handle the write sectors request.

Parameters
[in,out]ioThe io interface to use for writing.
[in]bufferPointer to the buffer.
[in]buffer_sizeThe 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]sectorSector Position in the io interface to write to.
Returns
0 upon success, anything else means an error.