/*program to save the partion table of your hard disk
for future use.
it will save your partition table in a file partition.dat
*/
#include
#include
#include
#include
#include
void main ()
{
FILE *f;
int drive=0x0;//default drive is floppy drive
char c,d;
char buffer[512];
printf("1.Hard disk
2.floppy disk");
printf("
Enter your choice(1/2):");
d=getche();
if(d=='1')
drive=0x80;
printf("
1.Creat the backup of your MBR
");//menu for user
printf("2.Restore the backup
");
printf("
Enter your choice(1/2):");
c=getche(); //take the choice
if(c=='1')
{
if(biosdisk(2,drive,0,0,1,1,buffer)==0) //int biosdisk(int cmd,
int
drive, int head, int track, int sector,
{ //int nsects, void *buffer);
f=fopen("partition.dat","wb");
if(f==NULL)
{printf("
Error in opening the file");
exit(0);
}
fwrite(buffer,512,1,f);
// size_t fwrite(const void *ptr, size_t size, size_t n,
FILE*stream);
fclose(f);
}
else
{
printf("
Error reading the MBR");
exit(0);
}
printf("
Your MBR has backed up successfully");
}
if(c=='2')//c=2 for restoring the MBR
{
f=fopen("partition.dat","rb");
if(f==NULL)
{printf("
Error in opening the file:partition.dat");
exit(0);
}
fread(buffer,512,1,f);
printf("
Are you sure to restore:(y/n):");
d=getchar();
if(toupper(d)=='Y')
{if(biosdisk(3,drive,0,0,1,1,buffer)!=0)
printf("
Error in writing the sector");
else
printf("
Your MBR has restored successfully");
}
}
}
Get your codes from..
Thursday, May 8, 2008
bootsector editer (C- h/w interaction)
Labels:
(C- h/w interaction)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment