Logical Block Addressing

From OSDev Wiki
(Redirected from LBA)
Jump to navigation Jump to search

Logical Block Addressing (LBA) is a linear addressing scheme for data blocks (sectors) on data storage devices. Most modern storage devices use LBA addressing.


Uses

LBAs are used to access certain blocks on a storage medium. LBA is said to be 'linear' because accessing LBA + 1, will indeed address the data block immediately after the block at LBA.

LBAs can be stored in several different formats. Sometimes they are stored relative to the start of a partition or filesystem. They may also be stored in an absolute way (from the beginning of the storage device). LBAs are almost always dependent on the block size for the device in question. Suppose we have a hard drive with 512 bytes per sector (or bytes per block), then an LBA of 50 would specify the sector containing bytes (50 * 512) to (51 * 512 - 1).

Comparison with CHS

CHS (Cylinder Head Sector) is an older way of addressing a storage device. Devices such as floppies usually have no direct way of being accessed with LBAs. Instead, they require you to specify the cylinder, the head, and the sector you want to access individually. However, since LBAs are easy to use, it is not uncommon to provide a conversion between the two.

For example, one could convert an LBA for a floppy drive to the CHS with the following code snippet (based on Brokenthorn's Floppy tutorial, see the link below):

void ToCHS(int lba, int *head, int *track, int *sector)
{
	(*head) = (lba % (SECTORS_PER_TRACK * 2)) / SECTORS_PER_TRACK;
	(*track) = (lba / (SECTORS_PER_TRACK * 2));
	(*sector) = (lba % SECTORS_PER_TRACK + 1);
}

See Also

External