Skip to contentSkip to conversation

fs: fat: don't call disk_write with zero sector num

PATCH In review Josh Wu 2 participants 3 messages Jul 24, 2013 – Sep 6, 2013 VFAT/FAT/msdos filesystem

lore
Share & tools
lore

Josh Wu

author
#0 lore raw

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
index fd07240..a05327c 100644
@@ -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
author
#1 lore raw

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 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.

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
index fd07240..a05327c 100644
@@ -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) {
#2 lore raw
In reply to Josh Wu
Quoted 11 lines · Josh

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.

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>