Nut/OS  4.10.3
API Reference
blockdev.h File Reference

Block device driver definitions. More...

#include <sys/types.h>
#include <stdint.h>
#include <sys/device.h>
#include <sys/file.h>
Include dependency graph for blockdev.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  _BLKPAR_SEEK
 Block seek parameter structure. More...
struct  _BLKPAR_INFO
 Device information parameter structure. More...
struct  _NUTBLOCKIO
 Generic block I/O device interface structure. More...

Typedefs

typedef struct _BLKPAR_SEEK BLKPAR_SEEK
 Block seek parameter structure.
typedef struct _BLKPAR_INFO BLKPAR_INFO
 Device information parameter structure.
typedef struct _NUTBLOCKIO NUTBLOCKIO
 Generic block I/O device interface 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.
long NutBlockDeviceSize (NUTFILE *nfp)
 Return the size of a mounted volume.
int NutBlockDeviceWrite_P (NUTFILE *nfp, PGM_P buffer, int num)
 Write data blocks from program space to a mounted volume.

Control Codes

#define NUTBLKDEV_MEDIAAVAIL   0x1200
 Query for media change.
#define NUTBLKDEV_MEDIACHANGE   0x1201
 Query for media change.
#define NUTBLKDEV_INFO   0x1202
 Retrieve device information.
#define NUTBLKDEV_SEEK   0x1203
 Block seek request.

Detailed Description

Block device driver definitions.

 *
 * $Log$
 * Revision 1.4  2009/01/09 17:59:05  haraldkipp
 * Added target independent AT45D block device drivers and non-volatile
 * memory support based on the new bus controllers.
 *
 * Revision 1.3  2008/08/11 06:59:59  haraldkipp
 * BSD types replaced by stdint types (feature request #1282721).
 *
 * Revision 1.2  2006/04/07 12:57:48  haraldkipp
 * Added ioctl(NUTBLKDEV_MEDIAAVAIL).
 *
 * Revision 1.1  2006/01/05 16:32:05  haraldkipp
 * First check-in.
 *
 *
 * 

Definition in file blockdev.h.


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.

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.

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.