- 论坛徽章:
- 0
|
请问有没有C写的恢复硬盘分区的源代码
#include<bios.h>;
#include<stdio.h>;
#include<dos.h>;
void write_pt(int cyl);
unsigned char sect[1024],boot[512];
int cyls;int heads;int sects;
main()
{int i;union REGS r;
r.h.ah=8;
r.h.dl=0x80;
int86(0x13,&r,&r);
if(r.h.ah){printf("Hard disk not ready error! \n" ;
exit(0);}
heads=r.h.dh+1;
cyls=r.h.ch+256*(r.h.cl>;>;6)+1;
sects=r.h.cl&0x3f;
printf("Searching.......\n" ;
for(i=1;i<cyls;i++)
{if (kbhit())exit(0);
biosdisk(2,0x80,1,i,1,2,sect);
if(sect[0]==0xeb&§[1]==0x3c&§[2]==0x90
&§[510]==0x55&§[511]==
0xaa&§[512]==0xf8&§[513]==0xff&§[514]==0xff)
{write_pt(i);exit(0);}}
write_pt(cyls);}
void write_pt(int cyl)
{char ch;
union cc{char ch[2];unsigned int i;}c;
union ll{char ch[5];long i;}l;
int i;unsigned char t1[16],t2[16];
t1[0]=0x80;
t1[1]=0x01;
t1[2]=0x01;
t1[3]=0x00;
t1[4]=0x04;
t1[5]=heads-1;
c.i=cyl-1;
t1[7]=c.ch[0];
t1[6]=c.ch[1]<<6|sects;
t1[8]=sects;
t1[9]=0;
t1[10]=0;
t1[11]=0;
l.i=(long)cyl*sects*heads-sects;
t1[12]=l.ch[0];
t1[13]=l.ch[1];
t1[14]=l.ch[2];
t1[15]=l.ch[3];
if(cyl<cyls){
t2[0]=0;
t2[1]=0;
c.i=cyl;
t2[2]=c.ch[1]<<6|1;
t2[3]=c.ch[0];
t2[4]=0x05;
t2[5]=heads-1;
c.i=cyls-1;
t2[7]=c.ch[0];
t2[6]=c.ch[1]<<6|sects;
l.i=l.i+sects;
t2[8]=l.ch[0];
t2[9]=l.ch[1];
t2[10]=l.ch[2];
t2[11]=l.ch[3];
l.i=(long)cyls*sects*heads-l.i;
t2[12]=l.ch[0];
t2[13]=l.ch[1];
t2[14]=l.ch[2];
t2[15]=l.ch[3];
}
else for(i=0;i<16;i++)t2=0;
printf("The Partition table is: \n" ;
for(i=0;i<16;i++)printf("%3x",t1);
printf("\n" ;
for(i=0;i<16;i++)printf("%3x",t2);
printf("\nAre you sure you want to write into the disk?(n)" ;
ch=getche();
if(ch=='Y'||ch=='y'){
biosdisk(2,0x80,0,0,1,1,boot);
for(i=0;i<0x10;i++)boot[0x1be+i]=t1;
for(i=0;i<0x10;i++)boot[0x1ce+i]=t2;
boot[510]=0x55;
boot[511]=0xaa;
biosdisk(3,0x80,0,0,1,1,boot);
}}
有人可以帮忙注解一下吗
我看不大明白,谢谢了 |
|