(Moving some discussion to this repo from circuitpython/web-editor#399)
Currently, Python code does not have write access to the CIRCUITPY filesystem on a USB native device, unless the filesystem is remounted in boot.py, or storage.disable_usb_drive().
Code editors, such as Thonny, https://github.com/circuitpython/web-editor, and other browser-based editors want to do filesystem operations. They either use USB MSC, or use the REPL. For browser-based editors, the user must give permission for the browser-supplied File System Access API to use USB MSC. This is only available on Chromium-based browsers. Firefox recently added Web Serial, but it appears unlikely to implement the File System API soon. (Firefox does implement it for browser-only-private filesystems, not the user drive or external drives.)
Some ideas about how to allow an editor to initiate CIRCUITPY write access:
(Moving some discussion to this repo from circuitpython/web-editor#399)
Currently, Python code does not have write access to the CIRCUITPY filesystem on a USB native device, unless the filesystem is remounted in
boot.py, orstorage.disable_usb_drive().Code editors, such as Thonny, https://github.com/circuitpython/web-editor, and other browser-based editors want to do filesystem operations. They either use USB MSC, or use the REPL. For browser-based editors, the user must give permission for the browser-supplied File System Access API to use USB MSC. This is only available on Chromium-based browsers. Firefox recently added Web Serial, but it appears unlikely to implement the File System API soon. (Firefox does implement it for browser-only-private filesystems, not the user drive or external drives.)
Some ideas about how to allow an editor to initiate CIRCUITPY write access:
RunModethat does one of thesestorage.remount("/", readonly=False)disable_usb_drive().storage.disable_usb_drive()duringcode.py. It's too late to prevent enumeration of the USB MSC drive, but the drive could report as "Not Ready" instead. E.g.: https://community.st.com/stm32-mcus-products-25/how-can-i-temporalily-detach-reattach-the-msc-only-portion-of-a-composite-usb-msc-hid-device-from-the-device-itself-71347.This is a bit dangerous if the host is actively writing to the filesystem, but that is already the case if we force a hard reset to change modes. We could add a required argument. The implementation could also wait some length of time with no host MSC writes before reporting Not Ready, like auto-reload does.