diff options
| author | Dan Halbert <halbert@halwitz.org> | 2019-02-21 17:15:50 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-02-21 17:15:50 -0500 |
| commit | d218069f03451e74e049b337830cbd1be7a25d8e (patch) | |
| tree | 12ea8d89c81889671baba36cd3668c0ca2536023 /supervisor | |
| parent | 3e877e0f6a05083980d5829e8fcc948a14642d58 (diff) | |
| parent | ed1ace09e971b24bc9ff88defe2e128064780824 (diff) | |
Merge pull request #1584 from tannewt/disable_concurrent_write_protection
Add option to disable the concurrent write protection
Diffstat (limited to 'supervisor')
| -rw-r--r-- | supervisor/filesystem.h | 9 | ||||
| -rw-r--r-- | supervisor/flash.h | 1 | ||||
| -rw-r--r-- | supervisor/shared/filesystem.c | 32 | ||||
| -rw-r--r-- | supervisor/shared/flash.c | 20 | ||||
| -rw-r--r-- | supervisor/shared/usb/usb_msc_flash.c | 4 | ||||
| -rw-r--r-- | supervisor/stub/filesystem.c | 8 |
6 files changed, 46 insertions, 28 deletions
diff --git a/supervisor/filesystem.h b/supervisor/filesystem.h index eb9e65c09..76f235f47 100644 --- a/supervisor/filesystem.h +++ b/supervisor/filesystem.h @@ -29,9 +29,16 @@ #include <stdbool.h> +#include "extmod/vfs_fat.h" + void filesystem_init(bool create_allowed, bool force_create); void filesystem_flush(void); -void filesystem_writable_by_python(bool writable); bool filesystem_present(void); +void filesystem_set_internal_writable_by_usb(bool usb_writable); +void filesystem_set_internal_concurrent_write_protection(bool concurrent_write_protection); +void filesystem_set_writable_by_usb(fs_user_mount_t *vfs, bool usb_writable); +void filesystem_set_concurrent_write_protection(fs_user_mount_t *vfs, bool concurrent_write_protection); +bool filesystem_is_writable_by_python(fs_user_mount_t *vfs); +bool filesystem_is_writable_by_usb(fs_user_mount_t *vfs); #endif // MICROPY_INCLUDED_SUPERVISOR_FILESYSTEM_H diff --git a/supervisor/flash.h b/supervisor/flash.h index ae6a44fd0..edf43f4b1 100644 --- a/supervisor/flash.h +++ b/supervisor/flash.h @@ -37,7 +37,6 @@ #include "supervisor/internal_flash.h" #endif -void supervisor_flash_set_usb_writable(bool usb_writable); void supervisor_flash_init(void); uint32_t supervisor_flash_get_block_size(void); uint32_t supervisor_flash_get_block_count(void); diff --git a/supervisor/shared/filesystem.c b/supervisor/shared/filesystem.c index 3382d28be..0ef978ef2 100644 --- a/supervisor/shared/filesystem.c +++ b/supervisor/shared/filesystem.c @@ -24,6 +24,8 @@ * THE SOFTWARE. */ +#include "supervisor/filesystem.h" + #include "extmod/vfs_fat.h" #include "lib/oofatfs/ff.h" #include "lib/oofatfs/diskio.h" @@ -92,16 +94,42 @@ void filesystem_flush(void) { supervisor_flash_flush(); } -void filesystem_writable_by_python(bool writable) { +void filesystem_set_internal_writable_by_usb(bool writable) { fs_user_mount_t *vfs = &_internal_vfs; - if (!writable) { + filesystem_set_writable_by_usb(vfs, writable); +} + +void filesystem_set_writable_by_usb(fs_user_mount_t *vfs, bool usb_writable) { + if (usb_writable) { vfs->flags |= FSUSER_USB_WRITABLE; } else { vfs->flags &= ~FSUSER_USB_WRITABLE; } } +bool filesystem_is_writable_by_python(fs_user_mount_t *vfs) { + return (vfs->flags & FSUSER_CONCURRENT_WRITE_PROTECTED) == 0 || + (vfs->flags & FSUSER_USB_WRITABLE) == 0; +} + +bool filesystem_is_writable_by_usb(fs_user_mount_t *vfs) { + return (vfs->flags & FSUSER_CONCURRENT_WRITE_PROTECTED) == 0 || + (vfs->flags & FSUSER_USB_WRITABLE) != 0; +} + +void filesystem_set_internal_concurrent_write_protection(bool concurrent_write_protection) { + filesystem_set_concurrent_write_protection(&_internal_vfs, concurrent_write_protection); +} + +void filesystem_set_concurrent_write_protection(fs_user_mount_t *vfs, bool concurrent_write_protection) { + if (concurrent_write_protection) { + vfs->flags |= FSUSER_CONCURRENT_WRITE_PROTECTED; + } else { + vfs->flags &= ~FSUSER_CONCURRENT_WRITE_PROTECTED; + } +} + bool filesystem_present(void) { return true; } diff --git a/supervisor/shared/flash.c b/supervisor/shared/flash.c index 8be21e5d0..6b1f24b4b 100644 --- a/supervisor/shared/flash.c +++ b/supervisor/shared/flash.c @@ -33,26 +33,6 @@ #define PART1_START_BLOCK (0x1) -void supervisor_flash_set_usb_writable(bool usb_writable) { - mp_vfs_mount_t* current_mount = MP_STATE_VM(vfs_mount_table); - for (uint8_t i = 0; current_mount != NULL; i++) { - if (i == VFS_INDEX) { - break; - } - current_mount = current_mount->next; - } - if (current_mount == NULL) { - return; - } - fs_user_mount_t *vfs = (fs_user_mount_t *) current_mount->obj; - - if (usb_writable) { - vfs->flags |= FSUSER_USB_WRITABLE; - } else { - vfs->flags &= ~FSUSER_USB_WRITABLE; - } -} - // there is a singleton Flash object const mp_obj_type_t supervisor_flash_type; STATIC const mp_obj_base_t supervisor_flash_obj = {&supervisor_flash_type}; diff --git a/supervisor/shared/usb/usb_msc_flash.c b/supervisor/shared/usb/usb_msc_flash.c index 658aab0d8..f6f0fa9c3 100644 --- a/supervisor/shared/usb/usb_msc_flash.c +++ b/supervisor/shared/usb/usb_msc_flash.c @@ -34,6 +34,7 @@ #include "lib/oofatfs/ff.h" #include "py/mpstate.h" +#include "supervisor/filesystem.h" #include "supervisor/shared/autoreload.h" #define MSC_FLASH_BLOCK_SIZE 512 @@ -148,8 +149,7 @@ bool tud_msc_is_writable_cb(uint8_t lun) { if (vfs == NULL) { return false; } - if (vfs->writeblocks[0] == MP_OBJ_NULL || - (vfs->flags & FSUSER_USB_WRITABLE) == 0) { + if (vfs->writeblocks[0] == MP_OBJ_NULL || !filesystem_is_writable_by_usb(vfs)) { return false; } return true; diff --git a/supervisor/stub/filesystem.c b/supervisor/stub/filesystem.c index 12fe9fb10..1c4a3e12d 100644 --- a/supervisor/stub/filesystem.c +++ b/supervisor/stub/filesystem.c @@ -26,13 +26,17 @@ #include "supervisor/filesystem.h" -void filesystem_init(void) { +void filesystem_init(bool create_allowed, bool force_create) { + (void) create_allowed; + (void) force_create; } void filesystem_flush(void) { } -void filesystem_writable_by_python(bool writable) { +bool filesystem_is_writable_by_python(fs_user_mount_t *vfs) { + (void) vfs; + return true; } bool filesystem_present(void) { |
