From 1a0596a2fbb68c1285ec59606d03a610ee94ca47 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Tue, 19 Feb 2019 14:45:45 -0800 Subject: 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. --- extmod/vfs_fat.h | 2 ++ extmod/vfs_fat_file.c | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'extmod') diff --git a/extmod/vfs_fat.h b/extmod/vfs_fat.h index dd5e5ffcb..08b03d0d1 100644 --- a/extmod/vfs_fat.h +++ b/extmod/vfs_fat.h @@ -38,6 +38,8 @@ #define FSUSER_NO_FILESYSTEM (0x0008) // the block device has no filesystem on it // Device is writable over USB and read-only to MicroPython. #define FSUSER_USB_WRITABLE (0x0010) +// Bit set when the above flag is checked before opening a file for write. +#define FSUSER_CONCURRENT_WRITE_PROTECTED (0x0020) typedef struct _fs_user_mount_t { mp_obj_base_t base; diff --git a/extmod/vfs_fat_file.c b/extmod/vfs_fat_file.c index 690073ce4..6aad1884c 100644 --- a/extmod/vfs_fat_file.c +++ b/extmod/vfs_fat_file.c @@ -34,6 +34,7 @@ #include "py/mperrno.h" #include "lib/oofatfs/ff.h" #include "extmod/vfs_fat.h" +#include "supervisor/filesystem.h" // this table converts from FRESULT to POSIX errno const byte fresult_to_errno_table[20] = { @@ -187,7 +188,7 @@ STATIC mp_obj_t file_open(fs_user_mount_t *vfs, const mp_obj_type_t *type, mp_ar } } assert(vfs != NULL); - if ((vfs->flags & FSUSER_USB_WRITABLE) != 0 && (mode & FA_WRITE) != 0) { + if ((mode & FA_WRITE) != 0 && !filesystem_is_writable_by_python(vfs)) { mp_raise_OSError(MP_EROFS); } -- cgit v1.2.3