The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
block_device.h File Reference
#include "common/stdint.h"

Go to the source code of this file.

Data Structures

struct  block_device
 block device abstraction for reading blocks from a storage device. More...

Typedefs

typedef struct block_device block_device_t
typedef bool(*) BlockReadFn(block_device_t *device, uint32_t startBlock, uint8_t blockCount, void *dest)
typedef bool(*) BlockWriteFn(block_device_t *device, uint32_t startBlock, uint8_t blockCount, const void *src)
typedef bool(*) BlockFlushFn(block_device_t *device)
typedef bool(*) BlockTrimFn(block_device_t *device, uint32_t startBlock, uint32_t blockCount)

Functions

bool block_device_read (block_device_t *device, uint32_t startBlock, uint8_t blockCount, void *dest)
 read blocks from a block device.
bool block_device_write (block_device_t *device, uint32_t startBlock, uint8_t blockCount, const void *src)
 write blocks to a block device.
bool block_device_flush (block_device_t *device)
 flush any cached writes to the underlying media.
bool block_device_trim (block_device_t *device, uint32_t startBlock, uint32_t blockCount)
 hint that a range of blocks is no longer in use (TRIM/discard).

Typedef Documentation

◆ block_device_t

typedef struct block_device block_device_t

◆ BlockReadFn

typedef bool(*) BlockReadFn(block_device_t *device, uint32_t startBlock, uint8_t blockCount, void *dest)

◆ BlockWriteFn

typedef bool(*) BlockWriteFn(block_device_t *device, uint32_t startBlock, uint8_t blockCount, const void *src)

◆ BlockFlushFn

typedef bool(*) BlockFlushFn(block_device_t *device)

◆ BlockTrimFn

typedef bool(*) BlockTrimFn(block_device_t *device, uint32_t startBlock, uint32_t blockCount)

Function Documentation

◆ block_device_read()

bool block_device_read ( block_device_t * device,
uint32_t startBlock,
uint8_t blockCount,
void * dest )

read blocks from a block device.

Parameters
deviceinitialized block device backend.
startBlockstarting block number to read from.
blockCountnumber of blocks to read.
destdestination buffer to store the read data.
Returns
true on success. false on failure.

◆ block_device_write()

bool block_device_write ( block_device_t * device,
uint32_t startBlock,
uint8_t blockCount,
const void * src )

write blocks to a block device.

Parameters
deviceinitialized block device backend.
startBlockstarting block number to write to.
blockCountnumber of blocks to write.
srcsource buffer containing the data to write.
Returns
true on success. false on failure.

◆ block_device_flush()

bool block_device_flush ( block_device_t * device)

flush any cached writes to the underlying media.

devices without a write-back cache leave the flush op NULL, this wrapper treats that as a successful no-op so callers can flush unconditionally.

Parameters
deviceinitialized block device backend.
Returns
true on success (including "nothing to flush"), false on I/O error.

◆ block_device_trim()

bool block_device_trim ( block_device_t * device,
uint32_t startBlock,
uint32_t blockCount )

hint that a range of blocks is no longer in use (TRIM/discard).

this is only an optimization for SSDs and virtual disks, devices that do not support it leave the trim op NULL and this wrapper is a no-op success.

Parameters
deviceinitialized block device backend.
startBlockfirst block in the range.
blockCountnumber of blocks in the range.
Returns
true on success (including "not supported"), false on error.