summaryrefslogtreecommitdiff
path: root/extmod
diff options
context:
space:
mode:
authorScott Shawcroft <scott@chickadee.tech>2016-10-21 15:18:05 -0700
committerScott Shawcroft <scott@chickadee.tech>2016-10-21 15:44:09 -0700
commit9eb86e801547169af6914995c9cd7d10bc0c3124 (patch)
treeefeb2988a0aa75187599752ca849f75687f2b3e7 /extmod
parenteb62d03e338aec65d357336c48d8db4a451748fb (diff)
Add support for USB writeable, MicroPython read-only volumes.
This prevents file system corruption due to two systems mutating it at once.
Diffstat (limited to 'extmod')
-rw-r--r--extmod/fsusermount.h8
-rw-r--r--extmod/vfs_fat_diskio.c5
2 files changed, 9 insertions, 4 deletions
diff --git a/extmod/fsusermount.h b/extmod/fsusermount.h
index 3eb54f8bd..7f2912b7f 100644
--- a/extmod/fsusermount.h
+++ b/extmod/fsusermount.h
@@ -28,9 +28,11 @@
#include "py/obj.h"
// these are the values for fs_user_mount_t.flags
-#define FSUSER_NATIVE (0x0001) // readblocks[2]/writeblocks[2] contain native func
-#define FSUSER_FREE_OBJ (0x0002) // fs_user_mount_t obj should be freed on umount
-#define FSUSER_HAVE_IOCTL (0x0004) // new protocol with ioctl
+#define FSUSER_NATIVE (0x0001) // readblocks[2]/writeblocks[2] contain native func
+#define FSUSER_FREE_OBJ (0x0002) // fs_user_mount_t obj should be freed on umount
+#define FSUSER_HAVE_IOCTL (0x0004) // new protocol with ioctl
+// Device is write-able over USB and read-only to MicroPython.
+#define FSUSER_USB_WRITEABLE (0x0008)
// constants for block protocol ioctl
#define BP_IOCTL_INIT (1)
diff --git a/extmod/vfs_fat_diskio.c b/extmod/vfs_fat_diskio.c
index 5608e0645..4d776f6b4 100644
--- a/extmod/vfs_fat_diskio.c
+++ b/extmod/vfs_fat_diskio.c
@@ -98,7 +98,10 @@ DSTATUS disk_status (
return STA_NOINIT;
}
- if (vfs->writeblocks[0] == MP_OBJ_NULL) {
+ // This is used to determine the writeability of the disk from MicroPython.
+ // So, if its USB writeable we make it read-only from MicroPython.
+ if (vfs->writeblocks[0] == MP_OBJ_NULL ||
+ (vfs->flags & FSUSER_USB_WRITEABLE) != 0) {
return STA_PROTECT;
} else {
return 0;