diff mbox series

[U-Boot,3/4] fs: fat: allocate a new cluster for rootdirectory of fat32

Message ID 20190513054927.17890-4-takahiro.akashi@linaro.org
State Superseded, archived
Delegated to: Heinrich Schuchardt
Headers show
Series fs: fat: fixes for write under root directory | expand

Commit Message

AKASHI Takahiro May 13, 2019, 5:49 a.m. UTC
Contrary to fat12/16, fat32 can have root directory at any location
and its size can be expanded.
Without this patch, root directory won't grow properly and so we will
eventually fail to add files under root directory. Please note that this
can happen even if you delete many files as deleted directory entries
are not reclaimed but just marked as "deleted" under the current
implementation.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
---
 fs/fat/fat_write.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

Comments

Heinrich Schuchardt May 14, 2019, 5:30 p.m. UTC | #1
On 5/13/19 7:49 AM, AKASHI Takahiro wrote:
> Contrary to fat12/16, fat32 can have root directory at any location
> and its size can be expanded.
> Without this patch, root directory won't grow properly and so we will
> eventually fail to add files under root directory. Please note that this
> can happen even if you delete many files as deleted directory entries
> are not reclaimed but just marked as "deleted" under the current
> implementation.
>
> Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

Tested-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
diff mbox series

Patch

diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c
index da1753d545ac..3bb9eac097eb 100644
--- a/fs/fat/fat_write.c
+++ b/fs/fat/fat_write.c
@@ -247,8 +247,11 @@  fill_dir_slot(fat_itr *itr, const char *l_name)
 		if (itr->remaining == 0)
 			flush_dir(itr);
 
+		/* allocate a cluster for more entries */
 		if (!fat_itr_next(itr))
-			if (!itr->dent && !itr->is_root && new_dir_table(itr))
+			if (!itr->dent &&
+			    (!itr->is_root || itr->fsdata->fatsize == 32) &&
+			    new_dir_table(itr))
 				return -1;
 	}
 
@@ -980,7 +983,10 @@  static dir_entry *find_directory_entry(fat_itr *itr, char *filename)
 			return itr->dent;
 	}
 
-	if (!itr->dent && !itr->is_root && new_dir_table(itr))
+	/* allocate a cluster for more entries */
+	if (!itr->dent &&
+	    (!itr->is_root || itr->fsdata->fatsize == 32) &&
+	    new_dir_table(itr))
 		/* indicate that allocating dent failed */
 		itr->dent = NULL;