📄 cbiolib.c
字号:
return ERROR; } return (dev->pFuncs->cbioDevIoctl(dev, command, arg)); }/********************************************************************************* cbioModeGet - return the mode setting for CBIO device** 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* This routine is not protected by a semaphore.** This routine confirms if the current layer is a CBIO to BLKDEV wrapper * or a CBIO to CBIO layer. Depending on the current layer it either * returns the mode from BLK_DEV or calls cbioModeGet() recursively.** RETURNS O_RDONLY, O_WRONLY, or O_RDWR or ERROR */int cbioModeGet ( CBIO_DEV_ID dev /* CBIO handle */ ) { BLK_DEV *pBd; if( OK != cbioDevVerify (dev)) { return ERROR; } /* * SPR#67729: isDriver is TRUE for a CBIO to BLKDEV layer and ramDiskCbio. * In case of ramDiskCbio the blkSubDev is set to NULL since it is a CBIO * layer. There should be some reference to the sub devices, either * blkSubDev or cbioSubDev. */ if((dev->blkSubDev != NULL) || (dev->cbioSubDev != NULL)) { if( dev->isDriver == TRUE) /* Boolean identifying the current layer */ { if(dev->blkSubDev == NULL) { return(CBIO_MODE (dev)); /* For ramDiskCbio */ } else { pBd = dev->blkSubDev; return (pBd->bd_mode); } } else return ( cbioModeGet(dev->cbioSubDev)); /* For CBIO to CBIO */ } return (ERROR); }/********************************************************************************* cbioModeSet - set mode for CBIO device* * Valid modes are O_RDONLY, O_WRONLY, or O_RDWR.** 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* This routine is not protected by a semaphore.* * This routine confirms if the current layer is a CBIO to BLKDEV wrapper * or a CBIO to CBIO layer. Depending on the current layer it either * sets the mode of the BLK_DEV or calls cbioModeSet() recursively.** RETURNS OK or ERROR if mode is not set.**/STATUS cbioModeSet ( CBIO_DEV_ID dev, /* CBIO handle */ int mode /* O_RDONLY, O_WRONLY, or O_RDWR */ ) { BLK_DEV *pBd; if( OK != cbioDevVerify (dev)) { return ERROR; } /* * SPR#67729: isDriver is TRUE for a CBIO to BLKDEV layer and ramDiskCbio. * In case of ramDiskCbio the blkSubDev is set to NULL since it is a CBIO * layer. There should be some reference to the sub devices, either * blkSubDev or cbioSubDev. */ if((dev->blkSubDev != NULL) || (dev->cbioSubDev != NULL)) { if(dev->isDriver == TRUE) /* Boolean identifying the current layer */ { if(dev->blkSubDev == NULL) { CBIO_MODE(dev) = mode; /* For ramDiskCbio */ return (OK); } else { pBd = dev->blkSubDev; pBd->bd_mode = mode; CBIO_MODE (dev) = mode; return (OK); } } else return (cbioModeSet (dev->cbioSubDev, mode)); /* For CBIO to CBIO */ } return (ERROR); }/********************************************************************************* cbioRdyChgdGet - determine ready status of CBIO device** For example * .CS* switch (cbioRdyChgdGet (cbioDeviceId)) * {* case TRUE:* printf ("Disk changed.\n");* break;* case FALSE:* printf ("Disk has not changed.\n");* break;* case ERROR:* printf ("Not a valid CBIO device.\n");* break;* default:* break;* }* .CE** 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* This routine is not protected by a semaphore.** This routine will check down to the driver layer to see if any lower* layer has its ready changed bit set to TRUE. If so, this routine returns* TRUE. If no lower layer has its ready changed bit set to TRUE, this layer* returns FALSE.** RETURNS TRUE if device ready status has changed, else FALSE if * the ready status has not changed, else ERROR if the CBIO_DEV_ID is invalid.**/int cbioRdyChgdGet ( CBIO_DEV_ID dev /* CBIO handle */ ) { if( OK != cbioDevVerify (dev)) { return (ERROR); } /* check the current layers (dev) ready changed setting */ if (TRUE == CBIO_READYCHANGED(dev)) { /* this CBIO device's ready changed bit is set, return TRUE */ return (TRUE); } /* * isDriver is TRUE for a CBIO to BLKDEV layer and ramDiskCbio. * In case of ramDiskCbio the blkSubDev is set to NULL since it is a CBIO * layer. There should be some reference to the sub devices, either * blkSubDev or cbioSubDev. */ if((dev->blkSubDev != NULL) || (dev->cbioSubDev != NULL)) { if(TRUE == dev->isDriver) /* Boolean identifying the current layer */ { if(NULL == dev->blkSubDev) { /* * This is a CBIO driver (no subordinate CBIO present). * Above, we have already checked for the 'dev' ready * changed bit being TRUE, so we may return FALSE. */ return (FALSE); /* For ramDiskCbio */ } else { /* * This is a CBIO to BLK_DEV layer, so there is a BLK_DEV * device below this CBIO device. Return TRUE or FALSE * depending upon the BLK_DEV's ready changed bit setting. */ return (((BLK_DEV *)(dev->blkSubDev))->bd_readyChanged); } } else { /* * This is a CBIO to CBIO layer, and it doesn't have * its ready changed bit set, however a layer below us * may have its bit set, so we recurse down a layer. */ return (cbioRdyChgdGet(dev->cbioSubDev)); } } /* should never get here */#ifdef DEBUG logMsg("cbioRdyChgdGet: bad device 0x%08lx\n", (long unsigned int)dev,0,0,0,0,0);#endif return (ERROR); }/********************************************************************************* cbioRdyChgdSet - force a change in ready status of CBIO device** Pass TRUE in status to force READY status change.** 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* If status is not passed as TRUE or FALSE, ERROR is returned.* This routine is not protected by a semaphore.** This routine sets readyChanged bit of passed CBIO_DEV.** RETURNS OK or ERROR if the device is invalid or status is not TRUE or FALSE.**/STATUS cbioRdyChgdSet ( CBIO_DEV_ID dev, /* CBIO handle */ BOOL status /* TRUE/FALSE */ ) { if((OK != cbioDevVerify (dev)) || (TRUE != status && FALSE != status)) { return ERROR; } CBIO_READYCHANGED(dev) = status; /* For ramDiskCbio */ return (OK); }/********************************************************************************* cbioLock - obtain CBIO device semaphore.** 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 or ERROR if the CBIO handle is invalid or semTake fails.*/STATUS cbioLock ( CBIO_DEV_ID dev, /* CBIO handle */ int timeout /* timeout in ticks */ ) { if( OK != cbioDevVerify (dev)) { return ERROR; } return (semTake(dev->cbioMutex, timeout)); } /********************************************************************************* cbioUnlock - release CBIO device semaphore.** 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 or ERROR if the CBIO handle is invalid or the semGive fails.*/STATUS cbioUnlock ( CBIO_DEV_ID dev /* CBIO handle */ ) { if( OK != cbioDevVerify (dev)) { return ERROR; } return (semGive(dev->cbioMutex)); }/********************************************************************************* cbioParamsGet - fill in CBIO_PARAMS structure with CBIO device parameters** 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 or ERROR if the CBIO handle is invalid.*/STATUS cbioParamsGet ( CBIO_DEV_ID dev, /* CBIO handle */ CBIO_PARAMS * pCbioParams /* pointer to CBIO_PARAMS */ ) { if( OK != cbioDevVerify (dev)) { return ERROR; } *pCbioParams = dev->cbioParams; return (OK); }/********************************************************************************* cbioRdyChk - print ready changed setting of CBIO layer and its subordinates** NOMANUAL*/int cbioRdyChk ( CBIO_DEV_ID dev /* CBIO handle */ ) { if( OK != cbioDevVerify (dev)) { printf ("\tCBIO_DEV_ID 0x%08lx is invalid per cbioDevVerify.\n", (unsigned long) dev); return (ERROR); } /* check the current layers (dev) readyChanged bit setting */ printf ("\tCBIO_DEV_ID 0x%08lx ready changed is %d.\n", (unsigned long) dev, CBIO_READYCHANGED (dev)); /* * isDriver is TRUE for a CBIO to BLKDEV layer and ramDiskCbio. * In case of ramDiskCbio the blkSubDev is set to NULL since it is a CBIO * layer. There should be some reference to the sub devices, either * blkSubDev or cbioSubDev. */ if((dev->blkSubDev != NULL) || (dev->cbioSubDev != NULL)) { if(TRUE == dev->isDriver) /* Boolean identifying the current layer */ { if(NULL == dev->blkSubDev) { /* * This is a CBIO driver (no subordinate CBIO present). * Above, we have already displayed the 'dev' ready * changed bit, so we may return. */ return (OK); /* For ramDiskCbio */ } else { /* * This is a CBIO to BLK_DEV layer, so there is a BLK_DEV * device below this CBIO device. Return TRUE or FALSE, * depending upon the BLK_DEV's ready changed bit setting. */ printf ("\tBLK_DEV ptr 0x%08lx ready changed is %d.\n", (unsigned long) dev->blkSubDev, dev->blkSubDev->bd_readyChanged ); return (OK); } } else { /* * This is a CBIO to CBIO layer, and it doesn't have * its ready changed bit set, however a layer below us * may have its bit set, so we recurse down a layer. */ return (cbioRdyChk (dev->cbioSubDev)); } } /* should never get here */#ifdef DEBUG logMsg("cbioRdyChk: bad device 0x%08lx\n", (long unsigned int)dev,0,0,0,0,0);#endif return (ERROR); }/********************************************************************************* cbioShow - print information about a CBIO device** This function will display on standard output all information which* is generic for all CBIO devices.* See the CBIO modules particular device show routines for displaying* implementation-specific information.** It takes two arguments:** A CBIO_DEV_ID which is the CBIO handle to display or NULL for * the most recent device.** RETURNS OK or ERROR if no valid CBIO_DEV is found.** SEE ALSO: dcacheShow(), dpartShow()**/STATUS cbioShow ( CBIO_DEV_ID dev /* CBIO handle */ ) { unsigned long size, factor = 1 ; char * units ; if( dev == NULL ) dev = cbioRecentDev; if( dev == NULL ) { errno = S_cbioLib_INVALID_CBIO_DEV_ID; return ERROR; } if( OK != cbioDevVerify (dev)) { return ERROR; } if( dev->cbioParams.bytesPerBlk == 0 ) { errno = EINVAL; return ERROR; } printf("Cached Block I/O Device, handle=%#lx\n", (u_long)dev); printf("\tDescription: %s\n", dev->cbioDesc); /* calculate disk size, while avoiding 64-bit arithmetic */ if( dev->cbioParams.bytesPerBlk < 1024 ) { factor = 1024 / dev->cbioParams.bytesPerBlk ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -