Sunteți pe pagina 1din 7

System Programming Course Code: CS609

Cs609@vu.edu.pk

Lecture # 29

LBA=0 (MBR) LBA =1388B3B

Logical Drive Extended Partition

3F 1388AFC 0390620A

3F 1388AFC
Logical Logical Extended Partition
Drive Drive

2nd Partition Relative start = 1388B3B


Table

1388B3B

2711676H

Virtual University of Pakistan 238


System Programming Course Code: CS609
Cs609@vu.edu.pk

Next Partition Table in Chain

Logical Logical Logical Extended


Drive Drive Drive Partition

3rd Partition Table Relative


Addre ss =
2711676h
Physical LBA
= 3A9A1B1H
2711676H

3A9A1B1H

Above slides shows the information collected as yet which indicates the logical drive
there starting LBA blocks, the number of block , the hidden blocks etc. The following
slide shows the contents of the data part of partition table of the last extended partition.

13A E: 010 0 00 0 0 00 00 00 0 0 00 00 -00 0 0 00 00 00 0 0 00 00 .. .. ... .. ... .. ..

13AE:0110 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................


13AE:0120 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
13AE:02A0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................

skipped

13AE:02B0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 10 ................


13AE:02C0 C1 FF 07 4A FF FF 3F 00-00 00 55 4B 1F 01 00 00 ...J..?...UK....
13AE:02D0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
13AE:02E0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
13AE:02F0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 55 AA ..............U.

It has just one data entry for the logical drive indicating that this is the partition table in
the chain. The detail of the contents this partition table are shown below.

Virtual University of Pakistan 239


System Programming Course Code: CS609
Cs609@vu.edu.pk

First Partition
System ID = 07 = Windows FAT32 partition
first block = 3F
First block physical address = 3F + 01388b3b +1388b3b +
1388b3b (Blocks in previous partions)
No. of blocks = 011f4b55
end cylinder# = 1023
end sec # = 63 indicating a LBA disk

Second Partition
System ID = 0 = Unused

The following slide shows the summary of all the data collected as yet depicting 4 logical
drives and the number of blocks within.

3F 3F 3F 3F

1388B3B 1388B3B 1388B3B 11F4B94

Virtual University of Pakistan 240


System Programming Course Code: CS609
Cs609@vu.edu.pk

1ST Partition 2nd Partition 3rd Partition


MBR Table Table Table

Null

#include <dos.h>
#include <bios.h>
struct DA P
{ unsigned char size;
unsigned char reserved1;
unsigned char blocks;
unsigned char reserved2;
unsigned char far *buffer;
unsigned long int lbalod;
unsigned long int lbahid;
} dap ;
struct PartEntry
{ unsigned char BootableFlag;
unsigned char StartHead;
unsigned char StartSector;
unsigned char StartCylinder;
unsigned char SystemID;
unsigned char End Head ;
unsigned char End Sector;
unsigned char EndC ylinder;
unsigned long AbsBegin;
unsigned long SectCount;
};

Virtual University of Pakistan 241


System Programming Course Code: CS609
Cs609@vu.edu.pk

struct PartTable
{
unsigned char code [446];
struct PartEntry e[4];
unsigned int signature;
};
struct DA P dap ;
void ReadLBA (unsigned int drive,
unsigned long int lbalo, unsigned long int lbahi,
unsigned char far * buffer, int nsects)
{
dap.lbalod = lbalo ;
dap.lbahid=lbahi;
dap.size=16;
dap.reserved1=0;
dap.blocks=nsects;
dap.reserved2=0;
dap.buffer =buffer;// (unsigned char far *)MK_FP(_DS,buf);
_AH=0x42;
_DL=drive;
_SI=(unsigned int)&dap;
geninterrupt(0x13);
}

void GetPart (unsigned char drive,


unsigned long int low , unsigned long int high)
{
struct PartTable p;
unsigned int Ssec, Esec;
unsigned int Scyl, Ecyl;
unsigned long int BSec;
int i;
ReadL BA(drive,low ,high, (unsigned char *) &p,1);
if (p.signature == 0xaa55)
{
for (i=0; i<4;i ++)
{
if (p.e[i].System ID != 0)
{
Ssec = p.e[i].StartSector;
Ssec = Ssec << 2;
Scyl = p.e[i].StartCylinder;
*(((unsigned char *)(& Scyl))+1) =
*(((unsigned char *)(&Ssec))+1);
Esec = p.e[i].EndSector;
Esec = Esec << 2;
Ecyl = p.e[i].EndCylinder;

Virtual University of Pakistan 242


System Programming Course Code: CS609
Cs609@vu.edu.pk

*(((unsigned char *)(& Ecyl))+1)=


*(((unsigned char *)(&Esec))+1);
printf( "Start Head = %d \n Start Sector =
%d \n Start Cylinder = %d\n End Head =
%d \n End Sector = %d \n End Cylinder =
%d\n Boot Record w ith respect to start of partition =
%ld\n Count of sectors from boot sector =
%ld\n System ID= %x L BA (Low ) = %ld",
p.e[i].StartHead, p.e[i].StartSector & 0x3f,
Scyl,p.e[i].End Head, p.e[i].EndSector & 0x3f,
Ecyl, p.e[i].AbsBegin, p.e[i].SectCount,p.e[i].System ID,low );
if (p.e[i].System ID == 0x0f)
GetPart(drive,low +p.e[i].AbsBegin,0);
BSec = p.e[i].AbsBegin;
getch();
}
else
printf ("ParTition unused or unknown\n");
}
}
else
printf("Not a Partition Table\n");
}

void m ain ()
{
GetPart(0x80,0,0) ;
}

Above is a listing of a simple program that reads the partition table using the extended
13H services. It then displays the contents of the data part of the partition table read. For
this purpose it uses various data structures designed in reflection of the partition table and
16 bytes data entries within. The program uses recursion and calls the getpart() function
recursively whenever it finds an extended partition to read the data within the extended
partition table.

Virtual University of Pakistan 243


System Programming Course Code: CS609
Cs609@vu.edu.pk

Get Drive Parameters


On Entry:
AH – 48
DL – Drive number
DS:SI – Address of result buffer
On Exit:
Carry Clear
AH – 0
DS:SI – result buffer
Carry Set
AH – Error Code

The partition table data entry also stores the CHS address of the starting block. But this
address is left insignificant if a LBA enable disk is in question. However LBA address
can be used in place of the CHS address, and in case CHS address is required it can be
calculated if the total number of tracks, sectors and heads are known. To get the total
number of tracks, sectors and head the above described service can be used.

Virtual University of Pakistan 244

S-ar putea să vă placă și