Only reset file->currentPostion on first creation

This commit is contained in:
Dave Murphy 2008-05-12 02:52:12 +00:00
parent 46df48ba21
commit a6dd89dbe4

View File

@ -71,11 +71,11 @@
static void _FAT_file_resetPosition (FILE_STRUCT* file) { static void _FAT_file_resetPosition (FILE_STRUCT* file) {
PARTITION* partition = file->partition; PARTITION* partition = file->partition;
file->currentPosition = 0; if ( file->currentPosition < partition->bytesPerCluster ) {
file->rwPosition.cluster = file->startCluster;
file->rwPosition.cluster = file->startCluster; file->rwPosition.sector = (file->currentPosition % partition->bytesPerCluster) / BYTES_PER_READ;
file->rwPosition.sector = 0; file->rwPosition.byte = file->currentPosition % BYTES_PER_READ;
file->rwPosition.byte = 0; }
file->appendPosition.cluster = _FAT_fat_lastCluster (partition, file->startCluster); file->appendPosition.cluster = _FAT_fat_lastCluster (partition, file->startCluster);
file->appendPosition.sector = (file->filesize % partition->bytesPerCluster) / BYTES_PER_READ; file->appendPosition.sector = (file->filesize % partition->bytesPerCluster) / BYTES_PER_READ;
@ -226,6 +226,7 @@ int _FAT_open_r (struct _reent *r, void *fileStruct, const char *path, int flags
file->dirEntryStart = dirEntry.dataStart; // Points to the start of the LFN entries of a file, or the alias for no LFN file->dirEntryStart = dirEntry.dataStart; // Points to the start of the LFN entries of a file, or the alias for no LFN
file->dirEntryEnd = dirEntry.dataEnd; file->dirEntryEnd = dirEntry.dataEnd;
file->currentPosition = 0;
_FAT_file_resetPosition (file); _FAT_file_resetPosition (file);
// Check if the end of the file is on the end of a cluster // Check if the end of the file is on the end of a cluster