[U-Boot] Antwort: [PATCH] fs: fat: fix reading non-cluster-aligned root directory
Bernhard Messerklinger
bernhard.messerklinger at br-automation.com
Thu Nov 8 12:19:48 UTC 2018
Hi Anssi,
I tested your patch because i faced the same problem.
But I need an addition to your patch to get everything to work.
Since for fat12/16 the sect_to_clust() calculation is always a negative
value
the division through the cluster size with an odd negative value cuts the
rest.
With the next clust_to_sect() call the now even cluster number is
multiplied
by the cluster size and and the data_begin section is added. So after the
calculation without the rest the negative value is smaller and my
rootdir_sect
is higher then the actual rootdir_sect.
In my case:
clust_size = 2
rootdir_sect = 113
dara_begin = 132
sect_to_clust: 0xfffffff1 = (0x113 - 132) / 2
sect_to_clust: 114 = 132 + 0xfffffff1 * 2
Now my root_cluster is above the root dir but it should be below it (112).
I fixed this with the following patch:
---
fs/fat/fat.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/fs/fat/fat.c b/fs/fat/fat.c
index de5c7210be..695b6323b1 100644
--- a/fs/fat/fat.c
+++ b/fs/fat/fat.c
@@ -587,7 +587,9 @@ static int get_fs_info(fsdata *mydata)
mydata->rootdir_size -
(mydata->clust_size * 2);
mydata->root_cluster =
- sect_to_clust(mydata, mydata->rootdir_sect);
+ sect_to_clust(mydata, mydata->rootdir_sect -
+ (mydata->rootdir_sect %
+ mydata->clust_size));
}
mydata->fatbufnum = -1;
After patch:
sect_to_clust: 0xfffffff0 = (0x112 - 132) / 2
sect_to_clust: 112 = 132 + 0xfffffff0 * 2
Can you verify this?
If yes? Is it maybe possible to add this to your patch?
Regards,
Bernhard
More information about the U-Boot
mailing list