diff options
author | Björn Stenberg <bjorn@haxx.se> | 2002-05-29 11:56:42 +0000 |
---|---|---|
committer | Björn Stenberg <bjorn@haxx.se> | 2002-05-29 11:56:42 +0000 |
commit | 3ad66b95fb2623e9d38cd7454ef7e7b492b6d6e9 (patch) | |
tree | 2ec76934790ca123fdd094a173bf6cb8bd22b47d /firmware | |
parent | d2a90d2d3259cfb95d03b1868d72af74f32eb45d (diff) | |
download | rockbox-3ad66b95fb2623e9d38cd7454ef7e7b492b6d6e9.tar.gz rockbox-3ad66b95fb2623e9d38cd7454ef7e7b492b6d6e9.zip |
FAT cache now uses static memory
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@789 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/drivers/fat.c | 53 |
1 files changed, 18 insertions, 35 deletions
diff --git a/firmware/drivers/fat.c b/firmware/drivers/fat.c index 9a81107725..88d13c3eab 100644 --- a/firmware/drivers/fat.c +++ b/firmware/drivers/fat.c | |||
@@ -24,7 +24,7 @@ | |||
24 | #include <ctype.h> | 24 | #include <ctype.h> |
25 | #include <time.h> | 25 | #include <time.h> |
26 | #include <sys/timeb.h> | 26 | #include <sys/timeb.h> |
27 | 27 | #include <stdbool.h> | |
28 | #include "fat.h" | 28 | #include "fat.h" |
29 | #include "ata.h" | 29 | #include "ata.h" |
30 | #include "debug.h" | 30 | #include "debug.h" |
@@ -132,12 +132,13 @@ struct bpb fat_bpb; | |||
132 | 132 | ||
133 | struct fat_cache_entry | 133 | struct fat_cache_entry |
134 | { | 134 | { |
135 | unsigned char *ptr; | ||
136 | int secnum; | 135 | int secnum; |
137 | int dirty; | 136 | bool inuse; |
137 | bool dirty; | ||
138 | }; | 138 | }; |
139 | 139 | ||
140 | struct fat_cache_entry fat_cache[FAT_CACHE_SIZE]; | 140 | static char fat_cache_sectors[FAT_CACHE_SIZE][SECTOR_SIZE]; |
141 | static struct fat_cache_entry fat_cache[FAT_CACHE_SIZE]; | ||
141 | 142 | ||
142 | /* sectors cache for longname use */ | 143 | /* sectors cache for longname use */ |
143 | static unsigned char lastsector[SECTOR_SIZE]; | 144 | static unsigned char lastsector[SECTOR_SIZE]; |
@@ -182,16 +183,11 @@ int fat_mount(int startsector) | |||
182 | int countofclusters; | 183 | int countofclusters; |
183 | int i; | 184 | int i; |
184 | 185 | ||
185 | /* Clear the cache. Be aware! The bss section MUST have been cleared | ||
186 | at boot. Otherwise we will free() garbage pointers here */ | ||
187 | for(i = 0;i < FAT_CACHE_SIZE;i++) | 186 | for(i = 0;i < FAT_CACHE_SIZE;i++) |
188 | { | 187 | { |
189 | if(fat_cache[i].ptr) | ||
190 | { | ||
191 | free(fat_cache[i].ptr); | ||
192 | } | ||
193 | fat_cache[i].secnum = 8; /* We use a "safe" sector just in case */ | 188 | fat_cache[i].secnum = 8; /* We use a "safe" sector just in case */ |
194 | fat_cache[i].dirty = 0; | 189 | fat_cache[i].inuse = false; |
190 | fat_cache[i].dirty = false; | ||
195 | } | 191 | } |
196 | 192 | ||
197 | /* Read the sector */ | 193 | /* Read the sector */ |
@@ -329,12 +325,10 @@ static int bpb_is_sane(void) | |||
329 | static void *cache_fat_sector(int secnum) | 325 | static void *cache_fat_sector(int secnum) |
330 | { | 326 | { |
331 | int cache_index = secnum & FAT_CACHE_MASK; | 327 | int cache_index = secnum & FAT_CACHE_MASK; |
332 | unsigned char *sec; | ||
333 | |||
334 | sec = fat_cache[cache_index].ptr; | ||
335 | 328 | ||
336 | /* Delete the cache entry if it isn't the sector we want */ | 329 | /* Delete the cache entry if it isn't the sector we want */ |
337 | if(sec && fat_cache[cache_index].secnum != secnum) | 330 | if(fat_cache[cache_index].inuse && |
331 | fat_cache[cache_index].secnum != secnum) | ||
338 | { | 332 | { |
339 | #ifdef WRITE | 333 | #ifdef WRITE |
340 | /* Write back if it is dirty */ | 334 | /* Write back if it is dirty */ |
@@ -347,36 +341,25 @@ static void *cache_fat_sector(int secnum) | |||
347 | secnum); | 341 | secnum); |
348 | } | 342 | } |
349 | } | 343 | } |
350 | #endif | ||
351 | free(sec); | ||
352 | |||
353 | fat_cache[cache_index].ptr = NULL; | ||
354 | fat_cache[cache_index].secnum = 8; /* Normally an unused sector */ | 344 | fat_cache[cache_index].secnum = 8; /* Normally an unused sector */ |
355 | fat_cache[cache_index].dirty = 0; | 345 | fat_cache[cache_index].dirty = false; |
356 | sec = NULL; | 346 | #endif |
347 | fat_cache[cache_index].inuse = false; | ||
357 | } | 348 | } |
358 | 349 | ||
359 | /* Load the sector if it is not cached */ | 350 | /* Load the sector if it is not cached */ |
360 | if(!sec) | 351 | if(!fat_cache[cache_index].inuse) |
361 | { | 352 | { |
362 | sec = malloc(fat_bpb.bpb_bytspersec); | 353 | if(ata_read_sectors(secnum + fat_bpb.startsector,1, |
363 | if(!sec) | 354 | fat_cache_sectors[cache_index])) |
364 | { | ||
365 | DEBUGF( "cache_fat_sector() - Out of memory\n"); | ||
366 | return NULL; | ||
367 | } | ||
368 | if(ata_read_sectors(secnum + fat_bpb.startsector,1,sec)) | ||
369 | { | 355 | { |
370 | DEBUGF( "cache_fat_sector() - Could" | 356 | DEBUGF( "cache_fat_sector() - Could not read sector %d\n", secnum); |
371 | " not read sector %d\n", | ||
372 | secnum); | ||
373 | free(sec); | ||
374 | return NULL; | 357 | return NULL; |
375 | } | 358 | } |
376 | fat_cache[cache_index].ptr = sec; | 359 | fat_cache[cache_index].inuse = true; |
377 | fat_cache[cache_index].secnum = secnum; | 360 | fat_cache[cache_index].secnum = secnum; |
378 | } | 361 | } |
379 | return sec; | 362 | return fat_cache_sectors[cache_index]; |
380 | } | 363 | } |
381 | 364 | ||
382 | #ifdef DISK_WRITE | 365 | #ifdef DISK_WRITE |