Information Technology Reference
In-Depth Information
if (c >= LAST_CLUSTER_FAT16)
// The entry is an EOC marker.
c = LAST_CLUSTER;
return c;
}
Finding an Empty Cluster
To find an empty cluster in the FAT, firmware reads entries until finding an
entry that contains 0000h.
The FATfindEmptyCluster function accepts a FILEOBJ pointer to a FILE
structure and returns the number of an available cluster. The function starts
looking at the cluster immediately following the file structure's current clus-
ter number (ccls). If ccls is the file's final cluster and the function is looking
for a cluster to append to the file, the new cluster will be the one following
the current cluster if possible. The firmware thus avoids creating fragmented
files when not required.
#define CLUSTER_EMPTY 0x0000
#define END_CLUSTER 0xFFFE
word FATfindEmptyCluster(FILEOBJ fo)
{
word c;
word curcls;
DISK *disk;
word value = 0x0;
// Save the DISK structure and current cluster number.
disk = fo -> dsk;
c = fo -> ccls;
// Cluster 2 is the first cluster.
if (c < 2)
c = 2;
curcls = c;
Search WWH ::




Custom Search