Sie sind auf Seite 1von 9

System Programming Course Code: CS609

Cs609@vu.edu.pk

Lecture # 30

Virtual University of Pakistan 245


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

Above slides shows the structure of result buffer used by extended 13H services. If a
extended service returns a value it will be stored in the result buffer as described above.

#include <bios.h>
#include <dos.h>
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;

Virtual University of Pakistan 246


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

void main()
{
clrscr();
_AH = 0x48;
_DL = 0x80;
rb.size = 30;
_SI = (unsigned int) &rb;
geninterrupt (0x13);
printf(" Heads = %ld\n Sectors = %ld\n
Tracks/Cylinders = %ld\n Byte s per sector =
%d\n Block count Low word =
%ld\n Block count Hi Word = %ld\n",
rb.heads, rb.sectors, rb.cylinders,
rb.byte spersector,rb.locount,rb.hicount);
}

The above program uses a RESULTBUFFER data structure in reflection of the result
buffer described in previous slides. It uses the interrupt 13H/48H to get the drive
parameters and then displays the received total number of sectors, heads and cylinders.

#include <bios.h>
#include <dos.h>
struct RESULTBUFFER
{ unsigned int size;
unsigned int infoflags ;
unsigned long int c ylinders;
unsigned long int heads;
unsigned long int sectors;
unsigned long int locount;
unsigned long int hicount;
unsigned int bytespersector;
unsigned long int configptr;
} rb;
void getdr vparam (unsigned int drive,
struct RESULTBUFFER * rbptr)
{ clrscr();
_AH = 0x48;
_DL = drive ;
rbptr->size = 30;
_SI = (unsigned int) rbptr;
geninterrupt (0x13);
}

Virtual University of Pakistan 247


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

