News:

GinGly.com - Used by 85,000 Members - SMS Backed up 7,35,000 - Contacts Stored  28,850 !!

Main Menu

Reading The Master Boot Record & FAT of a Normal 1.44 MB Floppy disk

Started by pingu.buj, Apr 07, 2008, 10:26 PM

Previous topic - Next topic

pingu.buj

Reading The Master Boot Record & FAT of a Normal 1.44 MB Floppy disk

#include<stdio.h>
#include<conio.h>
#include<dos.h>
#include<string.h>

char buffer[512],buf[512],c;

/*Procedure To read the content of MBR and place it ina file*/
char *mbr()
{
FILE *f;

strcpy(buffer,"The MBR is not Good");

_BX=(unsigned)buffer; //Reading The MBR
_ES=_DS;
_AX=0x0201;
_CX=0x0001; // Head:00 Track:00 Sector:01
_DX=0x0000;
geninterrupt(0x13);

if(strcmp(buffer,"The MBR is not Good")>0)
{
f=fopen("MBR.DAT","wb+");
fwrite(buffer, sizeof(buffer), 1, f); // Wiriting Content into a file
fclose(f);
}
else
printf("Not A Good Floppy Disk");

return(buffer);

}
char *FAT_table()
{

FILE *f;
char *bu;
strcpy(buffer,"PART I is not good");
strcpy(buf,"PART II is not good");

printf("Loading Frist Part");

_BX=(unsigned) buffer;
_ES=_DS;
_AX=0x0201;   //Reading Frist Part FAT table
_CX=0x0002;  // Head:00 Track:00 Sector:02
_DX=0x0000;

geninterrupt(0x13);

printf(" PRESS A KEY TO CONTINUE");
getch();
printf("Loading Second Part");

_BX=(unsigned) buf;
_ES=_DS;
_AX=0x0201; // Reading Second Part of FAT
_CX=0x0003; // Head:00 Track:00 Sector:03
_DX=0x0000;

geninterrupt(0x13);

if(strcmp(buffer,"PART I is not good")>0&&strcmp(buf,"PART II is not
good")>0)
{
f=fopen("FAT.DAT","wb+");

fwrite(buffer,sizeof(buffer),1,f);
fwrite(buf,sizeof(buf),1,f);        // Writing the content in a file
fclose(f);
}
else
printf("Not a Good Disk");

strcat(buffer,buf);
strcpy(bu,buffer);
textcolor(15);
cprintf("Finished Loading");
return(bu);
}

void main()
{
x:clrscr();

textcolor(15);

cprintf("INSERT FLOPPY IN A:DRIVE");

cprintf("PRESS 'ENTER' TO READ THE MBR & FAT CONTENT");

if((c=getch())==13)// To press 'Enter' key
{
mbr();FAT_table();
}
else
goto x;
getch();
}
? pingu.buj ?