diff options
| author | Keith Packard <keithp@keithp.com> | 2013-03-28 17:38:14 -0700 | 
|---|---|---|
| committer | Keith Packard <keithp@keithp.com> | 2013-03-28 17:38:14 -0700 | 
| commit | 44e418bbecd3a3deae942803141cf115d92f29d2 (patch) | |
| tree | 27a7663db6e0e29d5b28d836e0a18ad6b13d6c64 /src/drivers/ao_fat.c | |
| parent | 8101e4af199a3d79bff434f788cce9f97aeac53a (diff) | |
altos: seek forward on FAT cluster chain instead of restarting
This improves sequential file performance by taking advantage of any
previous cached cluster/offset pair and starting from there when the
cluster changes rather than starting from scratch at the begining again.
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'src/drivers/ao_fat.c')
| -rw-r--r-- | src/drivers/ao_fat.c | 24 | 
1 files changed, 12 insertions, 12 deletions
diff --git a/src/drivers/ao_fat.c b/src/drivers/ao_fat.c index 65c5ea7c..98f57d67 100644 --- a/src/drivers/ao_fat.c +++ b/src/drivers/ao_fat.c @@ -375,10 +375,20 @@ ao_fat_current_sector(void)  	sector_offset = ao_file_offset >> SECTOR_SHIFT; -	if (!ao_file_cluster) { +	if (!ao_file_cluster || ao_file_offset < ao_file_cluster_offset) { +		ao_file_cluster = ao_file_dirent.cluster; +		ao_file_cluster_offset = 0; +	} + +	if (ao_file_cluster_offset + bytes_per_cluster <= ao_file_offset) { +		uint16_t	cluster_distance; +  		cluster_offset = sector_offset / sectors_per_cluster; -		cluster = ao_fat_cluster_seek(ao_file_dirent.cluster, cluster_offset); +		cluster_distance = cluster_offset - ao_file_cluster_offset / bytes_per_cluster; + +		cluster = ao_fat_cluster_seek(ao_file_cluster, cluster_distance); +  		if (!ao_fat_cluster_valid(cluster))  			return 0xffffffff;  		ao_file_cluster = cluster; @@ -392,16 +402,6 @@ ao_fat_current_sector(void)  static void  ao_fat_set_offset(uint32_t offset)  { -	 -	if (offset == 0) { -		ao_file_cluster = ao_file_dirent.cluster; -		ao_file_cluster_offset = 0; -	} -	else if (offset < ao_file_cluster_offset || -	    ao_file_cluster_offset + bytes_per_cluster <= offset) -	{ -		ao_file_cluster = 0; -	}  	ao_file_offset = offset;  }  | 
