diff -u -r rockbox-19370/apps/buffering.c rockbox-19370-fatpreload/apps/buffering.c --- rockbox-19370/apps/buffering.c 2008-12-09 12:28:32.000000000 -0500 +++ rockbox-19370-fatpreload/apps/buffering.c 2008-12-09 14:25:32.818300000 -0500 @@ -604,6 +604,8 @@ return true; } + file_preloadfat(h->fd, MIN( h->filerem, buffer_len - h->widx ) ); + while (h->filerem > 0) { /* max amount to copy */ diff -u -r rockbox-19370/firmware/common/file.c rockbox-19370-fatpreload/firmware/common/file.c --- rockbox-19370/firmware/common/file.c 2008-12-09 12:28:50.000000000 -0500 +++ rockbox-19370-fatpreload/firmware/common/file.c 2008-12-09 15:10:15.985800000 -0500 @@ -793,3 +793,40 @@ } #endif /* #ifdef HAVE_HOTSWAP */ +int file_preloadfat(int fd, size_t count) +{ + long sectors; + struct filedesc* file = &openfiles[fd]; + int rc=0; + + if (fd < 0 || fd > MAX_OPEN_FILES-1) { + errno = EINVAL; + return -1; + } + if ( !file->busy ) { + errno = EBADF; + return -1; + } + + LDEBUGF( "file_preloadfat(%d,%ld)\n", + fd,count); + + /* attempt to read past EOF? */ + if ((long)count > file->size - file->fileoffset) + count = file->size - file->fileoffset; + + /* any head bytes? */ + if ( file->cacheoffset != -1 ) { + int offs = file->cacheoffset; + int headbytes = MIN((long)count, SECTOR_SIZE - offs); + count -= headbytes; + } + + /* read/write whole sectors right into/from the supplied buffer */ + sectors = count / SECTOR_SIZE; + if ( sectors ) { + rc = fat_preload(&(file->fatfile), sectors); + } + + return rc; +} diff -u -r rockbox-19370/firmware/drivers/fat.c rockbox-19370-fatpreload/firmware/drivers/fat.c --- rockbox-19370/firmware/drivers/fat.c 2008-12-09 12:28:50.000000000 -0500 +++ rockbox-19370-fatpreload/firmware/drivers/fat.c 2008-12-09 15:48:34.716600000 -0500 @@ -2520,3 +2520,38 @@ return (volumevolume]; +#else + struct bpb* fat_bpb = &fat_bpbs[0]; +#endif + long cluster = file->lastcluster; + long i; + long clustercount = sectorcount / (long)fat_bpb->bpb_secperclus + + ( (sectorcount % (long)fat_bpb->bpb_secperclus > 0 ) ? 1 : 0 ); + /* char buf[80]; */ + + LDEBUGF( "fat_preload(file:%lx,count:0x%lx)\n", + file->firstcluster,sectorcount); + LDEBUGF( "fat_preload: sec=%lx numsec=%ld eof=%d\n", + sector,numsec, eof?1:0); + + if ( file->eof ) + return 0; + + for ( i=0; cluster && i < clustercount; i++ ) { + cluster = get_next_cluster(IF_MV2(fat_bpb,) cluster); + } + +#if 0 +#include "sprintf.h" + snprintf(buf, sizeof(buf), "c:%ld i:%ld cc:%ld sc:%ld", cluster, i, clustercount, sectorcount); + lcd_putsxy(1,1,buf); +#endif + + DEBUGF("Cluster numbers preloaded: %ld\n", i); + return i; +} diff -u -r rockbox-19370/firmware/export/fat.h rockbox-19370-fatpreload/firmware/export/fat.h --- rockbox-19370/firmware/export/fat.h 2008-12-09 12:28:51.000000000 -0500 +++ rockbox-19370-fatpreload/firmware/export/fat.h 2008-12-09 13:29:57.512600000 -0500 @@ -123,5 +123,6 @@ extern int fat_getnext(struct fat_dir *ent, struct fat_direntry *entry); extern unsigned int fat_get_cluster_size(IF_MV_NONVOID(int volume)); /* public for debug info screen */ extern bool fat_ismounted(int volume); +extern long fat_preload(struct fat_file *ent, long sectorcount); #endif diff -u -r rockbox-19370/firmware/include/file.h rockbox-19370-fatpreload/firmware/include/file.h --- rockbox-19370/firmware/include/file.h 2008-12-09 12:28:52.000000000 -0500 +++ rockbox-19370-fatpreload/firmware/include/file.h 2008-12-09 13:28:36.506800000 -0500 @@ -81,5 +81,6 @@ extern int ftruncate(int fd, off_t length); extern off_t filesize(int fd); extern int release_files(int volume); +extern int file_preloadfat(int fd, size_t count); #endif