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

Description

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.

Structures

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.

0x00 - FreeUnit

Syntax

int BlockBuffer_FreeUnit(BlockBuffer_Unit *unit);

Properties

Description

This function frees unit.

A unit can only be freed when there's no block from that unit in use.

Return value

0x01 - GetBlock

Syntax

int BlockBuffer_GetBlock(BlockBuffer_Unit *unit, unsigned int blockN, int prop, BlockBuffer_Block **block);

Properties

Description

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:

Return value

0x02 - GetBlockSize

Syntax

int BlockBuffer_GetBlockSize(BlockBuffer_Unit *unit, unsigned int *size);

Properties

Description

This function gets the logical block size in bytes of unit and puts it in size.

Return value

0x03 - GetHardBlockSize

Syntax

int BlockBuffer_GetHardBlockSize(BlockBuffer_Unit *unit, unsigned int *size);

Properties

Description

This function gets the hardware block size in bytes of unit and puts it in size.

Return value

0x04 - RegisterUnit

Syntax

int BlockBuffer_RegisterUnit(const char *devImp, unsigned int unitN, BlockBuffer_Unit **unit);

Properties

Description

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.

Return value

0x05 - Release

Syntax

int BlockBuffer_Release(BlockBuffer_Unit *unit, BlockBuffer_Block *block);

Properties

Description

This function releases block from unit.

Return value

0x06 - SetBlockSize

Syntax

int BlockBuffer_SetBlockSize(BlockBuffer_Unit *unit, unsigned int size);

Properties

Description

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.

Return value