TC 2.0源文件:硬盘分区表的保存及恢复-无法读源文件或磁盘

TC 2.0源文件:硬盘分区表的保存及恢复-无法读源文件或磁盘

/* 硬盘分区表的保存及恢复 */

# include<stdio.h>

# include<bios.h>

# include<fcntl.h>

# include<sys\types.h>

# include<sys\stat.h>

void helpmsg(void);

int main(int argc,char *argv[])

{

int result;

char buffer[512];

FILE *fp;

if(argc==1)

helpmsg();

if(*argv[1]=='a'||*argv[1]=='A')

{

result=biosdisk(2,0x80,0,0,1,1,buffer);

if(!result)

{

printf("读硬盘分区表成功\n");

if((fp=fopen("a:part.doc","wb+"))==NULL)

{

fprintf(stderr,"不能创建文件:a:\part.doc\n");

exit(1);

}

fwrite(buffer,1,512,fp);

fclose(fp);

printf("硬盘分区表保存成功\n");

return 0;

}

else

{

fprintf(stderr,"读硬盘分区表失败");

exit(1);

}

}

if(*argv[1]=='c'||*argv[1]=='C')

{

if((fp=fopen("a:part.doc","rb+"))==NULL)

{

fprintf(stderr,"文件打开失败");

exit(1);

}

fread(buffer,1,512,fp);

result=biosdisk(3,0x80,0,0,1,1,buffer);

if(!result)

{

printf("硬盘分区表恢复成功");

fclose(fp);

return 0;

}

else

{

fprintf(stderr,"硬盘分区表恢复失败");

fclose(fp);

exit(1);

}

}

return 0;

}

void helpmsg(void)

{

puts("程序使用的正确格式为:Boot[A]或Boot[C]");

puts("其中参数:B---保存硬盘分区表到B盘");

puts("其中参数:C---从B盘恢复硬盘分区表");

exit(0);

}

推荐阅读