summaryrefslogtreecommitdiff
path: root/supervisor/shared
diff options
context:
space:
mode:
authorScott Shawcroft <scott@tannewt.org>2019-02-19 14:45:45 -0800
committerScott Shawcroft <scott@tannewt.org>2019-02-21 10:45:41 -0800
commit1a0596a2fbb68c1285ec59606d03a610ee94ca47 (patch)
treeca91a0b4816a7703afbc98e63f22563d17e5569a /supervisor/shared
parentb1e8c4367987944c3faaad613142fec974840044 (diff)
Add option to disable the concurrent write protection
This allows writing to the filesystem from the host computer and CircuitPython by increasing the risk of filesystem corruption.
Diffstat (limited to 'supervisor/shared')
-rw-r--r--supervisor/shared/filesystem.c32
-rw-r--r--supervisor/shared/flash.c20
-rw-r--r--supervisor/shared/usb/usb_msc_flash.c4
3 files changed, 32 insertions, 24 deletions
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;