Information Technology Reference
In-Depth Information
when adding an entry to a subdirectory whose cluster(s) are full. The
FILEallocate_new_cluster function can perform these tasks.
The function accepts a FILEOBJ pointer to a FILE structure, finds an avail-
able cluster, adds the cluster to the file's cluster chain in the FAT, sets the
FILE structure's ccls member to the new cluster's number, and returns a sta-
tus code. The function calls the FATfindEmptyCluster and FATwrite func-
tions from Chapter 8.
byte FILEallocate_new_cluster( FILEOBJ fo)
{
word c;
word curcls;
DISK *dsk;
// Save the FILE structure's dsk and ccls members.
dsk = fo -> dsk;
c = fo -> ccls;
// Find an empty cluster.
c = FATfindEmptyCluster(fo);
if (c == 0)
return CE_DISK_FULL;
// Mark the cluster as used and as the last one in the chain.
FATwrite( dsk, c, LAST_CLUSTER_FAT16);
// Write the cluster's number in the FAT entry for the FILE structure's ccls member.
curcls = fo -> ccls;
FATwrite( dsk, curcls, c);
// Set the FILE structure's ccls member to the new, empty cluster's number.
fo -> ccls = c;
return CE_GOOD;
}
Search WWH ::




Custom Search