From 6ef3a0b1819d260b6c13145d4151d0a8771fe665 Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 6 Jul 2018 13:01:07 +0700 Subject: [PATCH] implement filesystem_writable_by_python() --- ports/nrf/common-hal/storage/__init__.c | 3 ++- ports/nrf/supervisor/filesystem.c | 29 +++++++++++++++---------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/ports/nrf/common-hal/storage/__init__.c b/ports/nrf/common-hal/storage/__init__.c index 18334181a8..4ff5f0dac9 100644 --- a/ports/nrf/common-hal/storage/__init__.c +++ b/ports/nrf/common-hal/storage/__init__.c @@ -35,8 +35,9 @@ extern volatile bool mp_msc_enabled; void common_hal_storage_remount(const char *mount_path, bool readonly) { - if (strcmp(mount_path, "/") != 0) + if (strcmp(mount_path, "/") != 0) { mp_raise_OSError(MP_EINVAL); + } } void common_hal_storage_erase_filesystem(void) { diff --git a/ports/nrf/supervisor/filesystem.c b/ports/nrf/supervisor/filesystem.c index 992f7bdde3..1a3165a2d7 100644 --- a/ports/nrf/supervisor/filesystem.c +++ b/ports/nrf/supervisor/filesystem.c @@ -32,23 +32,23 @@ #include "internal_flash.h" -static fs_user_mount_t _usr_mnt; -static mp_vfs_mount_t _mp_mnt; +static mp_vfs_mount_t _mp_vfs; +static fs_user_mount_t _internal_vfs; void filesystem_init(bool create_allowed) { // init the vfs object - fs_user_mount_t *usr_vfs = &_usr_mnt; - usr_vfs->flags = 0; - flash_init_vfs(usr_vfs); + fs_user_mount_t *int_vfs = &_internal_vfs; + int_vfs->flags = 0; + flash_init_vfs(int_vfs); // try to mount the flash - FRESULT res = f_mount(&usr_vfs->fatfs); + FRESULT res = f_mount(&int_vfs->fatfs); if (res == FR_NO_FILESYSTEM && create_allowed) { // no filesystem so create a fresh one uint8_t working_buf[_MAX_SS]; - res = f_mkfs(&usr_vfs->fatfs, FM_FAT | FM_SFD, 4096, working_buf, sizeof(working_buf)); + res = f_mkfs(&int_vfs->fatfs, FM_FAT | FM_SFD, 4096, working_buf, sizeof(working_buf)); // Flush the new file system to make sure its repaired immediately. flash_flush(); if (res != FR_OK) { @@ -56,20 +56,20 @@ void filesystem_init(bool create_allowed) { } // set label - f_setlabel(&usr_vfs->fatfs, "CIRCUITPY"); + f_setlabel(&int_vfs->fatfs, "CIRCUITPY"); // create lib folder - f_mkdir(&usr_vfs->fatfs, "/lib"); + f_mkdir(&int_vfs->fatfs, "/lib"); flash_flush(); } else if (res != FR_OK) { return; } - mp_vfs_mount_t *mp_vfs = &_mp_mnt; + mp_vfs_mount_t *mp_vfs = &_mp_vfs; mp_vfs->str = "/"; mp_vfs->len = 1; - mp_vfs->obj = MP_OBJ_FROM_PTR(usr_vfs); + mp_vfs->obj = MP_OBJ_FROM_PTR(int_vfs); mp_vfs->next = NULL; MP_STATE_VM(vfs_mount_table) = mp_vfs; @@ -83,6 +83,13 @@ void filesystem_flush(void) { } void filesystem_writable_by_python(bool writable) { + fs_user_mount_t *vfs = &_internal_vfs; + + if (writable) { + vfs->flags |= FSUSER_USB_WRITABLE; + } else { + vfs->flags &= ~FSUSER_USB_WRITABLE; + } } bool filesystem_present(void) {