Skip to content

Commit a393a6e

Browse files
committed
Add fast seek support to file objects
1 parent 3d07571 commit a393a6e

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

extmod/vfs_fat_file.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,23 @@ STATIC mp_obj_t file_open(fs_user_mount_t *vfs, const mp_obj_type_t *type, mp_ar
197197
m_del_obj(pyb_file_obj_t, o);
198198
mp_raise_OSError(fresult_to_errno_table[res]);
199199
}
200+
// If we're reading, turn on fast seek.
201+
if (mode == FA_READ) {
202+
// one call to determine how much space we need.
203+
DWORD temp_table[2];
204+
temp_table[0] = 2;
205+
o->fp.cltbl = temp_table;
206+
f_lseek(&o->fp, CREATE_LINKMAP);
207+
DWORD size = (temp_table[0] + 1) * 2;
208+
o->fp.cltbl = m_malloc_maybe(size, false);
209+
if (o->fp.cltbl != NULL) {
210+
o->fp.cltbl[0] = size;
211+
res = f_lseek(&o->fp, CREATE_LINKMAP);
212+
if (res != FR_OK) {
213+
o->fp.cltbl = NULL;
214+
}
215+
}
216+
}
200217

201218
// for 'a' mode, we must begin at the end of the file
202219
if ((mode & FA_OPEN_ALWAYS) != 0) {

lib/oofatfs/ffconf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
/* This option switches f_mkfs() function. (0:Disable or 1:Enable) */
7575

7676

77-
#define _USE_FASTSEEK 0
77+
#define _USE_FASTSEEK 1
7878
/* This option switches fast seek function. (0:Disable or 1:Enable) */
7979

8080

0 commit comments

Comments
 (0)