From ad1161c08338cfba44f6551910df100cdc6b1bc1 Mon Sep 17 00:00:00 2001 From: Dave Murphy Date: Mon, 12 May 2008 16:10:42 +0000 Subject: [PATCH] reset read/write position properly on first cluster allocation --- source/fatfile.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/source/fatfile.c b/source/fatfile.c index 974e44c..0227b58 100644 --- a/source/fatfile.c +++ b/source/fatfile.c @@ -56,6 +56,10 @@ 2008-05-12 - Chishm * Modified WinterMute's seek then write fix for elegance * Removed resetPosition + + 2008-05-12 - WinterMute + * Modified Chishm's elegant fix to reset the read/write positions + */ @@ -594,6 +598,12 @@ int _FAT_write_r (struct _reent *r,int fd, const char *ptr, int len) { file->appendPosition.cluster = file->startCluster; file->appendPosition.sector = 0; file->appendPosition.byte = 0; + + if ( file->currentPosition < partition->bytesPerCluster ) { + file->rwPosition.cluster = file->startCluster; + file->rwPosition.sector = (file->currentPosition % partition->bytesPerCluster) / BYTES_PER_READ; + file->rwPosition.byte = file->currentPosition % BYTES_PER_READ; + } } if (file->append) {