From cdf92aef9a0d5154ad807c65252ac7f2d5be00d6 Mon Sep 17 00:00:00 2001
From: Przemyslaw Marczak
Date: Wed, 10 Dec 2014 16:50:41 +0100
Subject: [PATCH] fat: fix fat32 read issue
After fixing the fat16 issue, the fat32 was broken.
This patch restores the previous functionality for fat32 read.
Change-Id: I08c54e77200d8abddc934499dba06ac256f770fd
Signed-off-by: Przemyslaw Marczak
---
fs/fat/fat.c | 32 ++++++++++++++++++++------------
1 file changed, 20 insertions(+), 12 deletions(-)
diff --git a/fs/fat/fat.c b/fs/fat/fat.c
index fed893f..0563bb3 100644
--- a/fs/fat/fat.c
+++ b/fs/fat/fat.c
@@ -826,6 +826,7 @@ do_fat_read_at(const char *filename, unsigned long pos, void *buffer,
__u32 root_cluster = 0;
int rootdir_size = 0;
int j, k;
+ int do_read;
__u8 *dir_ptr;
if (read_bootsectandvi(&bs, &volinfo, &mydata->fatsize)) {
@@ -915,26 +916,33 @@ do_fat_read_at(const char *filename, unsigned long pos, void *buffer,
k = 0;
while (1) {
int i;
- debug("FAT read sect=%d, clust_size=%d, DIRENTSPERBLOCK=%zd\n",
- cursect, mydata->clust_size, DIRENTSPERBLOCK);
- if (!k) {
+ if (mydata->fatsize == 32 || !k) {
dir_ptr = do_fat_read_at_block;
- k++;
+ k = 1;
} else {
dir_ptr = (do_fat_read_at_block + mydata->sect_size);
memcpy(do_fat_read_at_block, dir_ptr, mydata->sect_size);
}
- if (disk_read(cursect,
- (mydata->fatsize == 32) ?
- (mydata->clust_size) :
- PREFETCH_BLOCKS,
- dir_ptr) < 0) {
- debug("Error: reading rootdir block\n");
- goto exit;
+ do_read = 1;
+
+ if (mydata->fatsize == 32 && j)
+ do_read = 0;
+
+ if (do_read) {
+ debug("FAT read sect=%d, clust_size=%d, DIRENTSPERBLOCK=%zd\n",
+ cursect, mydata->clust_size, DIRENTSPERBLOCK);
+
+ if (disk_read(cursect,
+ (mydata->fatsize == 32) ?
+ (mydata->clust_size) : PREFETCH_BLOCKS,dir_ptr) < 0) {
+ debug("Error: reading rootdir block\n");
+ goto exit;
+ }
+
+ dentptr = (dir_entry *) dir_ptr;
}
- dentptr = (dir_entry *) dir_ptr;
for (i = 0; i < DIRENTSPERBLOCK; i++) {
char s_name[14], l_name[VFAT_MAXLEN_BYTES];
--
2.7.4