📄 dpartcbio.c
字号:
if(TRUE == cbioRdyChgdGet (dev)) { errno = S_ioLib_DISK_NOT_PRESENT ; return ERROR; } if( (srcBlock) > pDev->cbioParams.nBlocks || (dstBlock) > pDev->cbioParams.nBlocks ) return ERROR; if( (srcBlock+numBlocks) > pDev->cbioParams.nBlocks || (dstBlock+numBlocks) > pDev->cbioParams.nBlocks ) return ERROR; srcBlock += pDev->cbioParams.blockOffset; dstBlock += pDev->cbioParams.blockOffset; if( semTake( pDev->cbioMutex, WAIT_FOREVER) == ERROR ) return ERROR; retStat = pDev->pDc->subDev->pFuncs->cbioDevBlkCopy( pDev->pDc->subDev, srcBlock, dstBlock, numBlocks ); if( retStat == ERROR ) if( TRUE == cbioRdyChgdGet (dev->pDc->subDev)) CBIO_READYCHANGED (dev) = TRUE; semGive( pDev->cbioMutex ); return ( retStat); }/********************************************************************************* dpartIoctl - Misc control operations ** This performs the requested ioctl() operation.* * CBIO modules can expect the following ioctl() codes from cbioLib.h:* CBIO_RESET - reset the CBIO device and the lower layer* CBIO_STATUS_CHK - check device status of CBIO device and lower layer* CBIO_DEVICE_LOCK - Prevent disk removal * CBIO_DEVICE_UNLOCK - Allow disk removal* CBIO_DEVICE_EJECT - Unmount and eject device* CBIO_CACHE_FLUSH - Flush any dirty cached data* CBIO_CACHE_INVAL - Flush & Invalidate all cached data* CBIO_CACHE_NEWBLK - Allocate scratch block** * command - ioctl() command being issued* * arg - specific to the particular ioctl() function requested or un-used.** RETURNS OK or ERROR and may otherwise set errno.*/LOCAL STATUS dpartIoctl ( CBIO_DEV_ID dev, UINT32 command, addr_t arg ) { STATUS retStat = ERROR ; if(OK != cbioDevVerify (dev)) { INFO_MSG("dpartIoctl: invalid handle\n"); return ERROR; } if( semTake( dev->cbioMutex, WAIT_FOREVER) == ERROR ) return ERROR; switch ( command ) { case CBIO_RESET : /* * if this is the first partition to issue RESET * we need to RESET the lower level device too, * otherwise, RESET only this partition. */ if((TRUE == cbioRdyChgdGet (dev->pDc->subDev)) || (TRUE == cbioRdyChgdGet (dev->pDc->masterDev))) { DEBUG_MSG("dpartCbio: resetting subordinate\n"); retStat = dev->pDc->subDev->pFuncs->cbioDevIoctl( dev->pDc->subDev, command, arg ); /* and also fill the partitions geometry now */ if( retStat == OK ) { retStat = dpartPartTableFill( dev->pDc ); } if( retStat == OK ) { CBIO_READYCHANGED (dev->pDc->masterDev) = FALSE; } } else { /* * if masterDev does not have readyChanged * there is no need to reset subDev, its been * already reset */ retStat = OK; } /* non-existent partitions will remain "removed" */ if (retStat == OK && dev->cbioParams.nBlocks == 0) { errno = S_ioLib_DISK_NOT_PRESENT ; retStat = ERROR ; } if( retStat == OK ) CBIO_READYCHANGED(dev) = FALSE; break; /* NEWBLK is the only ioctl where block# is coded in arg */ case CBIO_CACHE_NEWBLK: arg += dev->cbioParams.blockOffset ; /*FALLTHROUGH*/ /* all other commands should be executed by the lower layer */ case CBIO_STATUS_CHK : case CBIO_DEVICE_LOCK : case CBIO_DEVICE_UNLOCK : case CBIO_DEVICE_EJECT : /* check if master has readyChanged */ if((TRUE == cbioRdyChgdGet (dev->pDc->subDev)) || (TRUE == cbioRdyChgdGet (dev->pDc->masterDev))) { CBIO_READYCHANGED (dev) = TRUE; } /*FALLTHROUGH*/ case CBIO_CACHE_FLUSH : case CBIO_CACHE_INVAL : default: if(TRUE == cbioRdyChgdGet (dev)) { errno = S_ioLib_DISK_NOT_PRESENT ; retStat = ERROR ; } else { if( command == (int)CBIO_DEVICE_LOCK ) semTake( dev->pDc->subDev->cbioMutex, WAIT_FOREVER) ; retStat = dev->pDc->subDev->pFuncs->cbioDevIoctl( dev->pDc->subDev, command, arg ); if( command == (int)CBIO_DEVICE_UNLOCK ) semGive( dev->pDc->subDev->cbioMutex) ; } } /* end of switch */ if( retStat == ERROR ) if( TRUE == cbioRdyChgdGet (dev->pDc->subDev)) CBIO_READYCHANGED (dev) = TRUE; semGive( dev->cbioMutex ); return( retStat ); }/********************************************************************************* dpartDevCreate - Initialize a partitioned disk** To handle a partitioned disk, this function should be called,* with <subDev> as the handle returned from dcacheDevCreate(),* It is recommended that for efficient operation a single disk cache* be allocated for the entire disk and shared by its partitions.** <nPart> is the maximum number of partitions which are expected* for the particular disk drive. Up to 24 (C-Z) partitions per disk * are supported.** PARTITION DECODE FUNCTION* An external partition table decode function is provided via the* <pPartDecodeFunc> argument, which implements a particular style and* format of partition tables, and fill in the results into a table* defined as Pn array of PART_TABLE_ENTRY types. See dpartCbio.h* for definition of PART_TABLE_ENTRY.* The prototype for this function is as follows:* * .CS* STATUS parDecodeFunc* (* CBIO_DEV_ID dev, /@ device from which to read blocks @/* PART_TABLE_ENTRY *pPartTab, /@ table where to fill results @/* int nPart /@ # of entries in <pPartTable> @/* )* .CE** RETURNS: CBIO_DEV_ID or NULL if error creating CBIO device.* * SEE ALSO: dosFsDevCreate().* INTERNAL* during create, readyChanged bit is TRUE, so no accesses are allowed* until after a CBIO_RESET, at which time the actual partition table* will be brought in and applied.*/CBIO_DEV_ID dpartDevCreate ( CBIO_DEV_ID subDev, /* lower level CBIO device */ int nPart, /* # of partitions */ FUNCPTR pPartDecodeFunc /* function to decode partition table */ ) { CBIO_DEV_ID cbio = subDev ; CBIO_DEV_ID pDev = NULL ; DPART_CTRL * pDc ; int p ; if( nPart > PART_MAX_ENTRIES || pPartDecodeFunc == NULL ) { printErr ("%d is too many partitions, max limit %d\n", nPart, PART_MAX_ENTRIES); errno = EINVAL; return NULL; } cbioLibInit(); /* just in case */ /* if this is a BLK_DEV, create a CBIO_DEV */ if (OK != cbioDevVerify( subDev )) { /* attempt to handle BLK_DEV subDev */ cbio = cbioWrapBlkDev ((BLK_DEV *) subDev); if( NULL != cbio ) { /* SPR#71633, clear the errno set in cbioDevVerify() */ errno = 0; } } else { cbio = subDev; } if( NULL == cbio ) { DEBUG_MSG("dpartDevCreate: invalid handle\n"); return NULL; } /* allocate our main DPART_CTRL structure */ pDc = KHEAP_ALLOC((sizeof(DPART_CTRL))); if( pDc == NULL ) { return( NULL ); } bzero( (char *) pDc, sizeof( DPART_CTRL) ); /* create the primary CBIO handle */ pDev = cbioDevCreate ( NULL, 0 ); if( pDev == NULL ) { return( NULL ); } /* the primary CBIO handle is not for any actual I/O, just for show */ pDev->cbioDesc = "dpartCbio Partition Manager" ; CBIO_READYCHANGED (pDev) = CBIO_READYCHANGED (cbio); pDev->cbioParams.cbioRemovable = cbio->cbioParams.cbioRemovable ; pDev->cbioParams.nBlocks = cbio->cbioParams.nBlocks ; pDev->cbioParams.bytesPerBlk = cbio->cbioParams.bytesPerBlk ; pDev->cbioParams.blocksPerTrack = cbio->cbioParams.blocksPerTrack ; pDev->cbioParams.nHeads = cbio->cbioParams.nHeads ; pDev->cbioMode = cbio->cbioMode ; pDev->cbioParams.blockOffset = 0 ; pDev->cbioParams.lastErrBlk = NONE ; pDev->cbioParams.lastErrno = 0 ; pDev->cbioPartIndx = NONE ; /* master device */ /* SPR#67729: Fill in the members subDev and isDriver appropriately */ pDev->blkSubDev = NULL; /* Since lower layer is not BLKDEV */ pDev->cbioSubDev = cbio; /* Storing the reference to the sub Device */ pDev->isDriver = FALSE; /* == FALSE since this is a CBIO TO CBIO layer */ pDev->pDc = pDc ; /* DPART_CTRL */ pDev->pFuncs = &cbioFuncs; /* setup main fields */ pDc->subDev = cbio ; pDc->pPartDecodeFunc = pPartDecodeFunc ; pDc->nPart = nPart ; pDc->masterDev = pDev ; /* Now initialize the partition virtual devs */ for(p = 0; p < PART_MAX_ENTRIES; p++ ) { CBIO_DEV_ID tmpDev = & ( pDc->vDev[ p ] ); /* inherit most fields from the primary handle */ *tmpDev = *pDev ; tmpDev->cbioDesc = "dpartCbio Partition Slave Device"; tmpDev->cbioPartIndx = p; /* partition # */ CBIO_READYCHANGED (tmpDev) = TRUE; /* semaphore can be just copied, it has to be init'ed */ tmpDev->cbioMutex = semMCreate (dpartSemOptions); if (NULL == tmpDev->cbioMutex) { DEBUG_MSG("Error Creating the device semaphore\n"); pDev = NULL; break; }#ifdef _WRS_DOSFS2_VXWORKS_AE /* init the handle */ handleInit (&tmpDev->cbioHandle, handleTypeCbioHdl);#endif /* _WRS_DOSFS2_VXWORKS_AE */ /* these will be filled later from actual geometry */ tmpDev->cbioParams.nBlocks = 0 ; tmpDev->cbioParams.blockOffset = 0 ; } DEBUG_MSG("dpartDevCreate: handle dev %x subDev %x\n", pDev, cbio ); /* return device handle */ return( pDev ); }/********************************************************************************* dpartPartGet - retrieve handle for a partition** This function retrieves a CBIO handle into a particular partition* of a partitioned device. This handle is intended to be used with* dosFsDevCreate().** RETURNS: CBIO_DEV_ID or NULL if partition is out of range, or* <masterHandle> is invalid.** SEE ALSO: dosFsDevCreate()*/CBIO_DEV_ID dpartPartGet ( CBIO_DEV_ID masterHandle, /* CBIO handle of the master partition */ int partNum /* partition number from 0 to nPart */ ) { if(OK != cbioDevVerify( masterHandle)) { return NULL; } if( partNum >= masterHandle->pDc->nPart ) { errno = EINVAL; return NULL; } return ( & masterHandle->pDc->vDev[ partNum ] ); }/********************************************************************************* dpartShow - show current parameters of the RAM disk device** NOMANUAL*/STATUS dpartShow( CBIO_DEV_ID dev, int verb ) { DPART_CTRL * pDc ; int pn ; if( (OK != cbioDevVerify (dev))) { DEBUG_MSG("dpartShow: invalid handle\n"); return ERROR; } pDc = dev->pDc ; if( TRUE == cbioRdyChgdGet (dev)) dev->pFuncs->cbioDevIoctl( dev, CBIO_RESET, 0); if( dev->cbioPartIndx == (u_long)NONE ) printf(" Device %#lx is Master handle, Partition Table:\n", (u_long) dev); else printf(" Device %#lx is partition %ld, Partition Table:\n", (u_long) dev, dev->cbioPartIndx ); for( pn = 0; pn < pDc->nPart ; pn ++ ) { printf(" #%ld: from %ld to %ld (%ld blocks)\n", pDc->vDev[ pn ].cbioPartIndx, (block_t) pDc->vDev[ pn ].cbioParams.blockOffset, pDc->vDev[ pn ].cbioParams.nBlocks + pDc->vDev[ pn ].cbioParams.blockOffset, pDc->vDev[ pn ].cbioParams.nBlocks ); } printf(" master dev %#lx, subordinate dev %#lx, with total %ld blocks\n", (u_long) pDc->masterDev, (u_long) pDc->subDev, pDc->subDev->cbioParams.nBlocks ); return OK; }/* End of File */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -