Information Technology Reference
In-Depth Information
Reserving an Available Cluster
The FILECreateHeadCluster function reserves an available cluster, which
the host can then allocate to a file. The function accepts a pointer to a FILE
structure (fo) and a pointer to a variable that will contain the number of a
reserved, empty cluster (cluster). The function returns a status code.
The function calls the FATfindEmptyCluster and FATwrite functions from
Chapter 8, the LoadDirAttrib function from Chapter 9, and the EraseClus-
ter function above.
CETYPE FILECreateHeadCluster(FILEOBJ fo, word *cluster)
{
word
curcls;
DISK
*disk;
// Save the FILE structure's dsk member.
disk = fo -> dsk;
// Use the FAT to find an available cluster.
*cluster = FATfindEmptyCluster(fo);
if (*cluster == 0)
error = CE_DISK_FULL;
else
{
// Mark the cluster as in use and the last one in the chain.
if (FATwrite(disk, *cluster, LAST_CLUSTER_FAT16) == FAIL)
error = CE_WRITE_ERROR;
// Erase the cluster's contents.
if (error == CE_GOOD)
{
error = EraseCluster(disk,*cluster);
}
}
return(error);
}
Search WWH ::




Custom Search