⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cbiolib.c

📁 VXWORKS源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
Some developers may wish to create their own modules using the CBIO API.  The guidelines herein should be followed regardless of CBIO module typebeing designed.  The source file ramDiskCbio.c may be used as an implementation example.CBIO modules have a CBIO device creation routine.   The routine creates a CBIO_DEV structure and initializes all its fields.  Un-used function members are initialized to NULL.  CBIO modules do not perform an iosDevAdd() call, and are akin to block device drivers in that respect.  The creation routine returns a CBIO handle of type CBIO_DEV_ID.CBIO modules have a block transfer routine. This routine transfers between a user buffer and the lower layer (hardware, subordinate CBIO, or BLK_DEV).  It is optimized for block transfers.  This routine returns OK or ERROR and may otherwise set errno.This routine is declared:.CSSTATUS	xxCbioBlkRW		/@ Read/Write blocks @/    (    CBIO_DEV_ID     dev,    block_t         startBlock,    block_t         numBlocks,    addr_t          buffer,    CBIO_RW         rw,    cookie_t *      pCookie    );.CE.IPdev - the CBIO handle of the device being accessed (from creation routine).IPstartBlock - the starting block of the transfer operation.IPnumBlocks - 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*pCookie - 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		startBlock,    off_t		offset,    addr_t		buffer,    size_t		nBytes,    CBIO_RW             rw,    cookie_t *          pCookie    );.CE.IPdev - the CBIO handle of the device being accessed (from creation routine).IPstartBlock - 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*pCookie - 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         srcBlock,    block_t         dstBlock,    block_t         numBlocks    );.CE.IPdev - the CBIO handle of the device being accessed (from creation routine).IPsrcBlock - source start block of the copy.IPdstBlock - 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,    UINT32              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..LPNeed to add WV instrumentation.Need to beef up docsNeed to add cbioDevDelete routine.*//* includes */#include "vxWorks.h"#include "private/dosFsVerP.h"#include "stdlib.h"#include "stdio.h"#include "semLib.h"#include "ioLib.h"#include "errno.h"#include "string.h"#include "tickLib.h"#include "sysLib.h"#include "taskLib.h"#include "logLib.h"#include "blkIo.h"#include "assert.h"#include "dosFsLib.h"#include "private/cbioLibP.h"/* defines */#undef DEBUG 		/* define to debug cbioLib */#ifdef	DEBUG#undef	NDEBUGBOOL			cbioDebug = FALSE ;#else#define	NDEBUG#endif	/* DEBUG *//* implementation defined fields for Wrapper use */#define	cbioBlkShift	cbioPriv0#define	cbioDirtyMask	cbioPriv1#define	cbioBlkNo	cbioPriv2/* Globals & Statics */LOCAL BOOL		cbioInstalled ;LOCAL CBIO_DEV_ID	cbioRecentDev = NULL ;#ifndef _WRS_DOSFS2_VXWORKS_AEOBJ_CLASS		cbioClass ;CLASS_ID		cbioClassId = &cbioClass ;#endif /* _WRS_DOSFS2_VXWORKS_AE */int 	cbioMutexSemOptions = 			(SEM_Q_PRIORITY | SEM_INVERSION_SAFE | SEM_DELETE_SAFE);/* forward declarations */STATUS cbioShow (CBIO_DEV_ID dev);int cbioRdyChk (CBIO_DEV_ID dev);LOCAL STATUS cbioWrapOk ();LOCAL STATUS blkWrapBytesRW( CBIO_DEV_ID dev, block_t startBlock,	off_t offset, addr_t buffer, size_t nBytes,	CBIO_RW rw, cookie_t *pCookie);LOCAL STATUS blkWrapBlkRW( CBIO_DEV_ID dev, block_t startBlock,	block_t numBlocks, addr_t buffer, CBIO_RW rw, cookie_t * pCookie);LOCAL STATUS blkWrapBlkRWbuf( CBIO_DEV_ID dev, block_t startBlock,	block_t numBlocks, addr_t buffer, CBIO_RW rw, cookie_t * pCookie);LOCAL STATUS blkWrapBlkCopy( CBIO_DEV_ID dev, block_t srcBlock,	block_t dstBlock, block_t numBlocks);LOCAL STATUS blkWrapIoctl( CBIO_DEV_ID dev, UINT32  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 Library** This function initializes the CBIO 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 **/STATUS cbioLibInit( void )    {    STATUS stat;    if( cbioInstalled )	return OK;#ifdef _WRS_DOSFS2_VXWORKS_AE    /* Setup handle show routine. */    stat = handleShowConnect( handleTypeCbioHdl, (FUNCPTR) cbioShow );#else /* else, using VxWorks 5.x */    /* 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 );#endif /* _WRS_DOSFS2_VXWORKS_AE */    if (ERROR == stat)	return (ERROR);    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.  ** If the CBIO_DEV_ID passed to this routine is not a valid CBIO handle,* ERROR will be returned with errno set to S_cbioLib_INVALID_CBIO_DEV_ID** RETURNS OK if sucessful or ERROR if the handle is invalid, or if the* CBIO device routine returns ERROR.**/STATUS cbioBlkRW		    (    CBIO_DEV_ID		dev, 		/* CBIO handle */    block_t		startBlock,	/* starting block of transfer */    block_t		numBlocks, 	/* number of blocks to transfer */    addr_t		buffer,		/* address of the memory buffer */    CBIO_RW		rw,		/* direction of transfer R/W */    cookie_t *	 	pCookie		/* pointer to cookie */    )    {    if( OK != cbioDevVerify (dev))	{	return ERROR;	}    return (dev->pFuncs->cbioDevBlkRW (dev,startBlock,                                     numBlocks,buffer,                                      rw, pCookie));    }/********************************************************************************* 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.  * * If the CBIO_DEV_ID passed to this routine is not a valid CBIO handle,* ERROR will be returned with errno set to S_cbioLib_INVALID_CBIO_DEV_ID** RETURNS OK if sucessful or ERROR if the handle is invalid, or if the* CBIO device routine returns ERROR.**/STATUS cbioBytesRW	    (    CBIO_DEV_ID 	dev,		/* CBIO handle */    block_t		startBlock,	/* starting block of the transfer */    off_t		offset,		/* offset into block in bytes */    addr_t		buffer,		/* address of data buffer */    size_t		nBytes,		/* number of bytes to transfer */    CBIO_RW		rw,		/* direction of transfer R/W */    cookie_t *		pCookie		/* pointer to cookie */    )    {    if( OK != cbioDevVerify (dev))	{	return ERROR;	}    return (dev->pFuncs->cbioDevBytesRW(dev, startBlock,				      offset, buffer,			  	      nBytes, rw, pCookie));    }/********************************************************************************* 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.  * * If the CBIO_DEV_ID passed to this routine is not a valid CBIO handle,* ERROR will be returned with errno set to S_cbioLib_INVALID_CBIO_DEV_ID** RETURNS OK if sucessful or ERROR if the handle is invalid, or if the* CBIO device routine returns ERROR.**/STATUS cbioBlkCopy    (    CBIO_DEV_ID 	dev,		/* CBIO handle */    block_t		srcBlock,	/* source start block */    block_t		dstBlock, 	/* destination start block */    block_t		numBlocks	/* number of blocks to copy */    )    {    if( OK != cbioDevVerify (dev))	{	return ERROR;	}    return (dev->pFuncs->cbioDevBlkCopy(dev, srcBlock, 				      dstBlock, numBlocks));    }/********************************************************************************* 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** If the CBIO_DEV_ID passed to this routine is not a valid CBIO handle,* ERROR will be returned with errno set to S_cbioLib_INVALID_CBIO_DEV_ID** RETURNS OK if sucessful or ERROR if the handle is invalid, or if the* CBIO device routine returns ERROR.*/STATUS cbioIoctl    (    CBIO_DEV_ID		dev,		/* CBIO handle */    int			command,	/* ioctl command to be issued */    addr_t		arg		/* arg - specific to ioctl */    )    {    if( OK != cbioDevVerify (dev))	{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -