Nut/OS  4.10.3
API Reference
blockdev.c File Reference

Generic block I/O device routines. More...

#include <cfg/os.h>
#include <cfg/memory.h>
#include <dev/blockdev.h>
#include <sys/nutdebug.h>
#include <fs/fs.h>
#include <stdlib.h>
#include <errno.h>
#include <memdebug.h>
Include dependency graph for blockdev.c:

Go to the source code of this file.

Data Structures

struct  _BLOCKVOLUME
 Block volume information structure. More...

Typedefs

typedef struct _BLOCKVOLUME BLOCKVOLUME
 Block volume information structure type.

Functions

int NutBlockDeviceInit (NUTDEVICE *dev)
 Initialize the block I/O device.
NUTFILENutBlockDeviceOpen (NUTDEVICE *dev, CONST char *name, int mode, int acc)
 Mount a volume.
int NutBlockDeviceClose (NUTFILE *nfp)
 Unmount a currently mounted volume.
int NutBlockDeviceIOCtl (NUTDEVICE *dev, int req, void *conf)
 Perform block I/O device control functions.
int NutBlockDeviceRead (NUTFILE *nfp, void *buffer, int num)
 Read data blocks from a mounted volume.
int NutBlockDeviceWrite (NUTFILE *nfp, CONST void *buffer, int num)
 Write data blocks to a mounted volume.
int NutBlockDeviceWrite_P (NUTFILE *nfp, PGM_P buffer, int num)
 Write data blocks from program space to a mounted volume.
long NutBlockDeviceSize (NUTFILE *nfp)
 Return the size of a mounted volume.

Detailed Description

Generic block I/O device routines.

 * $Id: blockdev.c 2463 2009-02-13 14:52:05Z haraldkipp $
 * 

Definition in file blockdev.c.


Typedef Documentation

typedef struct _BLOCKVOLUME BLOCKVOLUME

Block volume information structure type.

Definition at line 59 of file blockdev.c.


Function Documentation

int NutBlockDeviceInit ( NUTDEVICE dev)

Initialize the block I/O device.

This dummy routine may be used by drivers, which do not need any specific initialization.

Parameters:
devSpecifies the device.
Returns:
Always 0.

Definition at line 131 of file blockdev.c.

References NUTASSERT.

NUTFILE* NutBlockDeviceOpen ( NUTDEVICE dev,
CONST char *  name,
int  mode,
int  acc 
)

Mount a volume.

Nut/OS doesn't provide specific routines for mounting. Instead routines for opening files are used.

Applications should not directly call this function, but use the high level stdio routines for opening a file.

Parameters:
devSpecifies the block I/O device.
namePartition number followed by a slash followed by a name of the file system device. Both items are optional. If no file system driver name is given, the first file system driver found in the list of registered devices will be used. If no partition number is specified or if partition zero is given, the first active primary partition will be used.
modeOpening mode. Currently ignored, but should be used for compatibility with future enhancements.
accFile attributes, ignored.
Returns:
Pointer to a newly created file pointer to the mounted partition or NUTFILE_EOF in case of any error.

Definition at line 163 of file blockdev.c.

References _NUTBLOCKIO::blkio_blk_cnt, _NUTBLOCKIO::blkio_blk_siz, _NUTBLOCKIO::blkio_vol_bot, _NUTBLOCKIO::blkio_vol_top, _NUTDEVICE::dev_dcb, _NUTDEVICE::dev_ioctl, ENODEV, errno, free(), FS_VOL_MOUNT, _FSCP_VOL_MOUNT::fscp_bmnt, _FSCP_VOL_MOUNT::fscp_part_type, IFTYP_FS, malloc(), _NUTFILE::nf_dev, _NUTFILE::nf_fcb, _NUTFILE::nf_next, NUTASSERT, NutDeviceLookup(), NUTFILE_EOF, _BLOCKVOLUME::vol_blk_buf, _BLOCKVOLUME::vol_blk_cnt, _BLOCKVOLUME::vol_blk_len, _BLOCKVOLUME::vol_blk_num, _BLOCKVOLUME::vol_blk_off, and _BLOCKVOLUME::vol_fsdev.

Here is the call graph for this function:

int NutBlockDeviceClose ( NUTFILE nfp)

Unmount a currently mounted volume.

Parameters:
nfpFile pointer to a previously mounted volume.
Returns:
0 on success, -1 otherwise.

Definition at line 241 of file blockdev.c.

References _NUTDEVICE::dev_ioctl, free(), FS_VOL_UNMOUNT, _NUTFILE::nf_fcb, NUTASSERT, and _BLOCKVOLUME::vol_fsdev.

