hi, I have written a code to read a disk sector using int 13h, ah=42. But it is not working properly. can anybody help me with the code .
/* code starts here */
//all headers included
typedef unsigned char UBYTE; /* 1 byte in 16-bit machine */
typedef unsigned int UWORD; /* 2 bytes in 16-bit machine */
typedef unsigned long UDWORD; /* 4 bytes in 16-bit machine */
typedef struct tagDISK_ADDRESS_PACKET {
BYTE SizeOfPacket;
BYTE Reserved;
WORD NBlocks;
DWORD Buffer;
DWORD StartingBlockLo;
DWORD StartingBlockHi;
}DISK_ADDRESS_PACKET;
typedef struct tagPARTITION_INFO {
BYTE boot_indicator;
BYTE starting_head;
unsigned starting_sector :6;
unsigned starting_cylinder:10;
BYTE system_id;
BYTE ending_head;
unsigned ending_sector:6;
unsigned ending_cylinder:10;
DWORD relative_sectors;
DWORD total_sectors;
}PARTITION;
typedef struct tagMBR {
char res[444];
PARTITION partno[4];
DWORD signature;
}MBR;
int ReadDiskGeometry(DISK_ADDR
ESS_PACKET
*g)
{/* asm {
mov ah, 0x42;
mov dl, 0x80;
lea si, g;
int 0x13;
};*/
union REGS regs;
struct SREGS sregs;
regs.h.ah=0x42;
regs.h.dl=0x80;
regs.x.si=FP_OFF(g);
sregs.ds=FP_SEG(g);
int86x(0x13,®s,®s,&s
regs);
return 0;
}
int main()
{
MBR *mbr;
DISK_ADDRESS_PACKET *p;
clrscr();
mbr=(MBR*) malloc(sizeof(MBR));
p->SizeOfPacket=sizeof(DIS
K_ADDRESS_
PACKET);
p->NBlocks=0x01;
p->Buffer=(DWORD)mbr;
p->StartingBlockLo=0x00;
p->StartingBlockHi=0x00;
ReadDiskGeometry(p);
printf(" Bootable :- %x\n",mbr->partno[0].boot_
indicator)
;
printf(" starting head :- %d\n",mbr->partno[0].start
ing_head);
printf(" starting sector :- %d\n",mbr->partno[0].start
ing_sector
);
printf(" starting cylinder:- %d\n",mbr->partno[0].start
ing_cylind
er);
printf(" syatem id :- %s\n",print_partition(mbr-
>partno[0]
.system_id
));
printf(" Relative Sectors :- %ld\n",mbr->partno[0].rela
tive_secto
rs);
printf(" total sectors :- %ld\n\n\n",mbr->partno[0].
total_sect
ors);
free(mbr);
getch();
return 0;
}
Start Free Trial