
Single 64KB get_contents_vfatname_block global variable would be used for all FAT implementation instead of allocating additional two global variables which are get_denfromdir_block and do_fat_read_at_block. This implementation can help in saving up 128KB memory space.
Signed-off-by: Tien Fong Chee tfchee@altera.com --- Changes for V2: - Renaming all references to get_dentfromdir_block and removing redundant Cc: Dinh Nguyen dinguyen@opensource.altera.com Cc: Dinh Nguyen dinh.linux@gmail.com Cc: ChinLiang clsee@altera.com Cc: Vagrant Cascadian vagrant@debian.org Cc: Simon Glass sjg@chromium.org Cc: Stephen Warren swarren@nvidia.com Cc: Benoît Thébaudeau benoit@wsystem.com --- fs/fat/fat.c | 23 +++++++++-------------- fs/fat/fat_write.c | 20 ++++++-------------- 2 files changed, 15 insertions(+), 28 deletions(-)
diff --git a/fs/fat/fat.c b/fs/fat/fat.c index 826bd85..7f42af7 100644 --- a/fs/fat/fat.c +++ b/fs/fat/fat.c @@ -327,7 +327,7 @@ get_cluster(fsdata *mydata, __u32 clustnum, __u8 *buffer, unsigned long size) * into 'buffer'. * Update the number of bytes read in *gotsize or return -1 on fatal errors. */ -__u8 get_contents_vfatname_block[MAX_CLUSTSIZE] +__u8 get_dentfromdir_block[MAX_CLUSTSIZE] __aligned(ARCH_DMA_MINALIGN);
static int get_contents(fsdata *mydata, dir_entry *dentptr, loff_t pos, @@ -373,14 +373,14 @@ static int get_contents(fsdata *mydata, dir_entry *dentptr, loff_t pos, /* align to beginning of next cluster if any */ if (pos) { actsize = min(filesize, (loff_t)bytesperclust); - if (get_cluster(mydata, curclust, get_contents_vfatname_block, + if (get_cluster(mydata, curclust, get_dentfromdir_block, (int)actsize) != 0) { printf("Error reading cluster\n"); return -1; } filesize -= actsize; actsize -= pos; - memcpy(buffer, get_contents_vfatname_block + pos, actsize); + memcpy(buffer, get_dentfromdir_block + pos, actsize); *gotsize += actsize; if (!filesize) return 0; @@ -515,13 +515,13 @@ get_vfatname(fsdata *mydata, int curclust, __u8 *cluster, return -1; }
- if (get_cluster(mydata, curclust, get_contents_vfatname_block, + if (get_cluster(mydata, curclust, get_dentfromdir_block, mydata->clust_size * mydata->sect_size) != 0) { debug("Error: reading directory block\n"); return -1; }
- slotptr2 = (dir_slot *)get_contents_vfatname_block; + slotptr2 = (dir_slot *)get_dentfromdir_block; while (counter > 0) { if (((slotptr2->id & ~LAST_LONG_ENTRY_MASK) & 0xff) != counter) @@ -532,7 +532,7 @@ get_vfatname(fsdata *mydata, int curclust, __u8 *cluster,
/* Save the real directory entry */ realdent = (dir_entry *)slotptr2; - while ((__u8 *)slotptr2 > get_contents_vfatname_block) { + while ((__u8 *)slotptr2 > get_dentfromdir_block) { slotptr2--; slot2str(slotptr2, l_name, &idx); } @@ -579,8 +579,6 @@ static __u8 mkcksum(const char name[8], const char ext[3]) * Get the directory entry associated with 'filename' from the directory * starting at 'startsect' */ -__u8 get_dentfromdir_block[MAX_CLUSTSIZE] - __aligned(ARCH_DMA_MINALIGN);
static dir_entry *get_dentfromdir(fsdata *mydata, int startsect, char *filename, dir_entry *retdent, @@ -811,9 +809,6 @@ exit: return ret; }
-__u8 do_fat_read_at_block[MAX_CLUSTSIZE] - __aligned(ARCH_DMA_MINALIGN); - int do_fat_read_at(const char *filename, loff_t pos, void *buffer, loff_t maxsize, int dols, int dogetsize, loff_t *size) { @@ -927,7 +922,7 @@ root_reparse: int i;
if (mydata->fatsize == 32 || firsttime) { - dir_ptr = do_fat_read_at_block; + dir_ptr = get_dentfromdir_block; firsttime = 0; } else { /** @@ -947,8 +942,8 @@ root_reparse: * 0 | sector n+1 | sector n+2 | sector n+3 | * 1 | sector n+3 | ... */ - dir_ptr = (do_fat_read_at_block + mydata->sect_size); - memcpy(do_fat_read_at_block, dir_ptr, mydata->sect_size); + dir_ptr = (get_dentfromdir_block + mydata->sect_size); + memcpy(get_dentfromdir_block, dir_ptr, mydata->sect_size); }
do_read = 1; diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c index c1d48c5..62f32bf 100644 --- a/fs/fat/fat_write.c +++ b/fs/fat/fat_write.c @@ -369,7 +369,6 @@ static __u32 dir_curclust; * a slot) into 'l_name'. If successful also copy the real directory entry * into 'retdent' * If additional adjacent cluster for directory entries is read into memory, - * then 'get_contents_vfatname_block' is copied into 'get_dentfromdir_block' and * the location of the real directory entry is returned by 'retdent' * Return 0 on success, -1 otherwise. */ @@ -384,7 +383,7 @@ get_long_file_name(fsdata *mydata, int curclust, __u8 *cluster, PREFETCH_BLOCKS : mydata->clust_size); __u8 counter = (slotptr->id & ~LAST_LONG_ENTRY_MASK) & 0xff; - int idx = 0, cur_position = 0; + int idx = 0;
if (counter > VFAT_MAXSEQ) { debug("Error: VFAT name is too long\n"); @@ -412,13 +411,13 @@ get_long_file_name(fsdata *mydata, int curclust, __u8 *cluster,
dir_curclust = curclust;
- if (get_cluster(mydata, curclust, get_contents_vfatname_block, + if (get_cluster(mydata, curclust, get_dentfromdir_block, mydata->clust_size * mydata->sect_size) != 0) { debug("Error: reading directory block\n"); return -1; }
- slotptr2 = (dir_slot *)get_contents_vfatname_block; + slotptr2 = (dir_slot *)get_dentfromdir_block; while (counter > 0) { if (((slotptr2->id & ~LAST_LONG_ENTRY_MASK) & 0xff) != counter) @@ -429,7 +428,7 @@ get_long_file_name(fsdata *mydata, int curclust, __u8 *cluster,
/* Save the real directory entry */ realdent = (dir_entry *)slotptr2; - while ((__u8 *)slotptr2 > get_contents_vfatname_block) { + while ((__u8 *)slotptr2 > get_dentfromdir_block) { slotptr2--; slot2str(slotptr2, l_name, &idx); } @@ -454,13 +453,6 @@ get_long_file_name(fsdata *mydata, int curclust, __u8 *cluster, /* Return the real directory entry */ *retdent = realdent;
- if (slotptr2) { - memcpy(get_dentfromdir_block, get_contents_vfatname_block, - mydata->clust_size * mydata->sect_size); - cur_position = (__u8 *)realdent - get_contents_vfatname_block; - *retdent = (dir_entry *) &get_dentfromdir_block[cur_position]; - } - return 0; }
@@ -1024,11 +1016,11 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size, if (disk_read(cursect, (mydata->fatsize == 32) ? (mydata->clust_size) : - PREFETCH_BLOCKS, do_fat_read_at_block) < 0) { + PREFETCH_BLOCKS, get_dentfromdir_block) < 0) { debug("Error: reading rootdir block\n"); goto exit; } - dentptr = (dir_entry *) do_fat_read_at_block; + dentptr = (dir_entry *) get_dentfromdir_block;
name_len = strlen(filename); if (name_len >= VFAT_MAXLEN_BYTES)