When write a file into FAT file system, if not find the file in the root
dir sectors, it will call get_fatent_value() to get next cluster number
via lookup the FAT table.

The issue is FAT table only can find the cluster number start to 2. If
current clust is in root dir, then curclust is a negative number or 0, 1.
So get_fatenv_value() cannot get correct next cluster number.

In this case we just increase the curclust. That means return the next
cluster in root dir.

Signed-off-by: Josh Wu <josh...@atmel.com>
---
 fs/fat/fat_write.c |   11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c
index 9f5e911..e495fdc 100644
--- a/fs/fat/fat_write.c
+++ b/fs/fat/fat_write.c
@@ -881,6 +881,17 @@ static dir_entry *find_directory_entry(fsdata *mydata, int 
startsect,
                        return dentptr;
                }
 
+               if (mydata->fatsize != 32 && (int)curclust < 2 ) {
+                       /* Current clust is in root dir, set to next clust */
+                       curclust++;
+                       if ((int)curclust < 2)
+                               continue;
+
+                       /* Reach the end of root dir */
+                       empty_dentptr = dentptr;
+                       return NULL;
+               }
+
                curclust = get_fatent_value(mydata, dir_curclust);
                if ((curclust >= 0xffffff8) || (curclust >= 0xfff8)) {
                        empty_dentptr = dentptr;
-- 
1.7.9.5

_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Reply via email to