Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
16 changes: 12 additions & 4 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,14 +211,22 @@ static void start_mp(safe_mode_t safe_mode) {

static void stop_mp(void) {
#if MICROPY_VFS
mp_vfs_mount_t *vfs = MP_STATE_VM(vfs_mount_table);

// Unmount all heap allocated vfs mounts.
while (gc_ptr_on_heap(vfs)) {
mp_vfs_mount_t *vfs = MP_STATE_VM(vfs_mount_table);
do {
if (gc_ptr_on_heap(vfs)) {
// mp_vfs_umount will splice out an unmounted vfs from the vfs_mount_table linked list.
mp_vfs_umount(vfs->obj);
// Start over at the beginning of the list since the first entry may have been removed.
vfs = MP_STATE_VM(vfs_mount_table);
continue;
}
vfs = vfs->next;
}
MP_STATE_VM(vfs_mount_table) = vfs;
} while (vfs != NULL);

// The last vfs is CIRCUITPY and the root directory.
vfs = MP_STATE_VM(vfs_mount_table);
while (vfs->next != NULL) {
vfs = vfs->next;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ EXTERNAL_FLASH_DEVICES = "W25Q32JVxQ"
LONGINT_IMPL = MPZ

CIRCUITPY_CODEOP = 0
CIRCUITPY_JPEGIO = 0
CIRCUITPY_ERRNO = 0
CIRCUITPY_RAINBOWIO = 0
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ EXTERNAL_FLASH_DEVICES = "S25FL216K, GD25Q16C, W25Q16JVxQ"
LONGINT_IMPL = MPZ

CIRCUITPY_CODEOP = 0
CIRCUITPY_ERRNO = 0
CIRCUITPY_RAINBOWIO = 0
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ EXTERNAL_FLASH_DEVICES = "S25FL064L"
LONGINT_IMPL = MPZ

CIRCUITPY_CODEOP = 0
CIRCUITPY_ERRNO = 0
CIRCUITPY_RAINBOWIO = 0
1 change: 1 addition & 0 deletions ports/atmel-samd/boards/feather_m4_can/mpconfigboard.mk
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ CIRCUITPY_FLOPPYIO = 0
CIRCUITPY_GIFIO = 0
CIRCUITPY_I2CTARGET = 0
CIRCUITPY_JPEGIO = 0
CIRCUITPY_PS2IO = 0
CIRCUITPY_SYNTHIO = 0

CIRCUITPY_LTO_PARTITION = one
Expand Down
3 changes: 3 additions & 0 deletions py/circuitpy_mpconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,9 @@ typedef long mp_off_t;
#endif


// For easy debugging printf's.
#define PLAT_PRINTF(...) mp_printf(&mp_plat_print, __VA_ARGS__)

#if MICROPY_PY_ASYNC_AWAIT && !CIRCUITPY_TRACEBACK
#error CIRCUITPY_ASYNCIO requires CIRCUITPY_TRACEBACK
#endif
Expand Down
10 changes: 9 additions & 1 deletion shared-bindings/storage/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,23 @@ static mp_obj_t storage_mount(size_t n_args, const mp_obj_t *pos_args, mp_map_t
// get the mount point
const char *mnt_str = mp_obj_str_get_str(args[ARG_mount_path].u_obj);


mp_obj_t vfs_obj = args[ARG_filesystem].u_obj;

// Currently, the only supported filesystem is VfsFat.
mp_arg_validate_type(vfs_obj, &mp_fat_vfs_type, MP_QSTR_filesystem);

// Add this back if/when we start supporting other filesystems.
#if 0
// Make sure we're given an object we can mount.
// TODO(tannewt): Make sure we have all the methods we need to operating it
// as a file system.
mp_obj_t vfs_obj = args[ARG_filesystem].u_obj;
mp_obj_t dest[2];
mp_load_method_maybe(vfs_obj, MP_QSTR_mount, dest);
if (dest[0] == MP_OBJ_NULL) {
mp_raise_ValueError(MP_ERROR_TEXT("filesystem must provide mount method"));
}
#endif

common_hal_storage_mount(vfs_obj, mnt_str, args[ARG_readonly].u_bool);

Expand Down
5 changes: 5 additions & 0 deletions shared-module/storage/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ void common_hal_storage_mount(mp_obj_t vfs_obj, const char *mount_path, bool rea
// call the underlying object to do any mounting operation
mp_vfs_proxy_call(vfs, MP_QSTR_mount, 2, (mp_obj_t *)&args);

fs_user_mount_t *vfs_fat = MP_OBJ_TO_PTR(vfs_obj);
// Filesystem is read-only to USB if writable by CircuitPython, and vice versa.
filesystem_set_writable_by_usb(vfs_fat, readonly);
filesystem_set_concurrent_write_protection(vfs_fat, true);

// Insert the vfs into the mount table by pushing it onto the front of the
// mount table.
mp_vfs_mount_t **vfsp = &MP_STATE_VM(vfs_mount_table);
Expand Down
8 changes: 4 additions & 4 deletions supervisor/shared/filesystem.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,13 @@ void filesystem_set_writable_by_usb(fs_user_mount_t *vfs, bool usb_writable) {
}

bool filesystem_is_writable_by_python(fs_user_mount_t *vfs) {
return (vfs->blockdev.flags & MP_BLOCKDEV_FLAG_CONCURRENT_WRITE_PROTECTED) == 0 ||
(vfs->blockdev.flags & MP_BLOCKDEV_FLAG_USB_WRITABLE) == 0;
return ((vfs->blockdev.flags & MP_BLOCKDEV_FLAG_CONCURRENT_WRITE_PROTECTED) == 0) ||
((vfs->blockdev.flags & MP_BLOCKDEV_FLAG_USB_WRITABLE) == 0);
}

bool filesystem_is_writable_by_usb(fs_user_mount_t *vfs) {
return (vfs->blockdev.flags & MP_BLOCKDEV_FLAG_CONCURRENT_WRITE_PROTECTED) == 0 ||
(vfs->blockdev.flags & MP_BLOCKDEV_FLAG_USB_WRITABLE) != 0;
return ((vfs->blockdev.flags & MP_BLOCKDEV_FLAG_CONCURRENT_WRITE_PROTECTED) == 0) ||
((vfs->blockdev.flags & MP_BLOCKDEV_FLAG_USB_WRITABLE) != 0);
}

void filesystem_set_internal_concurrent_write_protection(bool concurrent_write_protection) {
Expand Down