Contiki-Inga 3.x
Files | Data Structures | Macros | Functions
DiskIO Abstraction Layer

Files

file  diskio.c
 
 DiskIO Abstraction Layer Implementation

 
file  diskio.h
 
    DiskIO Layer definitions

 

Data Structures

struct  diskio_device_info
 Stores the necessary information to identify a device using the diskio-Library. More...
 

Macros

#define DISKIO_DEVICE_TYPE_NOT_RECOGNIZED   0
 Allows raw access to disks, used by the MBR-Subsystem.
 
#define DISKIO_MAX_SECTOR_SIZE   512
 Bigger sectors then this are not supported. More...
 
#define DISKIO_DEVICE_TYPE_MASK   0x7f
 Mask used to ignore modifiers like the PARTITION flag.
 

Functions

void diskio_print_device_info (struct diskio_device_info *dev)
 Prints information about the specified device. More...
 
int diskio_read_block (struct diskio_device_info *dev, uint32_t block_address, uint8_t *buffer)
 Reads one block from the specified device and stores it in buffer. More...
 
int diskio_read_blocks (struct diskio_device_info *dev, uint32_t block_start_address, uint32_t num_blocks, uint8_t *buffer)
 Reads multiple blocks from the specified device. More...
 
int diskio_write_block (struct diskio_device_info *dev, uint32_t block_address, uint8_t *buffer)
 Writes a single block to the specified device. More...
 
int diskio_write_blocks_start (struct diskio_device_info *dev, uint32_t block_start_address, uint32_t num_blocks)
 Start writing multiple blocks to the specified device. More...
 
int diskio_write_blocks_next (struct diskio_device_info *dev, uint8_t *buffer)
 Write next of multiple blocks to the specified device. More...
 
int diskio_write_blocks_done (struct diskio_device_info *dev)
 Start writing multiple blocks to the specified device. More...
 
void diskio_set_default_device (struct diskio_device_info *dev)
 Sets the default operation device. More...
 
struct diskio_device_infodiskio_devices ()
 Returns the device-Database. More...
 
int diskio_detect_devices ()
 Creates the internal database of available devices. More...
 

Detailed Description

Note
This interface was inspired by the diskio-interface of the FatFS-Module.

It's normally not important for Filesystem-Drivers to know, what type the underlying storage device is. It's only important that the Driver can write and read on this device. This abstraction layer enabled the filesystem drivers to do exactly that.

Macro Definition Documentation

#define DISKIO_MAX_SECTOR_SIZE   512

Bigger sectors then this are not supported.

May be reduced down to 512 to use less memory.

Definition at line 65 of file diskio.h.

Referenced by diskio_detect_devices().

Function Documentation

int diskio_detect_devices ( )

Creates the internal database of available devices.

Adds virtual devices for multiple Partitions on devices using the MBR-Library. Number of devices in the database is limited by the DISKIO_MAX_DEVICES define. Warning the device numbers may change when calling this function. It should be called once on start but may also be called, if the microSD-Card was ejected to update the device database.

Todo:
Place definitions at proper position

Definition at line 329 of file diskio.c.

References DISKIO_MAX_SECTOR_SIZE, diskio_device_info::first_sector, mbr_primary_partition::lba_first_sector, mbr_primary_partition::lba_num_sectors, mbr_hasPartition(), mbr_init(), mbr_read(), diskio_device_info::num_sectors, diskio_device_info::number, mbr::partition, diskio_device_info::partition, diskio_device_info::sector_size, and diskio_device_info::type.

struct diskio_device_info * diskio_devices ( )
read

Returns the device-Database.

Number of devices in the database is limited by the DISKIO_MAX_DEVICES define.

Returns
pointer to the Array of device infos. No available device entries have the type set to DISKIO_DEVICE_TYPE_NOT_RECOGNIZED.

Definition at line 323 of file diskio.c.

void diskio_print_device_info ( struct diskio_device_info dev)

Prints information about the specified device.

Output Format:
DiskIO Device Info
type = text
number = X
partition = X
num_sectors = X
sector_size = X
first_sector = X

Parameters
*devthe pointer to the device info struct

Definition at line 73 of file diskio.c.

References diskio_device_info::first_sector, diskio_device_info::num_sectors, diskio_device_info::number, diskio_device_info::partition, diskio_device_info::sector_size, and diskio_device_info::type.

int diskio_read_block ( struct diskio_device_info dev,
uint32_t  block_address,
uint8_t *  buffer 
)

Reads one block from the specified device and stores it in buffer.

Parameters
*devthe pointer to the device info struct
block_addressWhich block should be read
*bufferbuffer in which the data is written
Returns
DISKIO_SUCCESS on success, otherwise not 0 for an error

Definition at line 103 of file diskio.c.

Referenced by cfs_fat_mount_device(), cfs_fat_sync_fats(), and mbr_read().

int diskio_read_blocks ( struct diskio_device_info dev,
uint32_t  block_start_address,
uint32_t  num_blocks,
uint8_t *  buffer 
)

Reads multiple blocks from the specified device.

This may or may not be supported for every device. DISKIO_ERROR_OPERATION_NOT_SUPPORTED will be returned in that case.

Parameters
*devthe pointer to the device info
block_start_addressthe address of the first block to be read
num_blocksthe number of blocks to be read
*bufferbuffer in which the data is written
Returns
DISKIO_SUCCESS on success, otherwise not 0 for an error

Definition at line 109 of file diskio.c.

void diskio_set_default_device ( struct diskio_device_info dev)

Sets the default operation device.

This allows to call the diskio_* functions with the dev parameter set to NULL. The functions will then use the default device to operate.

Parameters
*devthe pointer to the device info, which will be the new default device

Definition at line 317 of file diskio.c.

int diskio_write_block ( struct diskio_device_info dev,
uint32_t  block_address,
uint8_t *  buffer 
)

Writes a single block to the specified device.

Parameters
*devthe pointer to the device info
block_addressaddress where the block should be written
*bufferbuffer in which the data is stored
Returns
DISKIO_SUCCESS on success, !0 on error

Definition at line 115 of file diskio.c.

Referenced by cfs_fat_flush(), cfs_fat_sync_fats(), and mbr_write().

int diskio_write_blocks_done ( struct diskio_device_info dev)

Start writing multiple blocks to the specified device.

Parameters
*devthe pointer to the device info
Returns
DISKIO_SUCCESS on success, !0 on error

Definition at line 133 of file diskio.c.

References NULL.

int diskio_write_blocks_next ( struct diskio_device_info dev,
uint8_t *  buffer 
)

Write next of multiple blocks to the specified device.

Parameters
*devthe pointer to the device info
*bufferbuffer in which the data is stored
Returns
DISKIO_SUCCESS on success, !0 on error

Definition at line 127 of file diskio.c.

int diskio_write_blocks_start ( struct diskio_device_info dev,
uint32_t  block_start_address,
uint32_t  num_blocks 
)

Start writing multiple blocks to the specified device.

Parameters
*devthe pointer to the device info
block_start_addressthe address of the first block to be written
num_blocksnumber of blocks to be written
Returns
DISKIO_SUCCESS on success, !0 on error

Definition at line 121 of file diskio.c.

References NULL.