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

📄 usrfdiskpartlib.c

📁 VxWorks BSP框架源代码包含头文件和驱动
💻 C
📖 第 1 页 / 共 4 页
字号:
    int extPartLevel          /* user should pass zero */    )    {    block_t tmpVal;        UCHAR * secBuf;             /* a secBuf for the sector data */    size_t numNames;      	/* partition name array entries */    UINT8 dosSec;               /* for temp use. Sector         */    UINT8 dosCyl;               /* for temp use. Cylinder       */    STATUS stat;		/* for return status of called  */    int i;                      /* used for loop through parts  */    size_t ix;                  /* used for loop through parts  */    int partOffset;             /* offset from partition tbl ent*/    CBIO_PARAMS cbioParams;    CBIO_DEV_ID cbioDev = cbio;    /* Verify the device handle, possibly create wrapper */    if (ERROR == cbioDevVerify( cbio ))        {        /* attempt to handle BLK_DEV subDev */        cbioDev = cbioWrapBlkDev ((BLK_DEV *) cbio);        if( NULL != cbioDev )            {            /* SPR#71633, clear the errno set in cbioDevVerify() */            errno = 0;            }        }    else	{	cbioDev = cbio;	}    if (cbioDev == NULL)        {        return (ERROR);        }    if (ERROR == cbioParamsGet (cbioDev, &cbioParams))	{	return (ERROR);	}    /* get number of partition type entries */    numNames = ((sizeof (partNames)) / (sizeof (struct partType)));    /* allocate a local secBuf for the read sectors MBR/Part data */    if  ((secBuf = KHEAP_ALLOC(cbioParams.bytesPerBlk)) == NULL)        {        printErr ("usrFdiskPartShow: Error allocating sector buffer.\n");        return (ERROR);        }    /* cbio reads the partition sector into a secBuf */    stat = cbioBlkRW( cbioDev, currentOffset, 1, (addr_t)secBuf,				CBIO_READ, NULL );    if (stat == ERROR)        {        /* if first time reading, a RESET may be needed on the device */        if( cbioIoctl( cbioDev, CBIO_RESET, 0) == ERROR )            {            printErr ("usrFdiskPartShow: error reading"                      " sector %ld, errno %x\n", currentOffset, errno);            printErr ("usrFdiskPartShow: device is not ready\n");            return (ERROR);	    }	else /* Reset OK, try read again */	    {	    stat = cbioBlkRW( cbioDev, currentOffset, 1, (addr_t)secBuf,				CBIO_READ, NULL );	    if (stat == ERROR)		{                printErr ("usrFdiskPartShow: error reading "			  "sector %ld, errno %x\n", currentOffset, errno);		return (ERROR);		}	    }        }     /* Check the validity of partition data with 0x55aa signature */    if ((secBuf[cbioParams.bytesPerBlk - 2] != PART_SIG_MSB) ||         (secBuf[cbioParams.bytesPerBlk - 1] != PART_SIG_LSB))	{	if ((secBuf[PART_SIG_ADRS]     != PART_SIG_MSB) ||             (secBuf[PART_SIG_ADRS + 1] != PART_SIG_LSB))            {            printErr ("usrFdiskPartShow: "                  "Sector %ld contains an invalid signature 0x55aa.\n",		  currentOffset);            return (ERROR);            }	}    /* Loop through and display data for all partitions in the list */    for (i=0 ; i<4 ; i++)        {	/* setup an offset relative to DOS_BOOT_PART_TBL to entry */	partOffset = i * 16;        /* Display extended or MBR */        if (currentOffset == 0x0)            {            printf ("\n");            printf ("Master Boot Record - Partition Table \n");            printf ("--------------------------------------\n");            }        else             {            printf ("\n");            printf ("Extended Partition Table %02d \n", extPartLevel);            printf ("--------------------------------------\n");            }                /* display partition entry and offset */        printf ("  Partition Entry number %02d    ", i);        switch (i)            {            case 3:                printf (" Partition Entry offset 0x1ee\n");                break;            case 2:                printf (" Partition Entry offset 0x1de\n");                break;            case 1:                printf (" Partition Entry offset 0x1ce\n");                break;            case 0:                printf (" Partition Entry offset 0x1be\n");                break;             }        printf ("  Status field = 0x%02x          ",                secBuf[DOS_BOOT_PART_TBL + partOffset +                        BOOT_TYPE_OFFSET]);                if ((secBuf[DOS_BOOT_PART_TBL + partOffset +              BOOT_TYPE_OFFSET]) == (PART_IS_BOOTABLE))            {            printf (" Primary (bootable) Partition \n");            }        else            {            printf (" Non-bootable Partition       \n");            }        /* print partition type name from array */        for (ix=0; ix < numNames; ix++)            {            if ((partNames[ix].partTypeNum) ==                 (secBuf[DOS_BOOT_PART_TBL + partOffset +                         SYSTYPE_OFFSET]))                {                printf ("  Type 0x%02x: ",secBuf[DOS_BOOT_PART_TBL                                                 + partOffset                                                 + SYSTYPE_OFFSET]);                printf ("%s\n",partNames[ix].partTypeName);                break;  /*  found type, so fall out of loop. */                }	    }        /* Skip the rest of a NULL/empty partition */        if (secBuf[DOS_BOOT_PART_TBL + partOffset + SYSTYPE_OFFSET]             == 0x0)            {            printf ("\n");            continue;            }        /* Print out the CHS information */        dosSec = (secBuf[DOS_BOOT_PART_TBL + partOffset                  + STARTSEC_SEC_OFFSET] & 0x3f);        dosCyl =  ((((secBuf[DOS_BOOT_PART_TBL + partOffset                      + STARTSEC_SEC_OFFSET]) & 0xc0) << 2)|                   (((secBuf[DOS_BOOT_PART_TBL + partOffset +                       STARTSEC_CYL_OFFSET]) & 0xff) >> 8));        printf ("  Partition start LCHS: Cylinder %04d, Head %03d,",                 dosCyl, secBuf[DOS_BOOT_PART_TBL + partOffset +                  STARTSEC_HD_OFFSET]);        printf (" Sector %02d   \n", dosSec);        /*         * Print out the ending sector CHS information for partition         * calculate the actual DOS CHS sector and cylinder values.         */        dosSec = (secBuf[DOS_BOOT_PART_TBL + partOffset                  + ENDSEC_SEC_OFFSET] & 0x3f);        dosCyl =  ((((secBuf[DOS_BOOT_PART_TBL + partOffset                              + ENDSEC_SEC_OFFSET]) & 0xc0) << 2) |                    (((secBuf[DOS_BOOT_PART_TBL + partOffset                             + ENDSEC_CYL_OFFSET]) & 0xff) ));        printf ("  Partition end   LCHS: Cylinder %04d, Head %03d,",                dosCyl, secBuf[DOS_BOOT_PART_TBL + partOffset                               + ENDSEC_HD_OFFSET]);        printf (" Sector %02d   \n", dosSec);        /* Print offsets */	tmpVal = DISK_TO_VX_32( &secBuf[DOS_BOOT_PART_TBL + partOffset                 + NSECTORS_OFFSET]) ;        if (extPartLevel == 0x0)            {            printf ("  Sectors offset from MBR partition 0x%08lx\n",tmpVal);            }        else             {            printf ("  Sectors offset from the extended partition 0x%08lx\n",			tmpVal);            }	tmpVal = DISK_TO_VX_32( &secBuf[DOS_BOOT_PART_TBL + partOffset                  + NSECTORS_TOTAL]) ;        printf ("  Number of sectors in partition 0x%08lx\n", tmpVal);	tmpVal = DISK_TO_VX_32( &secBuf[DOS_BOOT_PART_TBL + partOffset                  + NSECTORS_OFFSET]) ;	printf ("  Sectors offset from start of disk 0x%08lx\n",		(tmpVal + currentOffset));        }    /* Loop through all partitions in the list to find extended */    for (i=0 ; i<4 ; i++)        {	/* setup an offset relative to DOS_BOOT_PART_TBL to entry */	partOffset = i * 16;        if ((secBuf[DOS_BOOT_PART_TBL + partOffset + SYSTYPE_OFFSET]             == PART_TYPE_DOSEXT) ||            (secBuf[DOS_BOOT_PART_TBL + partOffset + SYSTYPE_OFFSET]             == 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 (currentOffset == 0) 	/* In the MBR, logical sector zero */		{  		extPartOffset = DISK_TO_VX_32			(&secBuf[DOS_BOOT_PART_TBL + partOffset 			         + NSECTORS_OFFSET]);			currentOffset = extPartOffset; /* startBlock = ext. start */		}	    else		/* In extended partition/logical drive */		{		currentOffset = DISK_TO_VX_32			(&secBuf[DOS_BOOT_PART_TBL + partOffset 			         + NSECTORS_OFFSET]);			currentOffset += extPartOffset;		}            /* Update extPartLevel and parse found extended partition */            extPartLevel++;            usrFdiskPartShow (cbioDev, currentOffset, extPartOffset, 			      extPartLevel);            extPartLevel--;            }        /* next part or end looping */        }    /* Clean up */    KHEAP_FREE(secBuf);      return (OK);    }#endif /* INCLUDE_DOS_PART_SHOW */

⌨️ 快捷键说明

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