Here is the call graph for this function:

int NutBlockDeviceIOCtl ( NUTDEVICE dev,
int  req,
void *  conf 
)

Perform block I/O device control functions.

This function is called by the ioctl() function of the C runtime library. Applications should not directly call this function.

Unkown requests are passed to the block I/O device.

Parameters:
devIdentifies the device that receives the device-control function.
reqRequested control function. May be set to one of the following constants:
confPoints to a buffer that contains any data required for the given control function or receives data from that function.
Returns:
0 on success, -1 otherwise.

Definition at line 280 of file blockdev.c.

References _NUTBLOCKIO::blkio_ioctl, _NUTDEVICE::dev_dcb, _NUTFILE::nf_fcb, NUTASSERT, NUTBLKDEV_INFO, NUTBLKDEV_SEEK, _BLKPAR_INFO::par_blkbp, _BLKPAR_SEEK::par_blknum, _BLKPAR_INFO::par_blksz, _BLKPAR_INFO::par_nblks, _BLKPAR_SEEK::par_nfp, _BLKPAR_INFO::par_nfp, _BLOCKVOLUME::vol_blk_buf, _BLOCKVOLUME::vol_blk_cnt, _BLOCKVOLUME::vol_blk_len, and _BLOCKVOLUME::vol_blk_num.

int NutBlockDeviceRead ( NUTFILE nfp,
void *  buffer,
int  num 
)

Read data blocks from a mounted volume.

The current position may have been set by a previous I/O control NUTBLKDEV_SEEK.

Applications should not call this function directly, but use the stdio interface.

Parameters:
nfpFile pointer to a previously mounted volume.
bufferPointer to the data buffer to fill.
numNumber of blocks to read.
Returns:
The number of blocks actually read. The current position is set to the next unread block. A return value of -1 indicates an error.

Definition at line 348 of file blockdev.c.

References _NUTBLOCKIO::blkio_read, _NUTDEVICE::dev_dcb, _NUTFILE::nf_dev, _NUTFILE::nf_fcb, NUTASSERT, _BLOCKVOLUME::vol_blk_cnt, _BLOCKVOLUME::vol_blk_len, _BLOCKVOLUME::vol_blk_num, and _BLOCKVOLUME::vol_blk_off.

int NutBlockDeviceWrite ( NUTFILE nfp,
CONST void *  buffer,
int  num 
)

Write data blocks to a mounted volume.

The current position may have been set by a previous I/O control NUTBLKDEV_SEEK.

Applications should not call this function directly, but use the stdio interface.

Parameters:
nfpFile pointer to a previously mounted volume.
bufferPointer to the data to be written.
numNumber of blocks to write.
Returns:
The number of blocks actually written. The current position is set to the next block. A return value of -1 indicates an error.

Definition at line 400 of file blockdev.c.

References _NUTBLOCKIO::blkio_write, CONST, _NUTDEVICE::dev_dcb, _NUTFILE::nf_dev, _NUTFILE::nf_fcb, NUTASSERT, _BLOCKVOLUME::vol_blk_cnt, _BLOCKVOLUME::vol_blk_len, _BLOCKVOLUME::vol_blk_num, and _BLOCKVOLUME::vol_blk_off.

int NutBlockDeviceWrite_P ( NUTFILE nfp,
PGM_P  buffer,
int  num 
)

Write data blocks from program space to a mounted volume.

Similar to NutBlockDeviceWrite() except that the data is located in program memory.

Applications should not call this function directly, but use the stdio interface.

Parameters:
nfpFile pointer to a previously mounted volume.
bufferPointer to the data bytes in program space to be written.
numNumber of blocks to write.
Returns:
The number of blocks actually written. The current position is set to the next block. A return value of -1 indicates an error.

Definition at line 452 of file blockdev.c.

References _NUTBLOCKIO::blkio_write, _NUTBLOCKIO::blkio_write_P, _NUTDEVICE::dev_dcb, _NUTFILE::nf_dev, _NUTFILE::nf_fcb, NUTASSERT, PGM_P, _BLOCKVOLUME::vol_blk_cnt, _BLOCKVOLUME::vol_blk_len, _BLOCKVOLUME::vol_blk_num, and _BLOCKVOLUME::vol_blk_off.

long NutBlockDeviceSize ( NUTFILE nfp)

Return the size of a mounted volume.

Parameters:
nfpFile pointer to a previously mounted volume.
Returns:
Total number of bytes.

Definition at line 495 of file blockdev.c.

References _NUTFILE::nf_fcb, NUTASSERT, _BLOCKVOLUME::vol_blk_cnt, and _BLOCKVOLUME::vol_blk_len.