Information Technology Reference
In-Depth Information
Cluster Operations
In creating and writing to files, a mass-storage host must be able to allocate
clusters to files. A host might also want to erase the contents of a cluster.
The following functions show how to perform these operations.
Erasing a Cluster
Deleting a file typically just removes the directory entry and marks the file's
cluster(s) as available. The clusters may still contain data from the deleted
file. When allocating an available cluster to a new file, the host may want to
erase the cluster's contents by writing zero to each of the cluster's bytes.
The EraseCluster function accepts pointer to a DISK structure (disk) and a
cluster number to erase (cluster) and returns a status code. The function
calls the SectorWrite function from Chapter 5 and the Cluster2Sector func-
tion from Chapter 8.
byte EraseCluster(DISK *disk, word cluster)
{
byte
index;
byte
NumofSectors;
dword
SectorAddress;
// Get the LBA of the passed cluster number.
SectorAddress = Cluster2Sector(disk, cluster);
// Set the buffer's data to zeroes.
memset(disk -> buffer, 0x00, SDC_SECTOR_SIZE);
// Write the buffer's contents to the sector in the storage media.
for (index = 0; index < disk -> SecPerClus && error == CE_GOOD; index++)
{
if (SectorWrite(SectorAddress++, disk -> buffer) != sdcValid)
error = CE_WRITE_ERROR;
}
return(error);
}
Search WWH ::




Custom Search