Information Technology Reference
In-Depth Information
Writing to the FAT
The FATwrite function accepts a pointer to a DISK structure (dsk), a cluster
number (cls), and a value to write to the FAT entry for the cluster (v). The
function gets the LBA of the sector containing the entry to write to, reads
the sector into a buffer, writes the value to the entry, and writes the sector
back to the storage media. The function calls the SectorRead and Sector-
Write functions from Chapter 5.
The function uses the RAMwrite macro to write a value (d) to the address
specified by a base address (a) plus an offset(f ):
#define RAMwrite(a, f, d) *(a + f) = d
word FATwrite(DISK *dsk, word cls, word v)
{
byte
c;
byte
i;
dword
l
dword
li;
word
p;
byte
q;
// Each entry is 2 bytes.
// To get the offset of the entry in the FAT, multiply the cluster number by 2.
p = cls * 2;
// To get the sector containing the entry, divide the entry's offset by 512 .
l = dsk -> fat + (p >> 9 );
// To get the offset within the sector, set bits 9-16 of the entry's offset to zero.
p &= 0x1ff;
// Read the sector into a buffer.
if ( SectorRead( l, dsk->buffer) != sdcValid)
return FAIL;
Search WWH ::




Custom Search