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

📄 pc_part.c

📁 NUcleus plus 支持的文件系统。 是学习文件系统的很好参考资料。
💻 C
字号:
/************************************************************************
*                                                                       
*       Copyright (c) 2001 by Accelerated Technology, Inc.              
*                                                                       
*  PROPRIETARY RIGHTS of Accelerated Technology are  involved in        
*  the subject matter of this material.  All manufacturing,             
*  reproduction, use, and sales rights pertaining to this subject       
*  matter are  governed by the license agreement.  The recipient of     
*     this software implicitly accepts the terms of the license.        
*                                                                       
*                                                                       
*************************************************************************

*************************************************************************
* FILE NAME                                     VERSION                 
*                                                                       
*       PC_PART.C                               FILE  2.3
*                                                                       
* COMPONENT                                                             
*                                                                       
*       Nucleus File                                                    
*                                                                       
* DESCRIPTION                                                           
*                                                                       
*       Analyze Partition record.                                       
*                                                                       
* DATA STRUCTURES                                                       
*                                                                       
*       None.                                                           
*                                                                       
* FUNCTIONS                                                             
*                                                                       
*       ext_partition_init                  Partition table interpretor.
*                                                                       
* DEPENDENCIES                                                          
*                                                                       
*       pcdisk.h                            File common definitions     
*                                                                       
*************************************************************************/

#include        "file\pcdisk.h"

extern _PC_BDEVSW       pc_bdevsw[];
extern INT              NUF_Fat_Type[];


/************************************************************************
* FUNCTION                                                              
*                                                                       
*       ext_partition_init                                              
*                                                                       
* DESCRIPTION                                                           
*                                                                       
*       Partition table interpretor                                     
*       Given a physical drive number and the addresses of two tables,  
*       partition start and partition end, this routine interprets the  
*       partion tables on the physical drive and fills in the start and 
*       end blocks of each partition. Extended partitions are           
*       supported.                                                      
*       If there are more than max partitions, only max will be         
*       returned.                                                       
*                                                                       
*       Note: the physical drive must be in a raw state so no partition 
*             mapping takes place.                                      
*                                                                       
* AUTHOR                                                                
*                                                                       
*       Kyoichiro Toda, Grape Systems, Inc.                             
*                                                                       
* INPUTS                                                                
*                                                                       
*       driveno                             Drive numver                
*       pstart                              Partition start sector      
*                                            pointer                    
*       pend                                Partition end sector pointer
*       max                                 Number of maximum partitions
*                                                                       
* OUTPUTS                                                               
*                                                                       
*       The number of partitions found on the drive.                    
*                                                                       
*************************************************************************/
INT16 ext_partition_init(INT16 driveno, UINT32 *pstart, UINT32 *pend, 
                         INT16 max)
{
INT16       nparts;
PTABLE      *ppart;
INT8        workbuf[256];
INT8        buf[512];
INT8        *pbuf;
UINT32      ltemp;
UINT32      ltemp2;
UINT16      stemp;
UINT16      i;
UINT32      partition_address;
UINT32      extpart_base_address;
INT16       extflg;
UINT32      rsec;
UINT32      psize;
UINT16      signature;


    nparts = extflg = 0;
    partition_address = extpart_base_address = 0L;

    while(YES)
    {
        if (nparts == max)
            goto done;

        /* Read block zero */
        if ( !pc_bdevsw[driveno].io_proc(driveno, partition_address, buf, 1, YES))
            goto done;

        /* Copy the table to a word alligned buffer so some compilers don't screw up */
        pbuf = &buf[0];
        pbuf += 0x1be;           /* The info starts at buf[1be] */
        copybuff(workbuf, pbuf, sizeof(PTABLE));
        ppart = (PTABLE *) workbuf;
        stemp = ppart->signature;
        SWAP16(&signature, &stemp);

        if (signature != 0xAA55)
            goto done;

        /* Read through the partition table. Find the primary DOS partition */
        for (i = 0; i < 4; i++)
        {
            /* -------------------- Partition Type values --------------------
               0x01     12-bit FAT
               0x04     16-bit FAT. Partition smaller than 32MB.
               0x06     16-bit FAT. Partition larger than or equal to 32MB.
               0x0E     Same as PART_DOS4_FAT(06h),
                        but uses Logical Block Address Int 13h extensions.
               0x0B     32-bit FAT. Partitions up to 2047GB.
               0x0C     Same as PART_DOS32(0Bh), 
                        but uses Logical Block Address Int 13h extensions.
              ---------------------------------------------------------------- */
            if ( (ppart->ents[i].p_typ == 0x01) ||
                 (ppart->ents[i].p_typ == 0x04) ||
                 (ppart->ents[i].p_typ == 0x06) ||
                 (ppart->ents[i].p_typ == 0x0E) ||
                 (ppart->ents[i].p_typ == 0x0B) ||
                 (ppart->ents[i].p_typ == 0x0C) )
            {
                /* Set the partition type */
                NUF_Fat_Type[driveno + nparts + i] = ppart->ents[i].p_typ;

                /* Get the relative start and size */
                SWAP32((UINT32 *)&ltemp, (UINT32 *)&ppart->ents[i].r_sec);
                ltemp += partition_address;
                *(pstart + nparts) = ltemp;

                SWAP32((UINT32 *)&rsec, (UINT32 *)&ppart->ents[i].r_sec);
                SWAP32((UINT32 *)&psize, (UINT32 *)&ppart->ents[i].p_size);

                ltemp2 = rsec + psize - 1L;
                ltemp2 += partition_address;
                *(pend + nparts) = ltemp2;

                nparts++;
                break;
            }
        }

        /* Now see if we have an extended partion */
        for (i = 0; i < 4; i++)
        {
            /* -------------------- Partition Type values --------------------
               0x05     Extended MS-DOS Partition
               0x0F     Same as PART_EXTENDED(05h),
                        but uses Logical Block Address Int 13h extensions.
              ---------------------------------------------------------------- */
            if ( (ppart->ents[i].p_typ == 0x05) ||
                 (ppart->ents[i].p_typ == 0x0F) )
            {
                /* Get the address of the extended partition. */

                SWAP32((UINT32 *)&ltemp, (UINT32 *)&ppart->ents[i].r_sec);
                ltemp += extpart_base_address;
                partition_address = ltemp;

                if (extflg == 0)
                {
                    extpart_base_address = ltemp;
                    extflg = 1;
                }
                break;
            }
        }
        if (i == 4)        /* No extended partitions, bail */
            break;
    }
done:
    return(nparts);
}

⌨️ 快捷键说明

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