From 7396fe90099dcd6150b08f7ae85bd022186cb0f7 Mon Sep 17 00:00:00 2001 From: koolkdev Date: Sun, 26 Mar 2017 22:03:01 +0300 Subject: [PATCH] fat writing optimization --- ios_fs/source/fat/fat_access.c | 1 + ios_fs/source/fat/fat_access.h | 1 + ios_fs/source/fat/fat_table.c | 1 + ios_fs/source/fat/fat_write.c | 6 +++--- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/ios_fs/source/fat/fat_access.c b/ios_fs/source/fat/fat_access.c index 394fa64..1665a3d 100644 --- a/ios_fs/source/fat/fat_access.c +++ b/ios_fs/source/fat/fat_access.c @@ -131,6 +131,7 @@ int fatfs_init(struct fatfs *fs) // For FAT32 (which this may be) fs->rootdir_first_cluster = GET_32BIT_WORD(fs->currentsector.sector, BPB_FAT32_ROOTCLUS); + fs->last_free_cluster = fs->rootdir_first_cluster + 1; fs->fs_info_sector = GET_16BIT_WORD(fs->currentsector.sector, BPB_FAT32_FSINFO); // For FAT16 (which this may be), rootdir_first_cluster is actuall rootdir_first_sector diff --git a/ios_fs/source/fat/fat_access.h b/ios_fs/source/fat/fat_access.h index 1752387..de23475 100644 --- a/ios_fs/source/fat/fat_access.h +++ b/ios_fs/source/fat/fat_access.h @@ -60,6 +60,7 @@ struct fatfs uint8 sectors_per_cluster; uint32 cluster_begin_lba; uint32 rootdir_first_cluster; + uint32 last_free_cluster; uint32 rootdir_first_sector; uint32 rootdir_sectors; uint32 fat_begin_lba; diff --git a/ios_fs/source/fat/fat_table.c b/ios_fs/source/fat/fat_table.c index 6a01adf..c05dd9a 100644 --- a/ios_fs/source/fat/fat_table.c +++ b/ios_fs/source/fat/fat_table.c @@ -337,6 +337,7 @@ int fatfs_find_blank_cluster(struct fatfs *fs, uint32 start_cluster, uint32 *fre while (nextcluster != 0x0); // Found blank entry + fs->last_free_cluster = current_cluster + 1; *free_cluster = current_cluster; return 1; } diff --git a/ios_fs/source/fat/fat_write.c b/ios_fs/source/fat/fat_write.c index 620010e..cfe14d6 100644 --- a/ios_fs/source/fat/fat_write.c +++ b/ios_fs/source/fat/fat_write.c @@ -55,7 +55,7 @@ int fatfs_add_free_space(struct fatfs *fs, uint32 *startCluster, uint32 clusters for (i=0;irootdir_first_cluster, &nextcluster)) + if (fatfs_find_blank_cluster(fs, fs->last_free_cluster, &nextcluster)) { // Point last to this fatfs_fat_set_cluster(fs, start, nextcluster); @@ -103,7 +103,7 @@ int fatfs_allocate_free_space(struct fatfs *fs, int newFile, uint32 *startCluste // Allocated first link in the chain if a new file if (newFile) { - if (!fatfs_find_blank_cluster(fs, fs->rootdir_first_cluster, &nextcluster)) + if (!fatfs_find_blank_cluster(fs, fs->last_free_cluster, &nextcluster)) return 0; // If this is all that is needed then all done @@ -230,7 +230,7 @@ static int fatfs_find_free_dir_offset(struct fatfs *fs, uint32 dirCluster, int e uint32 newCluster; // Get a new cluster for directory - if (!fatfs_find_blank_cluster(fs, fs->rootdir_first_cluster, &newCluster)) + if (!fatfs_find_blank_cluster(fs, fs->last_free_cluster, &newCluster)) return 0; // Add cluster to end of directory tree