libctr9
Nintendo 3DS ARM9 library
ctr_nand_interface.h File Reference
#include "ctr_io_interface.h"
#include "sdmmc/sdmmc.h"

Go to the source code of this file.

Data Structures

struct  ctr_nand_interface
 io interface object for accessing NAND. More...
 

Functions

int ctr_nand_interface_initialize (ctr_nand_interface *io)
 Initialize the given NAND io interface object. More...
 
void ctr_nand_interface_destroy (ctr_nand_interface *io)
 Destroys the given NAND io interface object. More...
 
int ctr_nand_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_nand_interface_write (void *io, const void *buffer, size_t buffer_size, uint64_t position)
 Writes bytes to the given io interface. More...
 
int ctr_nand_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_nand_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_nand_interface_disk_size (void *io)
 Returns the size of the underlying disk for the given io interface. More...
 
size_t ctr_nand_interface_sector_size (void *io)
 Returns the size of the sectors used by the io interface, which is 512 bytes for NAND. More...
 

Function Documentation

void ctr_nand_interface_destroy ( ctr_nand_interface io)

Destroys the given NAND io interface object.

Parameters
[in,out]ioNAND io interface to deinitialize.
Postcondition
The io interface has been destroyed and cannot be used for accessing NAND without being re-initialized.
uint64_t ctr_nand_interface_disk_size ( void *  io)

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

Returns
The size of the NAND as reported by it.
int ctr_nand_interface_initialize ( ctr_nand_interface io)

Initialize the given NAND io interface object.

Parameters
[out]ioNAND io interface to initialize.
Returns
0 on success, anything else on a failure. Unless something has gone horribly wrong with the NAND subsystem, this function shouldn't fail.
int ctr_nand_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]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_nand_interface_read_sector ( void *  io,
void *  buffer,
size_t  buffer_size,
size_t  sector,
size_t  count 
)

Reads sectors from the given io interface.

NAND uses 512 byte sectors.

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_nand_interface_sector_size ( void *  io)

Returns the size of the sectors used by the io interface, which is 512 bytes for NAND.

Returns
512 bytes as the sector size for NAND.
int ctr_nand_interface_write ( void *  io,
const void *  buffer,
size_t  buffer_size,
uint64_t  position 
)

Writes bytes to the given io interface.

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_nand_interface_write_sector ( void *  io,
const void *  buffer,
size_t  buffer_size,
size_t  sector 
)

Writes sectors from the given io interface.

NAND uses 512 byte 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.