General Info | |
Interface: BlockBuffer Files: blockbuffer.h Last change: 30/07/2002 Author: Luiz Henrique Shigunov |
Description
Structures |
Functions | |
0x00 - FreeUnit - Free a device unit 0x01 - GetBlock - Get a block 0x02 - GetBlockSize - Get unit's logical block size 0x03 - GetHardBlockSize - Get unit's hardware block size |
0x04 - RegisterUnit - Register a device unit 0x05 - Release - Release a block 0x06 - SetBlockSize - Set unit's logical block size |
This page describes the BlockBuffer interface which provides access to block devices through the use of a cache of blocks to get better performance.
BlockBuffer interface provides buffering services for block devices. The main objective is to keep most used blocks in memory and so minimize device usage.
It manages all blocks to get the biggest memory usage without interfering in the memory available to other modules.
Usage should be: get a block for reading/writing, use it, release the block so others can use it too. Each block has a read/write lock where many can read, but only one thread can write at the same time.
Every device to be registered must implement BlockDev interface.
typedef struct { char *data; void *avail1; void *avail2; unsigned int flags; unsigned int blockN; } BlockBuffer_Block;
Where data is a pointer to block's data. avail1 and avail2 are available to who gets the block for reading or writing. flags is not used yet. blockN is the block number.
int BlockBuffer_FreeUnit(BlockBuffer_Unit *unit);
This function frees unit.
A unit can only be freed when there's no block from that unit in use.
int BlockBuffer_GetBlock(BlockBuffer_Unit *unit, unsigned int blockN, int prop, BlockBuffer_Block **block);
This function gets blockN from unit and puts it in block.
Many threads can get the same block for reading at a time, but only one can get for writing at a time.
prop must be 0 or the sum of:
int BlockBuffer_GetBlockSize(BlockBuffer_Unit *unit, unsigned int *size);
This function gets the logical block size in bytes of unit and puts it in size.
int BlockBuffer_GetHardBlockSize(BlockBuffer_Unit *unit, unsigned int *size);
This function gets the hardware block size in bytes of unit and puts it in size.
int BlockBuffer_RegisterUnit(const char *devImp, unsigned int unitN, BlockBuffer_Unit **unit);
This function registers unitN from device devImp, which must implement BlockDev interface.
Only one module can use the same unit at a time.
If all goes ok, unit will have the unit ID.
int BlockBuffer_Release(BlockBuffer_Unit *unit, BlockBuffer_Block *block);
This function releases block from unit.
int BlockBuffer_SetBlockSize(BlockBuffer_Unit *unit, unsigned int size);
This function sets the logical block size of unit to size, which must be 512, 1024, 2048 or 4096 bytes.
No blocks from this unit can be in use.