Anda di halaman 1dari 8

System Programming Course Code: CS609

Cs609@vu.edu.pk

Lecture # 32

Besides the BPB another data structure can be used equivalently called the DPB (Drive
parameter block). The operating system translates the information in BPB on disk into the
DPB which is maintained main memory. This data structure can be accessed using the
undocumented service 21H/32H. Its detail is shown in the slide below.

Undocumented Services (INT 21H/32H)


On Entry:
AH = 32h
DL – 0 for current Drive
1 for A: Drive
2 for B: Drive
3 for C: Drive
On Exit:
DS:BX = far address of DPB

The DPB contains the information shown in the table below. This information can be
derived from the BPB but is placed in memory in the form of DPB.

DPB (Drive Parameter Block)


Offset Size Description
00h BYTE Drive number (00h = A:, 01h = B:, etc)
01h BYTE Unit number within device driver
02h WORD Bytes per sector
04h BYTE Highest sector number within a cluster
05h BYTE Shift count to convert clusters into sectors
06h WORD Number of reserved sectors at beginning
of drive
08h BYTE Number of F AT’s
09h WORD Number of root directory entries
0Bh WORD Number of first sector containing user
data
0Dh WORD Highest cluster number (number of data
cluster +1)

Virtual University of Pakistan 3


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

DPB (Drive Parameter Block)


Offset Size Description
0Fh WORD number of sectors per FAT
11h WORD Sector number of first directory sector
13h DWORD Address of device driver header
17h BYTE Media ID byte
18h BYTE 00h if disk accessed, FFh if not
19h DWORD Pointer to next DPB
1Dh WORD Cluster at which to start search for free
space when writing, usually the last
cluster allocated
1Fh WORD Number of free clusters on drive, FFFFh if
not know n

The following code shows how the service 21H/32H is invoked and the registers in which
it returns a value. It also shows the contents of the DPB by taking the dump at the
location returned by the service for a FAT 12 volume (i.e. Floppy disk).

-a
13A6:0100 mov ah,32
13A6:0102 int 21
13A6:0104

-p
AX=3200 BX=0000 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000
DS=13A6 ES=13A6 SS=13A6 CS=13A6 IP=0102 NV UP EI PL NZ NA PO NC
13A6:0102 CD21 INT 21

-p
AX=3200 BX=13D2 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000
DS=00A7 ES=13A6 SS=13A6 CS=13A6 IP=0104 NV UP EI PL NZ NA PO NC
13A6:0104 D3E3 SHL BX,CL

-d a7:13d2

00A7:13D0 00 00 00 02 00 00-01 00 02 E0 00 21 00 20 ...........!.


00A7:13E0 0B 09 00 13 00 56 34 12-00 F0 0A FF FF FF FF 00 .....V4.........
00A7:13F0 00 C9 06 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
00A7:1400 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
00A7:1410 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
00A7:1420 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
00A7:1430 00 00 00 00 00 00 00 0C-00 00 80 00 B0 13 10 00 ................
00A7:1440 D8 12 4D 5A 9A 00 29 00-00 00 20 00 C5 00 FF FF ..MZ..)... .....
00A7:1450 A7 05 ..

Virtual University of Pakistan 4


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

The details of the information read from the dump of the DPB are shown below.

Drive # = 0
unit # = 0
Bytes per sector = 0200H = 512 bytes
highest sec no within a cluster = 0
Shift count to convert sec to clust = 0
Reserved sectors at the begining of drive = 0001
FAT copies = 02
Root directory entries = E0 = 224
First sector containing user data = 21H = 33
Highest cluster number = 0b20 = 2848
Number of sectors per fat = 0009 = 9
Sector number of first directory = 0013 = 19

The following code shows how the service 21H/32H is invoked and the registers in which
it returns a value. It also shows the contents of the DPB by taking the dump at the
location returned by the service for a FAT 16 volume (i.e. hard disk partition smaller than
2 GB approx.).

-a
13A6:0100 mov ah,32
13A6:0102 int 21
13A6:0104

-p
AX=3200 BX=0000 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000
DS=13A6 ES=13A6 SS=13A6 CS=13A6 IP=0102 NV UP EI PL NZ NA PO NC
13A6:0102 CD21 INT 21

-p
AX=3200 BX=13D2 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000
DS=00A7 ES=13A6 SS=13A6 CS=13A6 IP=0104 NV UP EI PL NZ NA PO NC
13A6:0104 0000 ADD [BX+SI],AL DS:13D2=05

-d a7:13d2

00A7:13D0 05 05 00 02 07 03-08 00 02 00 02 C0 01 B4 ..............


00A7:13E0 CB CC 00 A0 01 56 34 12-00 F8 0A FF FF FF FF 00 .....V4.........
00A7:13F0 00 AA CB 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
00A7:1400 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
00A7:1410 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
00A7:1420 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
00A7:1430 00 00 00 00 00 00 00 0C-00 00 80 00 B0 13 10 00 ................
00A7:1440 D8 12 4D 5A 9A 00 29 00-00 00 20 00 C5 00 FF FF ..MZ..)... .....
00A7:1450 A7 05 ..

Virtual University of Pakistan 5


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

The details of the information read from the dump of the DPB are shown below.

