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>
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. | |
NUTFILE * | NutBlockDeviceOpen (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. |
Generic block I/O device routines.
* $Id: blockdev.c 4473 2012-08-20 15:12:45Z haraldkipp $ *
typedef struct _BLOCKVOLUME BLOCKVOLUME |
Block volume information structure type.
int NutBlockDeviceInit | ( | NUTDEVICE * | dev | ) |
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.
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. |
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, NULL, NUTASSERT, NutDeviceLookup(), NutDeviceLookupType(), 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.
int NutBlockDeviceClose | ( | NUTFILE * | nfp | ) |
Unmount a currently mounted volume.
nfp | File pointer to a previously mounted volume. |
References _NUTDEVICE::dev_ioctl, free(), FS_VOL_UNMOUNT, _NUTFILE::nf_fcb, NULL, NUTASSERT, rc, and _BLOCKVOLUME::vol_fsdev.
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.
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. |
References _NUTBLOCKIO::blkio_ioctl, _NUTDEVICE::dev_dcb, _NUTFILE::nf_fcb, NULL, 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, rc, _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.
nfp | File pointer to a previously mounted volume. |
buffer | Pointer to the data buffer to fill. |
num | Number of blocks to read. |
References _NUTBLOCKIO::blkio_read, _NUTDEVICE::dev_dcb, _NUTFILE::nf_dev, _NUTFILE::nf_fcb, NULL, NUTASSERT, rc, _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.
nfp | File pointer to a previously mounted volume. |
buffer | Pointer to the data to be written. |
num | Number of blocks to write. |
References _NUTBLOCKIO::blkio_write, _NUTDEVICE::dev_dcb, _NUTFILE::nf_dev, _NUTFILE::nf_fcb, NULL, NUTASSERT, rc, _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.
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. |
References _NUTBLOCKIO::blkio_write, _NUTBLOCKIO::blkio_write_P, _NUTDEVICE::dev_dcb, _NUTFILE::nf_dev, _NUTFILE::nf_fcb, NULL, NUTASSERT, PGM_P, rc, _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.
nfp | File pointer to a previously mounted volume. |
References _NUTFILE::nf_fcb, NULL, NUTASSERT, _BLOCKVOLUME::vol_blk_cnt, and _BLOCKVOLUME::vol_blk_len.