diff options
| author | Scott Shawcroft <scott@chickadee.tech> | 2016-10-21 15:18:05 -0700 |
|---|---|---|
| committer | Scott Shawcroft <scott@chickadee.tech> | 2016-10-21 15:44:09 -0700 |
| commit | 9eb86e801547169af6914995c9cd7d10bc0c3124 (patch) | |
| tree | efeb2988a0aa75187599752ca849f75687f2b3e7 | |
| parent | eb62d03e338aec65d357336c48d8db4a451748fb (diff) | |
Add support for USB writeable, MicroPython read-only volumes.
This prevents file system corruption due to two systems mutating
it at once.
| -rw-r--r-- | atmel-samd/internal_flash.c | 2 | ||||
| -rw-r--r-- | atmel-samd/spi_flash.c | 2 | ||||
| -rw-r--r-- | extmod/fsusermount.h | 8 | ||||
| -rw-r--r-- | extmod/vfs_fat_diskio.c | 5 |
4 files changed, 11 insertions, 6 deletions
diff --git a/atmel-samd/internal_flash.c b/atmel-samd/internal_flash.c index f7d0aea6c..444c174da 100644 --- a/atmel-samd/internal_flash.c +++ b/atmel-samd/internal_flash.c @@ -278,7 +278,7 @@ const mp_obj_type_t internal_flash_type = { }; void flash_init_vfs(fs_user_mount_t *vfs) { - vfs->flags |= FSUSER_NATIVE | FSUSER_HAVE_IOCTL; + vfs->flags |= FSUSER_NATIVE | FSUSER_HAVE_IOCTL | FSUSER_USB_WRITEABLE; vfs->readblocks[0] = (mp_obj_t)&internal_flash_obj_readblocks_obj; vfs->readblocks[1] = (mp_obj_t)&internal_flash_obj; vfs->readblocks[2] = (mp_obj_t)internal_flash_read_blocks; // native version diff --git a/atmel-samd/spi_flash.c b/atmel-samd/spi_flash.c index fef630eff..812ec84e3 100644 --- a/atmel-samd/spi_flash.c +++ b/atmel-samd/spi_flash.c @@ -609,7 +609,7 @@ const mp_obj_type_t spi_flash_type = { }; void flash_init_vfs(fs_user_mount_t *vfs) { - vfs->flags |= FSUSER_NATIVE | FSUSER_HAVE_IOCTL; + vfs->flags |= FSUSER_NATIVE | FSUSER_HAVE_IOCTL | FSUSER_USB_WRITEABLE; vfs->readblocks[0] = (mp_obj_t)&spi_flash_obj_readblocks_obj; vfs->readblocks[1] = (mp_obj_t)&spi_flash_obj; vfs->readblocks[2] = (mp_obj_t)spi_flash_read_blocks; // native version 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; |
