fs: fat: don't call disk_write with zero sector num
PATCH 1/1 fs: fat: don't call disk_write with zero sector num
In the set_cluster() function, it will convert the buffer size to sector numbers. Then call disk_write() to write by sector.
For remaining buffer, the size is less than a sector, call disk_write() again to write them in one sector.
But if the total buffer size is less then one sector, the original code will call disk_write() with zero sector number. It is unnecessary. So this patch fix this. Now it will not call disk_write() if total buffer size is less than one sector.
--- fs/fat/fat_write.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
fs/fat/fat_write.c +5 -3
@@ -568,9 +568,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 ) { -debug ("Error writing data\n" ); -return -1 ; +if ((size / mydata->sect_size) >0 ) { +if (disk_write (startsect, size / mydata->sect_size, buffer) <0 ) { +debug ("Error writing data\n" ); +return -1 ; + } }if (size % mydata->sect_size) {
Signature · 1 line
1.7.9.5
PATCH 1/1 fs: fat: don't call disk_write with zero sector num
Hi, All
Quoted 11 lines · Josh Wu
In the
set_cluster()function, it will convert the buffer size to sector numbers. Then calldisk_write()to write by sector.
For remaining buffer, the size is less than a sector, calldisk_write()again to write them in one sector.But if the total buffer size is less then one sector, the original code will call
disk_write()with zero sector number. It is unnecessary. So this patch fix this. Now it will not calldisk_write()if total buffer size is less than one sector.Signed-off-by Josh Wu <[email protected]>
Forgot to mention that: this is the v2 patch for [PATCH] fs: fat: fix bug when write size is less than a sector size
(http://thread.gmane.org/gmane.comp.boot-loaders.u-boot/165997)
Best Regards,
Josh Wu
Quoted 23 lines
--- fs/fat/fat_write.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)fs/fat/fat_write.c +5
-3@@ -568,9 +568,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 ) { -debug ("Error writing data\n" ); -return -1 ; +if ((size / mydata->sect_size) >0 ) { +if (disk_write (startsect, size / mydata->sect_size, buffer) <0 ) { +debug ("Error writing data\n" ); +return -1 ; + } }if (size % mydata->sect_size) {
Quoted 11 lines · Josh
In the
set_cluster()function, it will convert the buffer size to sector numbers. Then calldisk_write()to write by sector.
For remaining buffer, the size is less than a sector, calldisk_write()again to write them in one sector.But if the total buffer size is less then one sector, the original code will call
disk_write()with zero sector number. It is unnecessary. So this patch fix this. Now it will not calldisk_write()if total buffer size is less than one sector.Signed-off-by Josh Wu <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20130906/64a8d9d0/attachment.pgp>