[U-Boot] [PATCH v1] fat: fatwrite: fix the command for FAT12

Philipp Skadorov philipp.skadorov at savoirfairelinux.com
Fri Dec 9 19:55:37 CET 2016


The u-boot command fatwrite empties FAT clusters from the beginning
till the end of the file.
Specifically for FAT12 it fails to detect the end of the file and goes
beyond the file bounds thus corrupting the file system.

The users normally workaround this by re-formatting the partition as
FAT16/FAT32, like here:
https://github.com/FEDEVEL/openrex-uboot-v2015.10/issues/1

The patch is to check file bounds by already-existing macro that
accounts for FAT12.
The command then works correctly for all types of FAT.

Signed-off-by: Philipp Skadorov <philipp.skadorov at savoirfairelinux.com>
Cc:Donggeun Kim <dg77.kim at samsung.com>
---
 fs/fat/fat_write.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c
index 40a3860..e4f600e 100644
--- a/fs/fat/fat_write.c
+++ b/fs/fat/fat_write.c
@@ -670,16 +670,13 @@ static int clear_fatent(fsdata *mydata, __u32 entry)
 {
 	__u32 fat_val;
 
-	while (1) {
+	while (!CHECK_CLUST(entry, mydata->fatsize)) {
 		fat_val = get_fatent_value(mydata, entry);
 		if (fat_val != 0)
 			set_fatent_value(mydata, entry, 0);
 		else
 			break;
 
-		if (fat_val == 0xfffffff || fat_val == 0xffff)
-			break;
-
 		entry = fat_val;
 	}
 
-- 
2.7.4



More information about the U-Boot mailing list