Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Cs609@vu.edu.pk
Lecture # 30
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;
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);
}
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.
0 1 1 = Boot Block
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.
Example LBA=2711676
LBA=1388B3B LBA=2711676+3F
LSN=1 No LSN LSN=0
Logical Logical
Drive Drive
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.
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.
System Area
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.
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