📄 cbiolib.c
字号:
addr_t buffer, enum cbio_rw rw, cookie_t *cookie );.CE.IPdev - the CBIO handle of the device being accessed (from creation routine).IPstart_block - the starting block of the transfer operation.IPnum_blocks - the total number of blocks to transfer.IPbuffer - address of the memory buffer used for the transfer.IPrw - indicates the direction of transfer up or down (READ/WRITE).IP*cookie - pointer to cookie used by upper layer such as dosFsLib(),it should be preserved..LPCBIO modules have a byte transfer routine. This routine transfers between a user buffer and the lower layer (hardware, subordinate CBIO,or BLK_DEV). It is optimized for byte transfers. This routine returnsOK or ERROR and may otherwise set errno.This routine is declared:.CSLOCAL STATUS xxCbioBytesRW /@ Read/Write bytes @/ ( CBIO_DEV_ID dev, block_t start_block, off_t offset, addr_t buffer, size_t nBytes, enum cbio_rw rw, cookie_t *cookie );.CE.IPdev - the CBIO handle of the device being accessed (from creation routine).IPstart_block - the starting block of the transfer operation.IPoffset - offset in bytes from the beginning of the starting block.IPbuffer - address of the memory buffer used for the transfer.IPnBytes - number of bytes to transfer.IPrw - indicates the direction of transfer up or down (READ/WRITE).IP*cookie - pointer to cookie used by upper layer such as dosFsLib(),it should be preserved..LPCBIO modules have a block to block copy routine. This makescopies of one or more blocks on the lower layer (hardware, subordinate CBIO, or BLK_DEV). It is optimized for blockcopies on the subordinate layer. This routine returnsOK or ERROR and may otherwise set errno.This routine is declared:.CSLOCAL STATUS xxCbioBlkCopy /@ Copy sectors @/ ( CBIO_DEV_ID dev, block_t src_block, block_t dst_block, block_t num_blocks );.CE.IPdev - the CBIO handle of the device being accessed (from creation routine).IPsrc_block - source start block of the copy.IPdst_block - destination start block of the copy.IPnum_block - number of blocks to copy.LPCBIO modules have an ioctl() routine. This performs the requestedioctl() operation.CBIO modules can expect the following ioctl() codes from cbioLib.h:.IPCBIO_RESET - reset the CBIO device. When the third argument to the CBIO_RESET ioctl is NULL, the code verifies that the disk is inserted and is ready, after getting it to a known state. When the 3rd argument is a non-zero, it is assumed to be a BLK_DEV pointer and CBIO_RESET will install a new subordinate block device. This work is performed at the BLK_DEV to CBIO layer, and all layers shall account for it. A CBIO_RESET iindicates a possible change in device geometry, and the CBIO_PARAMS members will be reinitialized after a CBIO_RESET..IPCBIO_STATUS_CHK - check device status of CBIO device and lower layer.IPCBIO_DEVICE_LOCK - Prevent disk removal .IPCBIO_DEVICE_UNLOCK - Allow disk removal.IPCBIO_DEVICE_EJECT - Unmount and eject device.IPCBIO_CACHE_FLUSH - Flush any dirty cached data.IPCBIO_CACHE_INVAL - Flush & Invalidate all cached data.IPCBIO_CACHE_NEWBLK - Allocate scratch block.LPThe CBIO module may also implement other codes. CBIO modules pass all ioctl() requests to the lower layer also passing the argument before performing the requested I/O operation. This rule ensures changes in device geometry (if any occur) etc. are reflected in the upper layer. This routine returns OK or ERROR and may otherwise set errno.This routine is declared:.CSLOCAL STATUS xxCbioIoctl /@ Misc control operations @/ ( CBIO_DEV_ID dev, int command, addr_t arg );.CE.IPdev - the CBIO handle of the device being accessed (from creation routine).IPcommand - ioctl() command being issued.IParg - specific to the particular ioctl() function requested or un-used..LPFor more information about I/O, refer to the .I "VxWorks Programmers Guide: I/O System"INCLUDE FILEScbioLib.hcbioLibP.hINTERNALNeed to add WV instrumentation.Need to beef up docsNeed to add cbioDevDelete routine.*//* includes */#include "vxWorks.h"#include "stdlib.h"#include "stdio.h"#include "semLib.h"#include "ioLib.h"#include "classLib.h"#include "objLib.h"#include "errno.h"#include "string.h"#include "tickLib.h"#include "sysLib.h"#include "taskLib.h"#include "logLib.h"#include "private/objLibP.h"#include "private/classLibP.h"#include "private/semLibP.h"#include "blkIo.h" /* for blkIo wrapper backward compatibility */#include "private/cbioLibP.h"/* defines */#ifdef DEBUG#undef NDEBUGBOOL cbioDebug = FALSE ;#else#define NDEBUG#endif /* DEBUG */#include "assert.h"#define INFO_MSG logMsg/* implementation defined fields for Wrapper use */#define cbio_blkShift cbio_Priv0#define cbio_dirtyMask cbio_Priv1#define cbio_blkNo cbio_Priv2/* Globals & Statics */LOCAL BOOL cbioInstalled ;LOCAL CBIO_DEV_ID cbioRecentDev = NULL ;OBJ_CLASS cbioClass ;CLASS_ID cbioClassId = &cbioClass ;/* this global variable will allow to change the pointer range limit */int cbioBlkDevPtrLimit = 0x080000; /* 512KB */int cbioMutexSemOptions = (SEM_Q_PRIORITY | SEM_INVERSION_SAFE | SEM_DELETE_SAFE);/* forward declarations */STATUS cbioShow (CBIO_DEV_ID dev);LOCAL CBIO_DEV_ID cbioDevCreate (caddr_t ramAddr, size_t ramSize);LOCAL STATUS cbioWrapOk ();LOCAL STATUS blkWrapBytesRW( CBIO_DEV_ID dev, block_t start_block, off_t offset, addr_t buffer, size_t nBytes, enum cbio_rw rw, cookie_t *cookie);LOCAL STATUS blkWrapBlkRW( CBIO_DEV_ID dev, block_t start_block, block_t num_blocks, addr_t buffer, enum cbio_rw rw, cookie_t *cookie);LOCAL STATUS blkWrapBlkRWbuf( CBIO_DEV_ID dev, block_t start_block, block_t num_blocks, addr_t buffer, enum cbio_rw rw, cookie_t *cookie);LOCAL STATUS blkWrapBlkCopy( CBIO_DEV_ID dev, block_t src_block, block_t dst_block, block_t num_blocks);LOCAL STATUS blkWrapIoctl( CBIO_DEV_ID dev, int command, addr_t arg);LOCAL int shiftCalc (u_long mask);/* CBIO_FUNCS, one per CBIO module */LOCAL CBIO_FUNCS cbioFuncs = {(FUNCPTR) blkWrapBlkRW, (FUNCPTR) blkWrapBytesRW, (FUNCPTR) blkWrapBlkCopy, (FUNCPTR) blkWrapIoctl};#ifdef __unused__LOCAL void blkWrapDiskSizeAdjust ( CBIO_DEV_ID dev);#endif /*__unused__*//********************************************************************************* cbioLibInit - Initialize CBIO Class Library** This function initializes the CBIO class library, and will be called* when the first CBIO device is created, hence it does not need to* be called during system initialization. It can be called mulitple* times, but will do nothing after the first call.** RETURNS: OK or ERROR if no sufficient memory or invalid object.**/STATUS cbioLibInit( void ) { STATUS stat ; if( cbioInstalled ) return OK; /* Allocate object space for CBIO_DEV and CBIO_FUNCS */ stat = classInit( cbioClassId, sizeof(CBIO_DEV), OFFSET( CBIO_DEV,objCore), (FUNCPTR) cbioDevCreate, /* Create Routine */ (FUNCPTR) NULL, /* Init routine */ (FUNCPTR) NULL /* Destroy routine */ ) ; classShowConnect( cbioClassId, (FUNCPTR) cbioShow ); if( stat == OK ) cbioInstalled = TRUE ; return( stat ); }/********************************************************************************* cbioBlkRW - transfer blocks to or from memory* * This routine verifies the CBIO device is valid and if so calls the devices * block transfer routine. The CBIO device performs block transfers * between the device and memory. * .CE* * .IP* dev - the CBIO handle of the device being accessed (from creation routine)* .IP* start_block - the starting block of the transfer operation* .IP* num_blocks - the total number of blocks to transfer* .IP* buffer - address of the memory buffer used for the transfer* .IP* rw - indicates the direction of transfer up or down (READ/WRITE)* .IP* *pCookie - pointer to cookie used by upper layer such as dosFsLib(),* it should be preserved.* .LP** If the CBIO_DEV_ID passed to this routine is not a valid CBIO handle,* ERROR will be returned with errno set to S_objLib_OBJ_ID_ERROR** RETURNS OK if sucessful or ERROR if the handle is invalid, or if the* CBIO device routine returns ERROR.**/STATUS cbioBlkRW /* Read/Write blocks */ ( CBIO_DEV_ID dev, block_t start_block, block_t num_blocks, addr_t buffer, enum cbio_rw rw, cookie_t *cookie ) { if( OBJ_VERIFY( dev, cbioClassId ) != OK) { errno = S_objLib_OBJ_ID_ERROR; return ERROR; } return (dev->pFuncs->cbio_blkRW (dev,start_block, num_blocks,buffer, rw, cookie)); }/********************************************************************************* cbioBytesRW - transfer bytes to or from memory* * This routine verifies the CBIO device is valid and if so calls the devices* byte tranfer routine which transfers between a user buffer and the lower * layer (hardware, subordinate CBIO, or BLK_DEV). It is optimized for byte * transfers. * * .IP* dev - the CBIO handle of the device being accessed (from creation routine)* .IP* start_block - the starting block of the transfer operation* .IP* offset - offset in bytes from the beginning of the starting block* .IP* buffer - address of the memory buffer used for the transfer* .IP* nBytes - number of bytes to transfer* .IP* rw - indicates the direction of transfer up or down (READ/WRITE)* .IP* *cookie - pointer to cookie used by upper layer such as dosFsLib(),* it should be preserved.* .LP* * If the CBIO_DEV_ID passed to this routine is not a valid CBIO handle,* ERROR will be returned with errno set to S_objLib_OBJ_ID_ERROR** RETURNS OK if sucessful or ERROR if the handle is invalid, or if the* CBIO device routine returns ERROR.**/STATUS cbioBytesRW /* Read/Write bytes */ ( CBIO_DEV_ID dev, block_t start_block, off_t offset, addr_t buffer, size_t nBytes, enum cbio_rw rw, cookie_t *cookie ) { if( OBJ_VERIFY( dev, cbioClassId ) != OK) { errno = S_objLib_OBJ_ID_ERROR; return ERROR; } return (dev->pFuncs->cbio_BytesRW(dev, start_block, offset, buffer, nBytes, rw, cookie)); }/********************************************************************************* cbioBlkCopy - block to block (sector to sector) tranfer routine** This routine verifies the CBIO device is valid and if so calls the devices* block to block tranfer routine which makes copies of one or more blocks on * the lower layer (hardware, subordinate CBIO, or BLK_DEV). It is optimized * for block to block copies on the subordinate layer. * * .IP* dev - the CBIO handle of the device being accessed (from creation routine)* .IP* src_block - source start block of the copy* .IP* dst_block - destination start block of the copy* .IP* num_block - number of blocks to copy* .LP* * If the CBIO_DEV_ID passed to this routine is not a valid CBIO handle,* ERROR will be returned with errno set to S_objLib_OBJ_ID_ERROR** RETURNS OK if sucessful or ERROR if the handle is invalid, or if the* CBIO device routine returns ERROR.**/STATUS cbioBlkCopy /* Copy sectors */ ( CBIO_DEV_ID dev, block_t src_block, block_t dst_block, block_t num_blocks ) { return (dev->pFuncs->cbio_blkCopy(dev, src_block, dst_block, num_blocks)); }/********************************************************************************* cbioIoctl - perform ioctl operation on device** This routine verifies the CBIO device is valid and if so calls the devices* I/O control operation routine.* * CBIO modules expect the following ioctl() codes:* * .IP* CBIO_RESET - reset the CBIO device. When the third argument to the ioctl* call accompaning CBIO_RESET is NULL, the code verifies that the disk is * inserted and is ready, after getting it to a known state. When the 3rd * argument is a non-zero, it is assumed to be a BLK_DEV pointer and * CBIO_RESET will install a new subordinate block device. This work* is performed at the BLK_DEV to CBIO layer, and all layers shall account* for it. A CBIO_RESET indicates a possible change in device geometry, * and the CBIO_PARAMS members will be reinitialized after a CBIO_RESET.* .IP* CBIO_STATUS_CHK - check device status of CBIO device and lower layer* .IP* CBIO_DEVICE_LOCK - Prevent disk removal * .IP* CBIO_DEVICE_UNLOCK - Allow disk removal* .IP* CBIO_DEVICE_EJECT - Unmount and eject device* .IP* CBIO_CACHE_FLUSH - Flush any dirty cached data* .IP* CBIO_CACHE_INVAL - Flush & Invalidate all cached data* .IP* CBIO_CACHE_NEWBLK - Allocate scratch block* .LP** Arguments are:* .IP* dev - the CBIO handle of the device being accessed (from creation routine)* .IP * command - ioctl() command being issued* .IP * arg - specific to the particular ioctl() function requested or un-used.* .LP** If the CBIO_DEV_ID passed to this routine is not a valid CBIO handle,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -