public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] fs: fat: fix bug when write size is less than a sector size
@ 2013-07-18  8:07 Josh Wu
  2013-07-18  8:24 ` Wolfgang Denk
  0 siblings, 1 reply; 5+ messages in thread
From: Josh Wu @ 2013-07-18  8:07 UTC (permalink / raw)
  To: u-boot

Tested in at91sam9x5ek and sama5d3x-ek in mmc fat.

Signed-off-by: Josh Wu <josh.wu@atmel.com>
---
When I debugging this issue, I also find the thread talking about this:
  http://thread.gmane.org/gmane.comp.boot-loaders.u-boot/158698
But finally no patch is send for this bug. So I send this and cc all the
people in that thread. Hope it can be merged in 2013.07.

 fs/fat/fat_write.c |    8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c
index 5829adf..b7ba8ea 100644
--- a/fs/fat/fat_write.c
+++ b/fs/fat/fat_write.c
@@ -561,7 +561,7 @@ set_cluster(fsdata *mydata, __u32 clustnum, __u8 *buffer,
 	     unsigned long size)
 {
 	int idx = 0;
-	__u32 startsect;
+	__u32 startsect, nr_sectors;
 
 	if (clustnum > 0)
 		startsect = mydata->data_begin +
@@ -571,7 +571,11 @@ set_cluster(fsdata *mydata, __u32 clustnum, __u8 *buffer,
 
 	debug("clustnum: %d, startsect: %d\n", clustnum, startsect);
 
-	if (disk_write(startsect, size / mydata->sect_size, buffer) < 0) {
+	nr_sectors = size / mydata->sect_size;
+	if (nr_sectors == 0)
+		nr_sectors = 1;
+
+	if (disk_write(startsect, nr_sectors, buffer) < 0) {
 		debug("Error writing data\n");
 		return -1;
 	}
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-07-23 10:16 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-07-18  8:07 [U-Boot] [PATCH] fs: fat: fix bug when write size is less than a sector size Josh Wu
2013-07-18  8:24 ` Wolfgang Denk
2013-07-19  9:43   ` Josh Wu
2013-07-19 11:20     ` Wolfgang Denk
2013-07-23 10:16       ` Josh Wu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox