summaryrefslogtreecommitdiff
path: root/firmware/common/file.c
diff options
context:
space:
mode:
authorMiika Pekkarinen <miipekk@ihme.org>2006-03-28 11:51:12 +0000
committerMiika Pekkarinen <miipekk@ihme.org>2006-03-28 11:51:12 +0000
commit2d93495df2dd0c7c61fa73e07bb8fcae3d1ea5fd (patch)
tree38d90cb0894b238b84cfa88b3e4cc3658b8a7ced /firmware/common/file.c
parent6784e0333f3d8ee806a7eacbf2b709f45ffea0f5 (diff)
downloadrockbox-2d93495df2dd0c7c61fa73e07bb8fcae3d1ea5fd.tar.gz
rockbox-2d93495df2dd0c7c61fa73e07bb8fcae3d1ea5fd.zip
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
Diffstat (limited to 'firmware/common/file.c')
-rw-r--r--firmware/common/file.c37
1 files changed, 33 insertions, 4 deletions
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)
99 } 99 }
100 file->busy = true; 100 file->busy = true;
101 101
102#ifdef HAVE_DIRCACHE
103 if (dircache_is_enabled() && !file->write)
104 {
105 const struct dircache_entry *ce;
106
107 ce = dircache_get_entry_ptr(pathname);
108 if (!ce)
109 {
110 errno = ENOENT;
111 file->busy = false;
112 return -7;
113 }
114
115 fat_open(IF_MV2(unsupported at the moment,)
116 ce->startcluster,
117 &(file->fatfile),
118 NULL);
119 file->size = ce->size;
120 file->attr = ce->attribute;
121 file->cacheoffset = -1;
122 file->fileoffset = 0;
123
124 return fd;
125 }
126#endif
127
102 strncpy(pathnamecopy,pathname,sizeof(pathnamecopy)); 128 strncpy(pathnamecopy,pathname,sizeof(pathnamecopy));
103 pathnamecopy[sizeof(pathnamecopy)-1] = 0; 129 pathnamecopy[sizeof(pathnamecopy)-1] = 0;
104 130
105 /* locate filename */ 131 /* locate filename */
106 name=strrchr(pathnamecopy+1,'/'); 132 name=strrchr(pathnamecopy+1,'/');
107 if ( name ) { 133 if ( name ) {
@@ -120,7 +146,7 @@ int open(const char* pathname, int flags)
120 file->busy = false; 146 file->busy = false;
121 return -4; 147 return -4;
122 } 148 }
123 149
124 if(name[0] == 0) { 150 if(name[0] == 0) {
125 DEBUGF("Empty file name\n"); 151 DEBUGF("Empty file name\n");
126 errno = EINVAL; 152 errno = EINVAL;
@@ -156,7 +182,7 @@ int open(const char* pathname, int flags)
156 return rc * 10 - 6; 182 return rc * 10 - 6;
157 } 183 }
158#ifdef HAVE_DIRCACHE 184#ifdef HAVE_DIRCACHE
159 dircache_add_file(pathname); 185 dircache_add_file(pathname, file->fatfile.firstcluster);
160#endif 186#endif
161 file->size = 0; 187 file->size = 0;
162 file->attr = 0; 188 file->attr = 0;
@@ -394,6 +420,9 @@ int ftruncate(int fd, off_t size)
394 } 420 }
395 421
396 file->size = size; 422 file->size = size;
423#ifdef HAVE_DIRCACHE
424 dircache_update_filesize(fd, size, file->fatfile.firstcluster);
425#endif
397 426
398 return 0; 427 return 0;
399} 428}
@@ -569,7 +598,7 @@ static int readwrite(int fd, void* buf, long count, bool write)
569 { 598 {
570 file->size = file->fileoffset; 599 file->size = file->fileoffset;
571#ifdef HAVE_DIRCACHE 600#ifdef HAVE_DIRCACHE
572 dircache_update_filesize(fd, file->size); 601 dircache_update_filesize(fd, file->size, file->fatfile.firstcluster);
573#endif 602#endif
574 } 603 }
575 604