KallistiOS  ##version##
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
Data Fields
kos_blockdev Struct Reference

A simple block device. More...

#include <kos/blockdev.h>

Data Fields

void * dev_data
 Internal device data. More...
 
uint32_t l_block_size
 Log base 2 of the bytes per block. More...
 
int(* init )(struct kos_blockdev *d)
 Initialize the block device. More...
 
int(* shutdown )(struct kos_blockdev *d)
 Shut down the block device. More...
 
int(* read_blocks )(struct kos_blockdev *d, uint64_t block, size_t count, void *buf)
 Read a number of blocks from the device. More...
 
int(* write_blocks )(struct kos_blockdev *d, uint64_t block, size_t count, const void *buf)
 Write a number of blocks to the device. More...
 
uint64_t(* count_blocks )(struct kos_blockdev *d)
 Count the number of blocks on the device. More...
 
int(* flush )(struct kos_blockdev *d)
 Flush the write cache (if any) of the device. More...
 

Detailed Description

A simple block device.

This structure represents a single block device. Each block device should be associated with exactly one filesystem and is used to actually read the data from the disk (or other device) where it is stored.

By using a block device with any new filesystems, we can abstract away a few things so that filesystems can be used with a variety of different "devices", such as the SD card reader for the Dreamcast or a disk image file of some sort.

Field Documentation

uint64_t(* kos_blockdev::count_blocks)(struct kos_blockdev *d)

Count the number of blocks on the device.

This function should return the total number of blocks on the device. There is no expectation of the device to keep track of which blocks are in use or anything else of the sort.

Parameters
dThe device to read the block count from.
Returns
The number of blocks that the device has.
void* kos_blockdev::dev_data

Internal device data.

int(* kos_blockdev::flush)(struct kos_blockdev *d)

Flush the write cache (if any) of the device.

This function shall signal to the device that any write caches that are present on the device shall be flushed so that all data written to this point shall persist to the underlying storage.

Parameters
dThe device to flush caches on.
Return values
0On success.
-1On failure. Set errno as appropriate.
int(* kos_blockdev::init)(struct kos_blockdev *d)

Initialize the block device.

This function should do any necessary initialization to use the block device passed in.

Parameters
dThe device to initialize.
Return values
0On success.
-1On failure. Set errno as appropriate.
uint32_t kos_blockdev::l_block_size

Log base 2 of the bytes per block.

int(* kos_blockdev::read_blocks)(struct kos_blockdev *d, uint64_t block, size_t count, void *buf)

Read a number of blocks from the device.

This function should read the specified number of device blocks into the given buffer. The buffer will already be allocated by the caller.

Parameters
dThe device to read from.
blockThe first block to read.
countThe number of blocks to read.
bufThe buffer to read into.
Return values
0On success.
-1On failure. Set errno as appropriate.
int(* kos_blockdev::shutdown)(struct kos_blockdev *d)

Shut down the block device.

This function should do any teardown work that is needed to clean up the block device.

Parameters
dThe device to shut down.
Return values
0On success.
-1On failure. Set errno as appropriate.
int(* kos_blockdev::write_blocks)(struct kos_blockdev *d, uint64_t block, size_t count, const void *buf)

Write a number of blocks to the device.

This function should write the specified number of device blocks onto the device from the given buffer.

Parameters
dThe device to write to.
blockThe first block to write.
countThe number of blocks to write.
bufThe buffer to write from.
Return values
0On success.
-1On failure. Set errno as appropriate.

The documentation for this struct was generated from the following file: