Download Logical Sector Number-System Programming-Lecture Notes and more Study notes System Programming in PDF only on Docsity!
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 () { 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.headsrb.sectors); temp = lbaindex % (rb.headsrb.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
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.
For fixed disk Hidden Blocks = No. of Sec/Track
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
Logical Drive
Logical Drive
LBA=1388B3B+3F
LSN = 0 First Logical Sector
LBA=0 LSN=
First Logical Block in drive LBA = 3F
LSN = 0
LSN=
LSN=
LSN=
LBA=1388B3B
No LSN
LBA=
LBA=2711676+3F
LSN=
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=
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.
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.
BPB (BIOS Parameter Block)
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.
0x0E WORD
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.
0x0D BYTE
Bytes per Sector. The size of a hardware sector. Usually 512.
0x0B WORD
Meaning Field Length
Byte Offset
Root Entries. The total number of file name entries that can be stored in the root folder of the volume.
0x11 WORD
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.
0x10 BYTE
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.
0x13 WORD
0x1A WORD Number of Heads.
0x18 WORD Sectors per Track.
Sectors per file allocation table (FAT). Number of sectors occupied by each of the file allocation tables on the volume.
0x16 WORD
Media Type. Provides information about the media being used. A value of 0xF indicates a hard disk.
0x15 BYTE
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..
0x20 DWORD
0x1C DWORD Hidden Sectors.