void main ()
{
char st[15];
unsigned long int lbaindex;
unsigned int cylinder, head , sector, temp;
puts ("Enter the LBA address");
gets (st);
lbaindex = atol(st);
getdrvparam (0x80,&rb);
cylinder = lbaindex / (rb.heads*rb.sectors);
temp = lbaindex % (rb.heads*rb.sectors);
head = temp / rb.sectors;
sector = temp % rb.sectors + 1;
printf ("Heads = %d sectors = %d
c ylinders = %d" , head, sector, cylinder);

This is also a quite similar program only difference is that it also translates a LBA address
into CHS address and displays it, for this purpose it gets the drive parameters to know the
total number of heads, sectors and cylinders.

LSN (Logical Sector Number)


C H S
0 0 1 = Partition Table
For fixed disk
Hidden Blocks =
No. of Sec/Track

0 1 1 = Boot Block

Boot Block has LSN = 0


• If the blocks are indexed from the boot block such
that the boot block has index = 0,Then this index is
called LSN.
• LSN is relative index from the start of logical drive,
not the physical drive.

LSN is also indexed like LBA the only difference is that LBA is the address relative to
the start of physical drive (i.e. absolute), whereas LSN address is the address from the
start of logical partition i.e relative.

Virtual University of Pakistan 248


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

Example LBA=2711676

LBA=1388B3B LBA=2711676+3F
LSN=1 No LSN LSN=0

Logical Logical
Drive Drive

LBA=0 LSN=2 LBA=1388B3B+3F LSN=1


LSN = 0 First Logical
LSN=2
Sector
First Logical Block in drive
LBA = 3F
LSN = 0

As in the above example it can be noticed that the LBA = 0 is not the same as LSN=0.
The LBA=0 block is the first block on disk. Whereas each logical partition has LSN=0
block which is the first block in logical drive and is not necessarily the first block on
physical drive. Also notice the hidden blocks between the first physical block on each
partition and its first LSN block. These hidden blocks are not used by the operating
system for storing any kind of data.

Conclusion
• LBA is physical or absolute address.
• LSN is relative address with respect to the start of
Logical Drive.

Virtual University of Pakistan 249


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

File System Data Structures


• BIOS Parameter Block (BPB)
• Drive Parameter Block (DPB)
• File Control Block (FCB)
• FAT 12, FAT 16, FAT 32
• Master File Table (MFT)

To understand the file systems of DOS and Windows the above given data structure
should be understood which are used by the operating system for file management. In the
coming lecture these data structures will be discussed in detail.

Anatomy of a FAT based file system

System Area

FAT FAT Root Dir User Data


(FAT 12&16)

Boot Clust 2
Block

Above slide shows the overall anatomy of a FAT based system. Starting block(s) is /are
the boot block(s), immediately after which the FAT (File allocation table) starts. A typical
Virtual University of Pakistan 250
System Programming Course Code: CS609
Cs609@vu.edu.pk

volume will contain two copies of FAT. After FAT the root directory is situated which
contain information about the files and folders in the root directory. Whole of this area
constitutes the systems area rest of the area is used to store user data and folders.

Clusters
• A cluster is a collection of contiguous blocks.
• User Data is divided into clusters
• Number of blocks within a cluster is in power of 2.
• Cluster size can vary depending upon the size of
the disk.
• DOS has a built in limit of 128 blocks per cluster.
• But practically limit of 64 blocks per cluster has
been established.
• We will learn more about the size of clusters, later.

BPB (BIOS Parameter Block)


• Situated within the Boot Block.
• Contains vital information about the file system.

BIOS parameter block is a data structure maintained by DOS in the boot block for each
drive. The boot block is typically a 512 byte block which as seen the previous slides is
the first logical block i.e. LSN = 0. It contains some code and data. The data part
constitutes the BPB. Details for FAT 12 and 16 are shown in following slides.
Virtual University of Pakistan 251
System Programming Course Code: CS609
Cs609@vu.edu.pk

BPB (BIOS Parameter Block)


Byte Field
Meaning
Offset Length
0x0B WORD Bytes per Sector. The size of a hardware
sector. Usually 512.
0x0D BYTE Sectors Per Cluster. The number of sectors
in a cluster. The default cluster size for a
volume depends on the disk size and the
file system.
0x0E WORD Reserved Sectors. The number of sectors
from the Partition Boot Sector to the start
of the first file allocation table, including
the Partition Boot Sector. The minimum
value is 1.
0x10 BYTE Number of file allocation tables (FATs). The
number of copies of the file allocation table
on the volume. Typically, the value of this
field is 2.
0x11 WORD Root Entries. The total number of file name
entries that can be stored in the root folder
of the volume.

0x13 WORD Small Sectors. The number of sectors on


the volume if the number fits in 16 bits
(65535). For volumes larger than 65536
sectors, this field has a value of 0 and the
Large Sectors field is used instead.
0x15 BYTE Media Type. Provides information about the
media being used. A value of 0xF8
indicates a hard disk.
0x16 WORD Sectors per file allocation table (FAT).
Number of sectors occupied by each of the
file allocation tables on the volume.
0x18 WORD Sectors per Track.
0x1A WORD Number of Heads.
0x1C DWORD Hidden Sectors.
0x20 DWORD Large Sectors. If the Small Sectors field is
zero, this field contains the total number of
sectors in the volume. If Small Sectors is
nonzero, this field contains zero..

Virtual University of Pakistan 252


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

0x24 BYTE Physical Disk Number. This is related to


the BIOS physical disk number. Floppy
drives are numbered starting with 0x00 for
the A disk. Physical hard disks are
numbered starting with 0x80. The value is
typically 0x80 for hard disks, regardless of
how many physical disk drives exist,
because the value is only relevant if the
device is the startup disk.
0x25 BYTE Current Head. Not used by the FAT file
system. (Reserved)
0x26 BYTE Signature. Must be either 0x27, 0x28 or
0x29 in order to be recognized by
Windows.
0x27 4 bytes Volume Serial Number. A unique number
that is created when you format the
volume.
0x2B 11 bytes Volume Label.
0x36 8 bytes System ID. Either FAT12 or FAT16,
depending on the format of the disk.

Virtual University of Pakistan 253

Das könnte Ihnen auch gefallen