Advertisement

04.25.2003 at 12:40AM PDT, ID: 20595916
[x]
Attachment Details

bios extended read (int 13h, ah=42h)

Asked by manish_regmi in C Programming Language

Tags: disk_address_packet

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_ADDRESS_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,&regs,&regs,&sregs);
     return 0;
}

int main()
{
MBR *mbr;
DISK_ADDRESS_PACKET *p;
clrscr();
mbr=(MBR*) malloc(sizeof(MBR));
p->SizeOfPacket=sizeof(DISK_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].starting_head);
printf(" starting sector :- %d\n",mbr->partno[0].starting_sector);
printf(" starting cylinder:- %d\n",mbr->partno[0].starting_cylinder);
printf(" syatem id    :- %s\n",print_partition(mbr->partno[0].system_id));
printf(" Relative Sectors   :- %ld\n",mbr->partno[0].relative_sectors);
printf(" total sectors      :- %ld\n\n\n",mbr->partno[0].total_sectors);
free(mbr);
getch();
return 0;
}Start Free Trial
 
Loading Advertisement...
 
[+][-]04.25.2003 at 02:29AM PDT, ID: 8393869

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: C Programming Language
Tags: disk_address_packet
Sign Up Now!
Solution Provided By: jsemenak
Participating Experts: 1
Solution Grade: B
 
 
 
Loading Advertisement...
20080716-EE-VQP-32