From 2d93495df2dd0c7c61fa73e07bb8fcae3d1ea5fd Mon Sep 17 00:00:00 2001 From: Miika Pekkarinen Date: Tue, 28 Mar 2006 11:51:12 +0000 Subject: Boost open() performance on platforms with dircache. Tagcache initial scanning now over 50% faster than before. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@9306 a1c6a512-1295-4272-9138-f99709370657 --- firmware/common/file.c | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) (limited to 'firmware/common/file.c') diff --git a/firmware/common/file.c b/firmware/common/file.c index 761caeee4b..a0b4296495 100644 --- a/firmware/common/file.c +++ b/firmware/common/file.c @@ -99,9 +99,35 @@ int open(const char* pathname, int flags) } file->busy = true; +#ifdef HAVE_DIRCACHE + if (dircache_is_enabled() && !file->write) + { + const struct dircache_entry *ce; + + ce = dircache_get_entry_ptr(pathname); + if (!ce) + { + errno = ENOENT; + file->busy = false; + return -7; + } + + fat_open(IF_MV2(unsupported at the moment,) + ce->startcluster, + &(file->fatfile), + NULL); + file->size = ce->size; + file->attr = ce->attribute; + file->cacheoffset = -1; + file->fileoffset = 0; + + return fd; + } +#endif + strncpy(pathnamecopy,pathname,sizeof(pathnamecopy)); pathnamecopy[sizeof(pathnamecopy)-1] = 0; - + /* locate filename */ name=strrchr(pathnamecopy+1,'/'); if ( name ) { @@ -120,7 +146,7 @@ int open(const char* pathname, int flags) file->busy = false; return -4; } - + if(name[0] == 0) { DEBUGF("Empty file name\n"); errno = EINVAL; @@ -156,7 +182,7 @@ int open(const char* pathname, int flags) return rc * 10 - 6; } #ifdef HAVE_DIRCACHE - dircache_add_file(pathname); + dircache_add_file(pathname, file->fatfile.firstcluster); #endif file->size = 0; file->attr = 0; @@ -394,6 +420,9 @@ int ftruncate(int fd, off_t size) } file->size = size; +#ifdef HAVE_DIRCACHE + dircache_update_filesize(fd, size, file->fatfile.firstcluster); +#endif return 0; } @@ -569,7 +598,7 @@ static int readwrite(int fd, void* buf, long count, bool write) { file->size = file->fileoffset; #ifdef HAVE_DIRCACHE - dircache_update_filesize(fd, file->size); + dircache_update_filesize(fd, file->size, file->fatfile.firstcluster); #endif } -- cgit v1.2.3