Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions extmod/extmod.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ set(MICROPY_SOURCE_EXTMOD
${MICROPY_EXTMOD_DIR}/vfs_fat_diskio.c
${MICROPY_EXTMOD_DIR}/vfs_fat_file.c
${MICROPY_EXTMOD_DIR}/vfs_lfs.c
${MICROPY_EXTMOD_DIR}/vfs_rom.c
${MICROPY_EXTMOD_DIR}/vfs_rom_file.c
${MICROPY_EXTMOD_DIR}/vfs_posix.c
${MICROPY_EXTMOD_DIR}/vfs_posix_file.c
${MICROPY_EXTMOD_DIR}/vfs_reader.c
Expand Down
2 changes: 2 additions & 0 deletions extmod/extmod.mk
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ SRC_EXTMOD_C += \
extmod/vfs_fat_diskio.c \
extmod/vfs_fat_file.c \
extmod/vfs_lfs.c \
extmod/vfs_rom.c \
extmod/vfs_rom_file.c \
extmod/vfs_posix.c \
extmod/vfs_posix_file.c \
extmod/vfs_reader.c \
Expand Down
4 changes: 4 additions & 0 deletions extmod/modvfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "extmod/vfs_fat.h"
#include "extmod/vfs_lfs.h"
#include "extmod/vfs_posix.h"
#include "extmod/vfs_rom.h"

#if !MICROPY_VFS
#error "MICROPY_PY_VFS requires MICROPY_VFS"
Expand All @@ -51,6 +52,9 @@ static const mp_rom_map_elem_t vfs_module_globals_table[] = {
#if MICROPY_VFS_LFS2
{ MP_ROM_QSTR(MP_QSTR_VfsLfs2), MP_ROM_PTR(&mp_type_vfs_lfs2) },
#endif
#if MICROPY_VFS_ROM
{ MP_ROM_QSTR(MP_QSTR_VfsRom), MP_ROM_PTR(&mp_type_vfs_rom) },
#endif
#if MICROPY_VFS_POSIX
{ MP_ROM_QSTR(MP_QSTR_VfsPosix), MP_ROM_PTR(&mp_type_vfs_posix) },
#endif
Expand Down
12 changes: 12 additions & 0 deletions extmod/vfs_reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,17 @@ void mp_reader_new_file(mp_reader_t *reader, qstr filename) {

const mp_stream_p_t *stream_p = mp_get_stream(file);
int errcode = 0;

#if MICROPY_VFS_ROM
// Check if the stream can be memory mapped.
mp_buffer_info_t bufinfo;
if (mp_get_buffer(file, &bufinfo, MP_BUFFER_READ)) {
mp_reader_new_mem(reader, bufinfo.buf, bufinfo.len, MP_READER_IS_ROM);
return;
}
#endif

// Determine how big the input buffer should be, if the stream requests a certain size or not.
mp_uint_t bufsize = stream_p->ioctl(file, MP_STREAM_GET_BUFFER_SIZE, 0, &errcode);
if (bufsize == MP_STREAM_ERROR || bufsize == 0) {
// bufsize == 0 is included here to support mpremote v1.21 and older where mount file ioctl
Expand All @@ -94,6 +105,7 @@ void mp_reader_new_file(mp_reader_t *reader, qstr filename) {
bufsize = MIN(MICROPY_READER_VFS_MAX_BUFFER_SIZE, MAX(MICROPY_READER_VFS_MIN_BUFFER_SIZE, bufsize));
}

// Create the reader.
mp_reader_vfs_t *rf = m_new_obj_var(mp_reader_vfs_t, buf, byte, bufsize);
rf->file = file;
rf->bufsize = bufsize;
Expand Down
Loading
Loading