Information Technology Reference
In-Depth Information
Obtaining a Cluster's Logical Block Address
A file's directory entry and FAT entries store cluster numbers. To read data
from the storage media, firmware must specify a logical block address. The
Cluster2Sector function accepts a pointer to a DISK structure and a cluster
number and returns the LBA of the cluster's first sector.
dword Cluster2Sector(DISK *dsk, word cluster)
{
dword sector;
// Data clusters 0 and 1 don't exist.
// If cluster = 0 or 1, assume it's the root directory.
if (cluster == 0 || cluster == 1)
sector = dsk -> root + cluster;
else
// The data area begins with cluster 2.
// Subtract 2 from the cluster number to get the cluster number within the data area.
// Multiply the result by the number of sectors per cluster to get the sector number
// within the data area.
// Add the number of the first sector in the data area to get the absolute sector
// number for the cluster.
sector = ((cluster - 2) * dsk -> SecPerClus) + dsk -> data;
return(sector);
}
Reading from the FAT
The FATread function accepts a pointer to a DISK structure (dsk) and a
cluster number (ccls), reads the FAT entry for that cluster, and returns the
value read, which is the number of the next cluster in the file or directory or
an EOC marker. The function calls the SectorRead function from Chapter
5.
The function uses the RAMreadW macro to read a word at the address spec-
ified by a base address (a) plus an offset(f ):
#define RAMreadW(a, f) *(word *)(a + f)
Search WWH ::




Custom Search