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

📄 dpartcbio.c

📁 vxworks源码源码解读是学习vxworks的最佳途径
💻 C
📖 第 1 页 / 共 2 页
字号:
/* dpartCbio.c - generic disk partition manager *//* Copyright 1999 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------01j,15sep99,jkf  changes for new CBIO API.01i,24aug99,jkf  changed docs01h,31jul99,jkf  increased max partitions to 24 (c-z) in header,                  changed docs, defaulted the debug global to 0. SPR#28277.01g,31jul99,jkf  T2 merge, tidiness & spelling.01f,07dec98,lrn  minor fixes for partition table creation01e,25oct98,lrn  fixed re-reading subDev geometry on RESET01d,15sep98,lrn  some doc cleanups01c,10sep98,lrn  added cbioDevVerify for cache-less configs01b,02jul98,lrn  tested, doc review01a,15jun98,lrn  written, preliminary*//*DESCRIPTIONThis module implements a generic partition manager using the CBIOAPI (see cbioLib)  It supports creating a separate file system device for each of its partitions.This partition manager depends upon an external library to decode aparticular disk partition table format, and report the resultingpartition layout information back to this module.  This module isresponsible for maintaining the partition logic during operation.When using this module with the dcacheCbio module, it is recommenedthis module be the master CBIO device.   This module should be above the cache CBIO module layer.   This is because the cache layer is optimized to fuction efficently atop a single physical disk drive.An implementation of the de-facto standard partition table formatwhich is created by the MSDOS FDISK program is provided with theusrFdiskPartLib module, which should be used to handle PC-stylepartitioned hard or removable drives.EXAMPLEThe following code will initialize a disk which is expected to have upto 4 partitions:.CS  usrPartDiskFsInit( void * blkDevId )    {    const char * devNames[] = { "/sd0a", "/sd0b", "/sd0c", "/sd0d" };    int dcacheSize = 0x30000 ;    void * cbio, * cbio1 ;    /@ create disk cache @/    if( (cbio = dcacheDevCreate(blkDevId, NULL, dcacheSize, "/sd0"))    == NULL )    return ERROR ;    /@ create partition manager with FDISK style decoder, up to 4 parts @/    cbio1 = dpartDevCreate( cbio, 4, usrFdiskPartRead );    /@ create each partition as file system with a particular name @/    dosFsDevCreate( devNames[0], dpartPartGet(cbio1,0), 0, 0 );    dosFsDevCreate( devNames[1], dpartPartGet(cbio1,1), 0, 0 );    dosFsDevCreate( devNames[2], dpartPartGet(cbio1,2), 0, 0 );    dosFsDevCreate( devNames[3], dpartPartGet(cbio1,3), 0, 0 );    }.CEBecause this module complies with the CBIO programming interface onboth its upper and lower layers, it is both an optional and a stackablemodule. SEE ALSO:dcacheLib, dosFsLib, usrFdiskPartLibINTERNAL*//* includes */#include "vxWorks.h"#include "stdlib.h"#include "semLib.h"#include "ioLib.h"#include "classLib.h"#include "objLib.h"#include "string.h"#include "stdio.h"#include "errno.h"#include "private/classLibP.h"#include "private/semLibP.h"#include "assert.h"/* START - CBIO private header */#define	CBIO_DEV_EXTRA	struct dpartCtrl#include "private/cbioLibP.h"/* END - CBIO private header */#include "dpartCbio.h"/* Implementation dependent data structures */typedef struct dpartCtrl    {    CBIO_DEV *	subDev;		/* lower level CBIO device handle */    int		nPart ;		/* Actual # of partitions on the disk */    FUNCPTR	pPartDecodeFunc;/* Extern. partition decoder */    PART_TABLE_ENTRY		/* partition table */		table [ PART_MAX_ENTRIES ];        CBIO_DEV			/* per-partition virtual devices */		vDev [ PART_MAX_ENTRIES ];    CBIO_DEV *	masterDev;	/* master handle CBIO */    } DPART_CTRL ;/* custom use of CBIO fields */#define	cbio_partIndex	cbio_Priv0extern void logMsg( const char *fmt, ... );int dpartDebug = 0;#define	INFO_MSG	logMsg#define	DEBUG_MSG	if(dpartDebug) logMsg/* declarations */LOCAL STATUS dpartBlkRW    (    CBIO_DEV_ID		dev,    block_t		start_block,    block_t		num_blocks,    addr_t		buffer,    enum cbio_rw	rw,    cookie_t		*cookie    );LOCAL STATUS dpartBytesRW    (    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 dpartBlkCopy    (    CBIO_DEV_ID 	dev,    block_t		src_block,    block_t		dst_block,    block_t		num_blocks    );LOCAL STATUS dpartIoctl    (    CBIO_DEV_ID	dev,    int		command,    addr_t	arg    );/* CBIO_FUNCS, one per cbio driver */LOCAL CBIO_FUNCS cbioFuncs = {(FUNCPTR) dpartBlkRW,			      (FUNCPTR) dpartBytesRW,			      (FUNCPTR) dpartBlkCopy,			      (FUNCPTR) dpartIoctl};/********************************************************************************* dpartPartTableFill - Fill in partition geometry** Call external function to decode partitions, and fill the partition* geometry table accordingly.** RETURNS: OK or ERROR if the partition decode function failed for any reason*/LOCAL STATUS dpartPartTableFill( DPART_CTRL * pDc )    {    STATUS ret;    int pn ;    CBIO_DEV *  masterDev, * subDev ;    masterDev = pDc->masterDev;    subDev = pDc->subDev;    if((OBJ_VERIFY( masterDev, cbioClassId ) != OK) ||    	(OBJ_VERIFY( subDev, cbioClassId ) != OK)  )	{	errno = S_objLib_OBJ_ID_ERROR;	return ERROR;	}    bzero( (char *) &pDc->table, sizeof( pDc->table ) );    /* First, call out the external decode function */    ret = pDc->pPartDecodeFunc( pDc->subDev, &pDc->table, pDc->nPart ) ;    if( ret == ERROR )	return ERROR ;    /*     * re-configure device geometry in case it has been replaced     */    masterDev->params.cbio_nBlocks	= subDev->params.cbio_nBlocks ;    masterDev->params.cbio_bytesPerBlk	= subDev->params.cbio_bytesPerBlk ;    masterDev->params.cbio_blksPerTrack	= subDev->params.cbio_blksPerTrack ;    masterDev->params.cbio_nHeads	= subDev->params.cbio_nHeads ;    masterDev->cbio_mode		= subDev->cbio_mode ;    /*     * check sanity of the resulting partition table:     */    for( pn = 0; pn < pDc->nPart; pn ++ )	{	if( pDc->table[pn].spare != 0 || 	    (pDc->table[pn].offset + pDc->table[pn].nBlocks) >		pDc->subDev->params.cbio_nBlocks )		{		DEBUG_MSG("dpartCbio: error: "			"partition spills over disk size: %d blocks\n",			pDc->table[pn].offset + pDc->table[pn].nBlocks -			pDc->subDev->params.cbio_nBlocks );		return ERROR;		}	}    DEBUG_MSG("dpartCbio: partition table decoded:\n");    for( pn = 0; pn < pDc->nPart; pn ++ )	{	DEBUG_MSG("  part %d: offset %d nBlocks %d (next free block %d) \n",		pn, pDc->table[pn].offset, pDc->table[pn].nBlocks,		pDc->table[pn].offset + pDc->table[pn].nBlocks);	pDc->vDev[ pn ].params.cbio_nBlocks = pDc->table[pn].nBlocks ;	pDc->vDev[ pn ].params.cbio_offset  = pDc->table[pn].offset ;    	pDc->vDev[ pn ].params.cbio_bytesPerBlk	= 				subDev->params.cbio_bytesPerBlk ;    	pDc->vDev[ pn ].params.cbio_blksPerTrack = 				subDev->params.cbio_blksPerTrack ;    	pDc->vDev[ pn ].params.cbio_nHeads	= 				subDev->params.cbio_nHeads ;    	pDc->vDev[ pn ].cbio_mode		= subDev->cbio_mode ;	pDc->vDev[ pn ].cbio_readyChanged 	= TRUE ;	}    DEBUG_MSG("dpartCbio: end of partitions, total device blocks %d\n",		pDc->subDev->params.cbio_nBlocks );    return OK ;    }/********************************************************************************* dpartBlkRW	- Read/Write blocks** This routine transfers between a user buffer and the lower layer CBIO* It is optimized for block transfers.  ** dev - the CBIO handle of the device being accessed (from creation routine)* * start_block - the starting block of the transfer operation* * num_blocks - the total number of blocks to transfer* * buffer - address of the memory buffer used for the transfer* * rw - indicates the direction of transfer up or down (READ/WRITE)* * *cookie - pointer to cookie used by upper layer such as dosFsLib(),* it should be preserved.** RETURNS OK or ERROR and may otherwise set errno.*/LOCAL STATUS dpartBlkRW    (    CBIO_DEV_ID		dev,    block_t		start_block,    block_t		num_blocks,    addr_t		buffer,    enum cbio_rw	rw,    cookie_t		*cookie    )    {    CBIO_DEV *	pDev = (void *) dev ;    STATUS retStat ;    if( dev->cbio_readyChanged )	{	errno = S_ioLib_DISK_NOT_PRESENT ;	return ERROR;	}    if( (start_block) > pDev->params.cbio_nBlocks ||    	(start_block+num_blocks) > pDev->params.cbio_nBlocks )	return ERROR;    start_block += pDev->params.cbio_offset;    if( semTake( &pDev->cbio_mutex, WAIT_FOREVER) == ERROR )	return ERROR;    retStat = pDev->pDc->subDev->pFuncs->cbio_blkRW(		pDev->pDc->subDev,		start_block,		num_blocks,		buffer,		rw,		cookie );    if( retStat == ERROR )	if( dev->pDc->subDev->cbio_readyChanged )	    dev->cbio_readyChanged = TRUE ;    semGive( &pDev->cbio_mutex );    return (retStat);    }/********************************************************************************* dpartBytesRW - Read/Write bytes** This routine transfers between a user buffer and the lower layer CBIO* It is optimized for byte transfers.  ** dev - the CBIO handle of the device being accessed (from creation routine)* * start_block - the starting block of the transfer operation* * offset - offset in bytes from the beginning of the starting block* * buffer - address of the memory buffer used for the transfer* * nBytes - number of bytes to transfer* * rw - indicates the direction of transfer up or down (READ/WRITE)* * *cookie - pointer to cookie used by upper layer such as dosFsLib(),* it should be preserved.* * RETURNS OK or ERROR and may otherwise set errno.*/LOCAL STATUS dpartBytesRW    (    CBIO_DEV_ID 	dev,    block_t		start_block,    off_t		offset,    addr_t		buffer,    size_t		nBytes,    enum cbio_rw	rw,    cookie_t		*cookie    )    {    CBIO_DEV * 	pDev = dev ;    STATUS retStat ;    if( dev->cbio_readyChanged )	{	errno = S_ioLib_DISK_NOT_PRESENT ;	return ERROR;	}    if( start_block >= pDev->params.cbio_nBlocks )	return ERROR;    /* verify that all bytes are within one block range */    if (((offset + nBytes) > pDev->params.cbio_bytesPerBlk ) ||	(offset <0) || (nBytes <=0))	return ERROR;    /* apply offset */    start_block += pDev->params.cbio_offset;    if( semTake( &pDev->cbio_mutex, WAIT_FOREVER) == ERROR )	return ERROR;    retStat = pDev->pDc->subDev->pFuncs->cbio_BytesRW(		pDev->pDc->subDev,		start_block,		offset,		buffer,		nBytes,		rw,		cookie );    if( retStat == ERROR )	if( dev->pDc->subDev->cbio_readyChanged )	    dev->cbio_readyChanged = TRUE ;    semGive( &pDev->cbio_mutex );    return ( retStat );    }/********************************************************************************* dpartBlkCopy - Copy sectors ** This routine makes copies of one or more blocks on the lower layer CBIO.* It is optimized for block copies on the subordinate layer.  * * dev - the CBIO handle of the device being accessed (from creation routine)* * src_block - source start block of the copy

⌨️ 快捷键说明

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