Skip to contentSkip to conversation

fs/fat/fatwrite: Local variable as buffer to store dir_slot entries

PATCH New Tien Fong Chee 2 participants 2 messages Jul 28, 2016 – Nov 29, 2016 VFAT/FAT/msdos filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 fs/fat/fatwrite: Local variable as buffer to store dir_slot entries

fill_dir_slot use get_contents_vfatname_block as a temporary buffer for constructing a list of dir_slot entries. To save the memory and providing correct type of memory for above usage, a local buffer with accurate size declaration is introduced.

The local array size 640 is used because for long file name entry, each entry use 32 bytes, one entry can store up to 13 characters. The maximum number of entry possible is 20. So, total size is 32*20=640bytes.

---
Changes for V2
- Removed extra space
Cc: Dinh Nguyen <[email protected]>
Cc: Dinh Nguyen <[email protected]>
Cc: ChinLiang <[email protected]>
Cc: Vagrant Cascadian <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Stephen Warren <[email protected]>
Cc: Beno?t Th?baudeau <[email protected]>

---
 fs/fat/fat_write.c | 3 ++-
 include/fat.h      | 2 ++
 2 files changed, 4 insertions(+), 1 deletion(-)
fs/fat/fat_write.c +2 -1
index eb3a916..c1d48c5 100644
@@ -323,7 +323,8 @@ static void flush_dir_table(fsdata *mydata, dir_entry **dentptr);
 static void
 fill_dir_slot(fsdata *mydata, dir_entry **dentptr, const char *l_name)
 {
-	dir_slot *slotptr = (dir_slot *)get_contents_vfatname_block;
+	__u8 temp_dir_slot_buffer[MAX_LFN_SLOT * sizeof(dir_slot)];
+	dir_slot *slotptr = (dir_slot *)temp_dir_slot_buffer;
 	__u8 counter = 0, checksum;
 	int idx = 0, ret;
 	char s_name[16];
include/fat.h +2 -0
index 9d053e6..483ff7c 100644
@@ -33,6 +33,8 @@
 #define FAT16BUFSIZE	(FATBUFSIZE/2)
 #define FAT32BUFSIZE	(FATBUFSIZE/4)
 
+/* Maximum number of entry for long file name according to spec */
+#define MAX_LFN_SLOT	20
 
 /* Filesystem identifiers */
 #define FAT12_SIGN	"FAT12   "
Signature · 1 line
1.8.2.1
#1 lore raw

PATCH 1/2 fs/fat/fatwrite: Local variable as buffer to store dir_slot entries

Quoted 5 lines · Tien Fong Chee

fill_dir_slot use get_contents_vfatname_block as a temporary buffer for constructing a list of dir_slot entries. To save the memory and providing correct type of memory for above usage, a local buffer with accurate size declaration is introduced.

Quoted 7 lines

The local array size 640 is used because for long file name entry, each entry use 32 bytes, one entry can store up to 13 characters. The maximum number of entry possible is 20. So, total size is 32*20=640bytes.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20161129/b4a561d0/attachment.sig>