From b7dcf2ce33e9c08068a07c4b10c8745c2e032006 Mon Sep 17 00:00:00 2001 From: Dave Murphy Date: Wed, 7 Oct 2009 19:48:51 +0000 Subject: [PATCH] fix cluster over allocation, skip cluster alignment write if already aligned --- source/fatfile.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/source/fatfile.c b/source/fatfile.c index 66cfe09..80220da 100644 --- a/source/fatfile.c +++ b/source/fatfile.c @@ -36,7 +36,6 @@ #include #include #include -#include #include "cache.h" #include "file_allocation_table.h" @@ -728,7 +727,7 @@ ssize_t _FAT_write_r (struct _reent *r, int fd, const char *ptr, size_t len) { tempVar = remain / BYTES_PER_READ; } - if ((tempVar > 0) && flagNoError) { + if ((tempVar > 0 && tempVar < partition->sectorsPerCluster) && flagNoError) { if (!_FAT_cache_writeSectors (cache, _FAT_fat_clusterToSector (partition, position.cluster) + position.sector, tempVar, ptr)) { @@ -741,6 +740,7 @@ ssize_t _FAT_write_r (struct _reent *r, int fd, const char *ptr, size_t len) { } } + if ((position.sector >= partition->sectorsPerCluster) && flagNoError && (remain > 0)) { position.sector = 0; tempNextCluster = _FAT_fat_nextCluster(partition, position.cluster); @@ -757,11 +757,12 @@ ssize_t _FAT_write_r (struct _reent *r, int fd, const char *ptr, size_t len) { } } + size_t chunkSize = partition->bytesPerCluster; + // Write whole clusters while ((remain >= partition->bytesPerCluster) && flagNoError) { uint32_t chunkEnd; uint32_t nextChunkStart = position.cluster; - size_t chunkSize = 0; do { chunkEnd = nextChunkStart;