Information Technology Reference
In-Depth Information
Performing Sequential Reads
The FATReadQueued function is identical to the FATread function above
except that it's optimized for doing multiple, sequential reads of the FAT.
The function reads a sector from the media only if the entry to read is the
first one in a sector. Otherwise, the function assumes that the passed DISK
structure's buffer member contains the sector with the entry to read.
word FATReadQueued( DISK *dsk, word ccls)
{
word
c;
word
d;
dword
l;
word
p;
byte
q;
// Save the passed cluster number.
p = ccls;
// Each sector holds 256 two-byte entries.
// If the LSB of the cluster number = 0, the FAT entry is in a new sector.
if ((ccls & 0xFF) == 0x00)
{
// Get the sector number.
// The LBA of the FAT sector containing the cluster's data is the FAT's starting
// address plus the high byte of the current cluster's address.
// (Each sector contains 256 two-byte entries.)
l = dsk -> fat + (p >> 8 );
// Read the sector containing the entry.
if (SectorRead( l, dsk -> buffer) != sdcValid)
return CLUSTER_FAIL;
}
// To find the number of the next cluster,
// read 2 bytes in the buffer of retrieved data
// beginning at offset = low byte of current cluster's address << 1.
// Shift left 1 (multiply by 2) because each entry is 2 bytes.
c = RAMreadW( dsk -> buffer, ((p & 0xFF) << 1));
Search WWH ::




Custom Search