Find the solution and make changes.
Code:
#include <bios.h>
#include <dos.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
//Structure of result buffer used by extended 13H services.
struct RESULTBUFFER
{
unsigned int size;
unsigned int infoflags;
unsigned long int cylinders;
unsigned long int heads;
unsigned long int sectors;
unsigned long int locount;
unsigned long int hicount;
unsigned int bytespersector;
unsigned long int configptr;
}rb; //If Int 13 returns some value then it will be stored in rb.
//Function to get drive parameters
void getDriveParameters(unsigned int drive, struct RESULTBUFFER * rbptr)
{
_AH = 0x48; //Service #
_DL = drive ; //Drive number
rbptr->size = 30; //Size of result buffer
_SI = (unsigned int) rbptr; //Offset address of result buffer
geninterrupt (0x13); //Generate Interrupt 13
}
void main()
{
char input[15];
//Will be used to store current cylender, head and sector numbers
unsigned long int lba, cylinder, head , sector;
clrscr();
//Taking input from user
puts ("\nEnter the current Cylinder # : ");
gets (input);
cylinder = atol(input);
puts ("\nEnter the current Head # : ");
gets (input);
head = atol(input);
puts ("\nEnter the current Sector # : ");
gets (input);
sector = atol(input);
//Getting drive parameters of Result buffer using Int 13H/48H
getDriveParameters(0x80,&rb);
//Now we have No. of heads per cylinder in rb.heads and No. of Sectors per track for the disk in rb.sectors
//Now from the following formula we can calculate the LBA index for the selected CHS index
lba=( ( cylinder * rb.heads + head ) * rb.sectors ) + sector - 1;
printf("\n\nThe LBA Index for current CHS address : %ld",lba);
printf("\n\n\n\nPress any key to exit...");
getch();
}