General Info

Interface: BlockDev
Files: blockdev.h
Last change: 15/02/2004
Author: Luiz Henrique Shigunov
Description
Structures
Functions

0x01 - GetUnitDesc - Get an unit's description
0x00 - GetUnitDescIndex - Get an unit's description

0x02 - Read - Read blocks
0x03 - Write - Write blocks

Description

This page describes the BlockDev interface which provides access to block devices.

A block device is the one that reads/writes fixed size blocks and can read/write blocks in a random order. For instance: can read block 1 and write block 1000.

The number and name of a unit do not need to be the same whenever the module is loaded. But, it would be good if they were the same whenever possible.

That is why a tool to automatically mount file systems when the system starts must use some sort of file system ID to know in which disk the file system is and not use the number or the name of a unit because they can change.

Structures

typedef struct {
    unsigned int unit;
    char *unitName;
    int type;
    int flags;
    unsigned int blockSize;
    unsigned int nBlocks;
} BlockDev_UnitDesc;

Where unit is the unit number, unitName the unit name (string terminating with zero), type the unit type which can be:

flags is the OR (0x01 | 0x08, for instance) of the following values:

blockSize is the physical block size of the unit in bytes and it is a power of 2 (1, 2, 4, 8, 16, ...) and nBlocks is the total unit size in blocks.

blockSize and nBlocks can be zero in some conditions. For example, if there is no floppy in a floppy drive.

typedef struct {
    unsigned int unit;
    unsigned int block;
    unsigned int n;
    void *buffer;
    unsigned int done;
} BlockDev_IO;

Where unit it is the unit number, block the initial block, n the number of blocks, buffer the buffer with data or that will receive data and done the number of blocks processed.

System Functions

These functions are exclusive for system modules.

0x01 - GetUnitDesc

Syntax

int BlockDev_GetUnitDesc(unsigned int unit, BlockDev_UnitDesc *unitDesc, unsigned int size, int prop);

Properties

Description

This function gets the description of unit.

unitDesc is a buffer that will be filled with the unit data and size it is the buffer size.

prop must be the OR (0x01 | 0x08, for instance) of the following values:

The value BlockDev_DO_NOT_READ is used mainly for removable units like floppy. For these units, it is necessary to read media to know some information like the media size, for example.

The value BlockDev_NO_NAME is useful for modules that do not need to know the unit name and so can use sizeof(BlockDev_UnitDesc) as the buffer size.

Return value

0x00 - GetUnitDescIndex

Syntax

int BlockDev_GetUnitDescIndex(unsigned int index, BlockDev_UnitDesc *unitDesc, unsigned int size, int prop);

Properties

Description

This function gets the description of index which is zero based.

unitDesc is a buffer that will be filled with the unit data and size it is the buffer size.

prop must be the OR (0x01 | 0x08, for instance) of the following values:

The value BlockDev_DO_NOT_READ is used mainly for removable units like floppy. For these units, it is necessary to read media to know some information like the media size, for example.

The value BlockDev_NO_NAME is useful for modules that do not need to know the unit name and so can use sizeof(BlockDev_UnitDesc) as the buffer size.

Return value

0x02 - Read

Syntax

int BlockDev_Read(BlockDev_IO *request);

Properties

Description

This function reads n blocks, which must be different than zero, from unit in buffer starting at block including.

done will contain the number of blocks read.

From the request structure only done will be touched. The remaining fields will be unchanged.

Return value

0x03 - Write

Syntax

int BlockDev_Write(BlockDev_IO *request);

Properties

Description

This function writes n blocks, which must be different than zero, from buffer in unit starting at block including.

done will contain the number of blocks written.

From the request structure only done will be touched. The remaining fields will be unchanged.

Return value