summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Shawcroft <scott@tannewt.org>2019-02-03 13:41:20 -0800
committerScott Shawcroft <scott@tannewt.org>2019-02-03 13:41:20 -0800
commita393a6e0c578231123220e73adc32b8ee58db64b (patch)
tree55d5117b0db15bfbfdb99cf43ad5f91a8057fae0
parent3d0757102977bcebadfd530949a84fb224e0cfcb (diff)
Add fast seek support to file objects
-rw-r--r--extmod/vfs_fat_file.c17
-rw-r--r--lib/oofatfs/ffconf.h2
2 files changed, 18 insertions, 1 deletions
diff --git a/extmod/vfs_fat_file.c b/extmod/vfs_fat_file.c
index 75fa2fbd4..4c38a35e5 100644
--- a/extmod/vfs_fat_file.c
+++ b/extmod/vfs_fat_file.c
@@ -197,6 +197,23 @@ STATIC mp_obj_t file_open(fs_user_mount_t *vfs, const mp_obj_type_t *type, mp_ar
m_del_obj(pyb_file_obj_t, o);
mp_raise_OSError(fresult_to_errno_table[res]);
}
+ // If we're reading, turn on fast seek.
+ if (mode == FA_READ) {
+ // one call to determine how much space we need.
+ DWORD temp_table[2];
+ temp_table[0] = 2;
+ o->fp.cltbl = temp_table;
+ f_lseek(&o->fp, CREATE_LINKMAP);
+ DWORD size = (temp_table[0] + 1) * 2;
+ o->fp.cltbl = m_malloc_maybe(size, false);
+ if (o->fp.cltbl != NULL) {
+ o->fp.cltbl[0] = size;
+ res = f_lseek(&o->fp, CREATE_LINKMAP);
+ if (res != FR_OK) {
+ o->fp.cltbl = NULL;
+ }
+ }
+ }
// for 'a' mode, we must begin at the end of the file
if ((mode & FA_OPEN_ALWAYS) != 0) {
diff --git a/lib/oofatfs/ffconf.h b/lib/oofatfs/ffconf.h
index 315101f0e..214311b4c 100644
--- a/lib/oofatfs/ffconf.h
+++ b/lib/oofatfs/ffconf.h
@@ -74,7 +74,7 @@
/* This option switches f_mkfs() function. (0:Disable or 1:Enable) */
-#define _USE_FASTSEEK 0
+#define _USE_FASTSEEK 1
/* This option switches fast seek function. (0:Disable or 1:Enable) */