Skip to content

Conversation

@dhalbert
Copy link
Collaborator

@dhalbert dhalbert commented Sep 30, 2025


  • Ensure that a filesystem visible via USB is read-only to the host if it is read-write to CircuitPython and vice-versa.
  • Type-check storage.mount(filesystem=, ...) argument to ensure it is a VfsFat object.
    • Currently it only checks that it implements mount. But elsewhere in the code there are assumptions it is an fs_user_mount_t, which is a `VfsFat.
    • If/when we provide other filesystem types (as MicroPython does), we will relax this. I left the old validation code in as #if 0 for that reason, instead of just deleting this.
  • stop_mp() unmounts user-mounted Vfs filesystems on VM shutdown. This used to assume that the user-mounted filesystems all came last. I think that is currently the case, but made this code more robust in case they are intermixed with non-user-mounted ones. Tested on a Fruit Jam with automounted filesystems and on an nRF52840 with a user-mounted SD card.
  • Add some clarifying parentheses on a bool expression.
  • Add #define PLAT_PRINTF(...) mp_printf(&mp_plat_print, __VA_ARGS__) in circuitpy_mpconfig.h. There are similar macros elsewhere, but only in specific files. I got tired of typing &mp_plat_print. I chose the name for minimal typing for auto-completion.

@tannewt we discussed that open() was not calling filesystem_lock(), etc. I looked at adding these but it's not clear to me that the file objects are properly finalized on VM shutdown, etc., so the locks may not go back to their initial state. Given that this does not actually seem to be a problem right now, I am leaving it alone, to be fixed later when we make more objects have finalizers. This addition is the critical one for fixing the issue

 filesystem_set_writable_by_usb(vfs_fat, readonly);
 filesystem_set_concurrent_write_protection(vfs_fat, true);

@dhalbert dhalbert requested a review from tannewt September 30, 2025 16:33
Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor thing.

re: PLAT_PRINT, it's fine to add but note that LLM power complete is much better at completing it and ESP_LOG.

@dhalbert dhalbert requested a review from tannewt September 30, 2025 18:43
Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@tannewt tannewt merged commit a54ddb3 into adafruit:main Sep 30, 2025
626 checks passed
@dhalbert dhalbert deleted the usb-fs-write-prot branch October 15, 2025 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

write-locking problem with USB automount

2 participants