drive no = 05 = F drive
unit no = 05
bytes per sector = 200H = 512
Highest sector number within a cluster = 7
Hence Sec. per cluster = highest sec. within a
cluster + 1 = 7 + 1 = 8
shift count = 3
reserved sectors = 0008
Number of Fats = 2
Root Dir Entries = 0200H = 512
First sector containing user data = 01C0 = 448
Highest cluster number = cbb4H = 52148
No of sectors per FAT = CC = 204
Sector number of First directory = 01A0 = 416

#include <bios.h>
#include <dos.h>

struct BPB
{
unsigned int bytespersec;
unsigned char secperclust;
unsigned int reservedsecs;
unsigned char fats;
unsigned int rootdirents;
unsigned int smallsecs;
unsigned char media;
unsigned int fatsecs;
unsigned int secspertrack;
unsigned int heads;

Virtual University of Pakistan 6


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

unsigned long int hiddensecs;


unsigned long int hugesecs;
unsigned char driveno;
unsigned char reserved;
unsigned char bootsignature;
unsigned long int volumeid;
unsigned char volumelabel[11];
unsigned char filesystem[8];
};
struct bootblock
{
unsigned char jumpinstruction[3];
unsigned char osname[8];
struct BPB bpb;
unsigned char code[448];
};

void nputs( char *p, int n)


{
int i ;
for (i =0;i<n;i++)
putch(p[i]);
}
void main( void)
{
struct bootblock bb;
clrscr();
absread(0,1,0,&bb);
printf("jump instruction = % x\n" ,
bb.jumpinstruction);
printf("OS = ");
nputs (bb.osname,8);
puts("\n");

Virtual University of Pakistan 7


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

printf("No of bytes per sector = % d \nNo of sectors


per cluster = % d\n No of reserved sectors =
%d" , bb.bpb.bytespersec,
bb.bpb.secperclust, bb.bpb.reservedsecs);
printf("No of FATs = % d\nNo of Root Directory
entry = % d \nNo of Small sectors = % d
\nMedia descriptor = % xH \nFAT sectors =
%dSectors per track = % d \nNo of Heads =
%d \nNo of hidden sectors = % ld \nNo. of
huge sectors = % ld \nDrive number = % x
\nReserved = % xH \nBoot Signature = % xH
\nVolume ID = % lx \n" , bb.bpb.fats,
bb.bpb.rootdirents, bb.bpb.smallsecs,
bb.bpb.media, bb.bpb.fatsecs,
bb.bpb.secspertrack, bb.bpb.heads,
bb.bpb.hiddensecs, bb.bpb.hugesecs,
bb.bpb.driveno, bb.bpb.reserved,
bb.bpb.bootsignature,bb.bpb.volumeid);

puts (" Volume Name =");


nputs (bb.bpb.volumelabel,11);
puts ("\n");

puts (" File system =");


nputs (bb.bpb.filesystem,8);
puts("\n");
getch();
}

The above program creates a data structure in reflection of the BPB and reads the boot
record of the volume using absread(). It extracts the data part of the boot block and
displays all the values stored in it.

Virtual University of Pakistan 8


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

#include <dos.h>
#include <bios.h>
struct DPB {
unsigned char driveno;
unsigned char unitno;
unsigned int bytespersec;
unsigned char highestsecinclust;
unsigned char shiftcount;
unsigned int reservedsecs;
unsigned char fats;
unsigned int rootentries;
unsigned int firstuserdatasec;
unsigned int highestclustnumber; //only for 16 and 12
bit FATs
unsigned int secsperfat;
unsigned int firstdirsec;
unsigned int ddheaderoff;
unsigned int ddheaderseg;

unsigned char media;


unsigned char accessed;
unsigned int nextdpboff;
unsigned int nextdpbseg;
unsigned int searchstart;
unsigned int freeclust;
};
void main (void)
{
struct DPB far *ptr;
struct DPB dpb;
clrscr();
_asm push DS;
_asm push BX;
_AH=0x32;
_DL=1;
geninterrupt (0x21);

Virtual University of Pakistan 9


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

ptr = (struct DPB far *)MK_FP(_DS,_BX);


dpb=*ptr;
_asm pop BX;
_asm pop DS;
printf("Drive No = %x\n",dpb.driveno);
printf("Unit No = %x\n",dpb.unitno);
printf("Bytes per sector = %d\n",dpb.bytespersec);
printf("Highest sector number within a cluster =
%d\n",dpb.highestsecinclust);
printf("Shift Count = %d\n",dpb.shiftcount);
printf("Reserved sectors = %d\n",dpb.reservedsecs);
printf("number of FATs = %d\n",dpb.fats);
printf("Root enteries = %d\n",dpb.rootentries);
printf("First User data sec = %d\n",dpb.firstuserdatasec);
printf("Highest Cluster number =
%d\n",dpb.highestclustnumber);
printf("No of Sectors per FAT = %d\n",dpb.secsperfat);
printf("First directory Sector = %d\n",dpb.firstdirsec);

printf("DD header offset = %x\n",dpb.ddheaderoff);


printf("DD header segment = %x\n",dpb.ddheaderseg);
printf("Media ID= %d\n",dpb.media);
printf("Disk accessed recently= %d\n",dpb.accessed);
printf("Next DPB offset address = %d\n",dpb.nextdpboff);
printf("Next DPB segment address =
%d\n",dpb.nextdpbseg);
printf("Point where to start the search for next cluster=
%d\n",dpb.searchstart);
printf("Free cluster= %d\n",dpb.freeclust);
getch();
}

The above program is doing is the same using the DPB rather than BPB.

Virtual University of Pakistan 10

Anda mungkin juga menyukai