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

📄 usrfdiskpartlib.c

📁 VxWorks BSP框架源代码包含头文件和驱动
💻 C
📖 第 1 页 / 共 4 页
字号:
                      "block %ld, errno %x\n",                      startBlock, errno);            KHEAP_FREE(secBuf);            return (ERROR);            }    /* Check the validity of partition data with 0x55aa signature */    if ((secBuf[pCbioParams->bytesPerBlk - 2] != PART_SIG_MSB) ||         (secBuf[pCbioParams->bytesPerBlk - 1] != PART_SIG_LSB))	{	if ((secBuf[PART_SIG_ADRS]     != PART_SIG_MSB) ||             (secBuf[PART_SIG_ADRS + 1] != PART_SIG_LSB))            {	    if( startBlock == 0)	        {	        printErr ("usrFdiskPartLib warning: " 		      "disk partition table is not initialized\n");	        printErr ("usrFdiskPartLib warning: "		     "use usrFdiskPartCreate( %#x, 1) to initialize the "		     "disk as a single partition\n", dev );	        pPartTab [ 0 ].nBlocks = pCbioParams->nBlocks;	        pPartTab [ 0 ].offset = 0;	        pPartTab [ 0 ].flags = 0xeeee ;	        KHEAP_FREE (secBuf);	        return(1);	        }            printErr ("usrFdiskPartLib error: "                   "Sector %d contains an invalid "                  "MSDOS partition signature 0x55aa.\n", startBlock);	    KHEAP_FREE (secBuf);            return (ERROR);            }	}    /*     * Loop through all parts add mountable parts to table, will call     * itself recursively to parse extended partitions & logical     * drives in extended parts.  Recursive functions may use a lot     * of stack space. Developer should beware of stack overflow.     */    for (i=0 ; i<4 ; i++)        {	/* partition offset relative to DOS_BOOT_PART_TBL */	partOffset = DOS_BOOT_PART_TBL + i * 16 ;        /* if it is a bootable & non-extended partition, add first */	partBootType = secBuf[ partOffset + BOOT_TYPE_OFFSET] ;	partSysType  = secBuf[ partOffset + SYSTYPE_OFFSET] ;	/* XXX - for MS-DOS consistency, Bootable partitions should be first */        /* continue to next loop iteration if an empty partition */        if (partSysType == 0)            {            continue;            }	/* XXX - make this more logical, if not extended and if valid FS */        if (((partSysType != PART_TYPE_DOSEXT)      &&             (partSysType != PART_TYPE_WIN95_EXT))  &&                  ((partSysType == PART_TYPE_DOS4)     ||             (partSysType == PART_TYPE_WIN95_D4) ||             (partSysType == PART_TYPE_DOS3)     ||             (partSysType == PART_TYPE_DOS32)    ||             (partSysType == PART_TYPE_DOS32X)   ||             (partSysType == PART_TYPE_DOS12)))            {            /* Fill the node with the current partition tables data */ 	    pPartTab [ tableIndex ].nBlocks =		DISK_TO_VX_32( &secBuf[ partOffset + NSECTORS_TOTAL]) ;	    /* offset in part table is relative to table location */	    pPartTab [ tableIndex ].offset =		startBlock +		DISK_TO_VX_32( &secBuf[ partOffset + NSECTORS_OFFSET]) ;	    /* type of partition */	    pPartTab [ tableIndex ].flags =		partSysType | (partBootType << 8 ) ;	    tableIndex ++ ; /* next partition in next entry */            }        else if ((partSysType == PART_TYPE_DOSEXT) ||                 (partSysType == PART_TYPE_WIN95_EXT))            {	    /* found an extended partition, call ourselves to parse.	     * For primary partitions, the Relative Sectors 	     * field represents the offset from the beginning 	     * of the disk to the beginning of the partition, 	     * counting by sectors. The Number of Sectors field 	     * represents the total number of sectors in the partition. 	     * Extended partition have the System ID byte in the 	     * Partition Table entry is set to 5.  Within the extended 	     * partition, you can create any number of logical drives. 	     * The primary partition points to an extended which can have	     * multiple "logical drives".	     * When you have an extended partition on the hard disk, 	     * the entry for that partition in the Partition Table 	     * (at the end of the Master Boot Record) points to the 	     * first disk sector in the extended partition.  	     * The first sector of each logical drive in an extended 	     * partition also has a Partition Table, with four entries 	     * (just like the others).  The first entry is for the 	     * current logical drive.  The second entry contains 	     * information about the next logical drive in the 	     * extended partition. Entries three and four are all 	     * zeroes.  This format repeats for every logical drive. 	     * The last logical drive has only its own partition entry 	     * listed. The entries for partitions 2-4 are all zeroes.  	     * The Partition Table entry is the only information 	     * on the first side of the first cylinder of each 	     * logical drive in the extended partition. The entry 	     * for partition 1 in each Partition Table contains the 	     * starting address for data on the current logical drive. 	     * And the entry for partition 2 is the address of the 	     * sector that contains the Partition Table for the next 	     * logical drive. 	     * 	     * The use of the Relative Sector and Total Sectors 	     * fields for logical drives in an extended partition 	     * is different than for primary partitions. 	     * 	     * For the partition 1 entry of each logical drive, the 	     * Relative Sectors field is the sector from the beginning 	     * of the logical drive that contains the Partition Boot 	     * Sector. The Total Sectors field is the number of sectors 	     * from the Partition Boot Sector to the end of the logical 	     * drive.   	     * 	     * For the partition 2 entry, the Relative Sectors field is 	     * the offset from the beginning of the extended partition 	     * to the sector containing the Partition Table for the logical 	     * drive defined in the Partition 2 entry. The Total Sectors 	     * field is the total size of the logical drive defined in 	     * the Partition 2 entry.	     */	    if (startBlock == 0) 	/* In the MBR, logical sector zero */		{  		extStartBlock = DISK_TO_VX_32			(&secBuf[ partOffset + NSECTORS_OFFSET]);			startBlock = extStartBlock; /* startBlock = extended start */		}	    else		/* In extended partition/logical drive */		{		startBlock = DISK_TO_VX_32			(&secBuf[ partOffset + NSECTORS_OFFSET]);			startBlock += extStartBlock;		}            /* Call ourselves to parse extended (sub) partition table */            stat = useFdiskPartParse (dev,	/* same device */			pCbioParams,		/* CBIO device parameters */			pPartTab + tableIndex,	/* next tab entry to fill */			nPart - tableIndex,	/* # left entries */			startBlock, 		/* where ext starts */			extStartBlock		/* where main ext starts */			);	    if( stat == ERROR )		{		KHEAP_FREE(secBuf);		return ERROR ;		}	    tableIndex += stat ;            }	else	    {	    printErr("usrFdiskPartLib: warning: "		    "invalid partition entry encountered "		    "block %d, entry %d, sys type %x, Skipped\n",		    startBlock, i, partSysType );	    }	/* check for max # of partitions */	if( tableIndex >= nPart )	    {      	    KHEAP_FREE(secBuf);	    return tableIndex ;            }        /* loop here to next part or end looping */        }    /*     * if signature is ok, but no partitions where found     * on the first level, assume the entire disk is     * one big file system     */    if (tableIndex == 0 && startBlock == 0)	{	pPartTab [ tableIndex ].nBlocks = pCbioParams->nBlocks;	pPartTab [ tableIndex ].offset = 0;	pPartTab [ tableIndex ].flags = 0x55aa ;	tableIndex ++;	}    KHEAP_FREE(secBuf);    return (tableIndex);    }/******************************************************************************* usrFdiskPartRead - read an FDISK-style partition table** This function will read and decode a PC formatted partition table* on a disk, and fill the appropriate partition table array with* the resulting geometry, which should be used by the dpartCbio* partition manager to access a partitioned disk with a shared disk* cache.** EXAMPLE:* The following example shows how a hard disk which is expected to have* up to two partitions might be configured, assuming the physical* level initialization resulted in the <blkIoDevId> handle:** .CS* devCbio = dcacheDevCreate( blkIoDevId, 0, 0x20000, "Hard Disk");* mainDevId = dpartDevCreate( devCbio, 2, usrFdiskPartRead )* dosFsDevCreate(  "/disk0a", dpartPartGet (mainDevId, 0), 0,0,0);* dosFsDevCreate(  "/disk0b", dpartPartGet (mainDevId, 1), 0,0,0);* .CE* * RETURNS: OK or ERROR if partition table is corrupt**/STATUS usrFdiskPartRead    (    CBIO_DEV_ID cDev,        /* device from which to read blocks */    PART_TABLE_ENTRY *pPartTab, /* table where to fill results */    int nPart               /* # of entries in <pPartTable> */    )    {    CBIO_DEV_ID dev = cDev;    CBIO_PARAMS cbioParams;    /* Verify the device handle, possibly create wrapper */    if (ERROR == cbioDevVerify( dev ))                         {                                                         /* attempt to handle BLK_DEV subDev */                    dev = cbioWrapBlkDev ((BLK_DEV *) cDev);        if( NULL != dev )            {            /* SPR#71633, clear the errno set in cbioDevVerify() */            errno = 0;            }        }                                                     if (dev == NULL)	{	return (ERROR);	}    /* The main device has already been RESET before this is called */    if (TRUE == cbioRdyChgdGet(dev))	{	return (ERROR);	}    /* Get CBIO device parameters */    if (ERROR == cbioParamsGet (dev, &cbioParams))	{	return (ERROR);	}    /* parse the boot partition and fill table with valid partitions */    if  ((useFdiskPartParse(dev, &cbioParams, pPartTab, nPart, 0, 0)) == ERROR)	{	printErr ("useFdiskPartParse error\n");	return (ERROR);	}        return (OK);    }/******************************************************************************* usrFdiskPartCreate - create an FDISK-like partition table on a disk** This function may be used to create a basic PC partition table.* Such partition table however is not intended to be compatible with* other operating systems, it is intended for disks connected to a* VxWorks target, but without the access to a PC which may be used to* create the partition table.** This function is capable of creating only one partition table - the* MBR, and will not create any Bootable or Extended partitions.* Therefore, 4 partitions are supported.** <dev> is a CBIO device handle for an entire disk, e.g. a handle* returned by dcacheDevCreate(), or if dpartCbio is used, it can be either* the Master partition manager handle, or the one of the 0th partition* if the disk does not contain a partition table at all.** The <nPart> argument contains the number of partitions to create. If* <nPart> is 0 or 1, then a single partition covering the entire disk is* created.* If <nPart> is between 2 and 4, then the arguments <size1>, <size2>* and <size3> contain the * .I percentage* of disk space to be assigned to the 2nd, 3rd, and 4th partitions* respectively. The first partition (partition 0) will be assigned the* remainder of space left (space hog).** Partition sizes will be round down to be multiple of whole tracks* so that partition Cylinder/Head/Track fields will be initialized * as well as the LBA fields. Although the CHS fields are written they* are not used in VxWorks, and can not be guaranteed to work correctly* on other systems.** RETURNS: OK or ERROR writing a partition table to disk**/STATUS usrFdiskPartCreate    (    CBIO_DEV_ID cDev, 	/* device representing the entire disk */    int		nPart,	/* how many partitions needed, default=1, max=4 */    int		size1,	/* space percentage for second partition */    int		size2,	/* space percentage for third partition */    int		size3	/* space percentage for fourth partition */    )    {    PART_TABLE_ENTRY partTbl[4];    UINT32 totalSecs, trackSecs, cylSecs, totalTracks, i;    caddr_t secBuf = NULL ;    const char dummyString[] =             "Wind River Systems Inc., DosFs 2.0 Partition Table";    STATUS stat = OK;    CBIO_PARAMS cbioParams;    CBIO_DEV_ID dev = cDev;    bzero((caddr_t) partTbl, sizeof(partTbl));

⌨️ 快捷键说明

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