summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2013-03-28 17:38:14 -0700
committerKeith Packard <keithp@keithp.com>2013-03-28 17:38:14 -0700
commit44e418bbecd3a3deae942803141cf115d92f29d2 (patch)
tree27a7663db6e0e29d5b28d836e0a18ad6b13d6c64 /src
parent8101e4af199a3d79bff434f788cce9f97aeac53a (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')
-rw-r--r--src/drivers/ao_fat.c24
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;
}