www.pudn.com > READDPT.rar > READDPT.CPP


//Read Disk Partion Table 
#include 
#include 
#include 
#include 
#include 
#include 
int  ReadSector(double Sector_Start,int Sector_Num,char * Buffer);//Read Specified sector 
void ReadDPT(char * Buffer,int is_Expand); 
void ReadDPTItem(char *Buffer); 
int ReadExpandPartion(double Start_Position); 
double HexToDec(char * cPtr,int Length); 
int  DecToHex(double DecNum,char *cPtr,int Length); 
struct DiskAddressPacket 
{ 
   char  PacketSize; 
   char  Reserved; 
   short int BlockCount; 
   void  far * BufferAd; 
   unsigned char   BlockNum[8]; 
}; 
const int DPT_START=446; 
const int DPT_LENGTH=16; 
static int  Main_Expartion_Flag=1; 
static double Main_Expartion_Start; 
void main() 
{ 
   unsigned char  Buffer[512]; 
   if(!ReadSector(0,1,Buffer)) 
   { 
      cout<<"\nSome error have ocuured!"; 
      exit(1); 
   } 
   ReadDPT(Buffer+DPT_START,0); 
   getch(); 
} 
int  ReadSector(double Sector_Start,int Sector_Num,char * Buffer)//Read Specified sector 
{ 
   union REGS in,out; 
   struct SREGS sregs; 
   DiskAddressPacket DAP; 
   DAP.PacketSize=16; 
   DAP.Reserved=0; 
   DAP.BlockCount=Sector_Num; 
   DAP.BufferAd=MK_FP ((char *)FP_SEG (Buffer),Buffer); 
   if(!(DecToHex(Sector_Start,DAP.BlockNum,8))) 
   { 
      return 0; 
   } 
   in.h.ah=0x42; 
   in.h.dl=0x80; 
   in.x.si=(int)&DAP; 
   sregs.ds=FP_SEG(&DAP); 
   int86x(0x13,&in,&out,&sregs); 
   if(!out.x.cflag) 
      return 1; 
   else 
      return 0; 
} 
void ReadDPT(char * Buffer,int is_Expand) 
{ 
   static int ExpartNum=0; 
   if(!is_Expand) 
      printf("\n    ******************Disk DPT****************** "); 
   for ( int i=0;i<4;i++) 
   { 
      if(is_Expand) 
      { 
	 ExpartNum++; 
	 printf("\nThe %d Expand partion parameter is following",ExpartNum); 
      } 
      else 
	 printf("\nThe %d Main partion parameter is following",i+1); 
      ReadDPTItem(Buffer+i*16); 
      if(is_Expand&&1==i) 
	 break; 
   } 
} 
void ReadDPTItem(char *Buffer) 
{ 
   unsigned char PartionType; 
   double Total_Sectors,Start_Position; 
   //Read partion state; 
   printf("\n   State   Start_Position     Partion_Size     Partion Type"); 
   cout<>4; 
      oper2=oper2&0x0f; 
      powresult=pow(16,power); 
      temp=oper2*powresult; 
      DecNum+=temp; 
      power++; 
 
   } 
   return DecNum; 
} 
int DecToHex(double DecNum,char *cPtr,int Length) 
{ 
   double Shang=DecNum,temp; 
   int Yushu=0; 
   int ActualLen=0; 
   int Flag=1; 
   int ByteTo; 
   while (Shang>=0.00001) 
   { 
     temp=Shang/16; 
     temp=(long int)temp; 
     Yushu=Shang-temp*16; 
     Shang=temp; 
     if(!(Flag%2)) 
     { 
	Yushu<<=4; 
	Yushu&=0x00f0; 
	cPtr[ActualLen]&=0x0f; 
	ByteTo=cPtr[ActualLen]; 
	ByteTo|=Yushu; 
	cPtr[ActualLen]=(char)ByteTo; 
	ActualLen++; 
     } 
     else 
     { 
	cPtr[ActualLen]=Yushu; 
     } 
     if(Length==ActualLen) 
     { 
	return 0; 
     } 
     Flag++; 
   } 
   for(int i=ActualLen;i