blockdev.c File Reference

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

Go to the source code of this file.

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,v 1.2 2009/02/13 14:52:05 haraldkipp Exp $
 * 

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:
dev Specifies 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:
dev Specifies the block I/O device.
name Partition 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.
mode Opening mode. Currently ignored, but should be used for compatibility with future enhancements.
acc File 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(), and NUTFILE_EOF.

int NutBlockDeviceClose ( NUTFILE nfp  ) 

Unmount a currently mounted volume.

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

Definition at line 241 of file blockdev.c.

References free, FS_VOL_UNMOUNT, _NUTFILE::nf_fcb, and NUTASSERT.

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:
dev Identifies the device that receives the device-control function.
req Requested control function. May be set to one of the following constants:
conf Points 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_INFO::par_nfp, and BLKPAR_SEEK::par_nfp.

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:
nfp File pointer to a previously mounted volume.
buffer Pointer to the data buffer to fill.
num Number 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, and NUTASSERT.

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:
nfp File pointer to a previously mounted volume.
buffer Pointer to the data to be written.
num Number 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, and NUTASSERT.

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:
nfp File pointer to a previously mounted volume.
buffer Pointer to the data bytes in program space to be written.
num Number 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, and PGM_P.

long NutBlockDeviceSize ( NUTFILE nfp  ) 

Return the size of a mounted volume.

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

Definition at line 495 of file blockdev.c.

References _NUTFILE::nf_fcb, and NUTASSERT.


© 2000-2007 by egnite Software GmbH - visit http://www.ethernut.de/