From mboxrd@z Thu Jan 1 00:00:00 1970 From: Wolfgang Denk Date: Thu, 18 Jul 2013 10:24:45 +0200 Subject: [U-Boot] [PATCH] fs: fat: fix bug when write size is less than a sector size In-Reply-To: <1374134870-10154-1-git-send-email-josh.wu@atmel.com> References: <1374134870-10154-1-git-send-email-josh.wu@atmel.com> Message-ID: <20130718082445.2BBA0380DF1@gemini.denx.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Dear Josh Wu, In message <1374134870-10154-1-git-send-email-josh.wu@atmel.com> you wrote: > Tested in at91sam9x5ek and sama5d3x-ek in mmc fat. > > Signed-off-by: Josh Wu > --- > 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. Definitely not. This needs thurough testing before it can go mainline. > - __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; Why would this be needed? The case of a partial write is covered further down below in the code, in the "if (size % mydata->sect_size)" part... Best regards, Wolfgang Denk -- DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de I still miss my ex-wife, but my aim is getting better.