KallistiOS git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches
kos_blockdev_t Struct Reference

A simple block device. More...

#include <kos/blockdev.h>

Data Fields

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

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

◆ count_blocks

uint64_t(* kos_blockdev_t::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.

◆ dev_data

void* kos_blockdev_t::dev_data

Internal device data.

◆ flush

int(* kos_blockdev_t::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.

◆ init

int(* kos_blockdev_t::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.

◆ l_block_size

uint32_t kos_blockdev_t::l_block_size

Log base 2 of the bytes per block.

◆ read_blocks

int(* kos_blockdev_t::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.

◆ shutdown

int(* kos_blockdev_t::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.

◆ write_blocks

int(* kos_blockdev_t::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: