Information Technology Reference
In-Depth Information
dest = dest + 1; // Increment the dest buffer offset.
seek++; // Increment the number of the byte to copy.
(temp)--; // Decrement the number of bytes remaining to copy.
}
} // End: if not end of file
} // while no error and more bytes to copy
// Save the offset within the sector.
fo->pos = pos;
// Save the offset within the file.
fo->seek = seek;
return(error);
}
Writing to a File
The FILEopen function in this chapter can prepare to write to a file.
Because storage media typically requires writing complete sectors, each write
to the media writes a sector's worth of data. To write to a portion of a sector,
firmware reads the sector's contents into a buffer, changes the data in the
desired location(s), and writes the entire buffer back to the storage media. As
Chapter 1 explained, to write to the media, a MultiMediaCard's controller
may need to erase an entire erase block that contains multiple sectors and
write the data back to the erased sectors, including the new data.
Tasks
To write to an empty file, firmware must perform the following actions
(shown in Figure 10-2):
1. Allocate a cluster in the FAT, store the cluster number in the file's direc-
tory entry, and convert the cluster number to an LBA sector number.
2. Write data to the cluster's sector(s).
3. To write more data, search the FAT for an available cluster, store the clus-
ter number in the FAT entry for the file's current cluster, store an EOC
Search WWH ::




Custom Search