adafruit / circuitpython

CircuitPython - a Python implementation for teaching coding with microcontrollers
https://circuitpython.org
Other
4.07k stars 1.2k forks source link

Automount SD cards #8678

Open tannewt opened 10 months ago

tannewt commented 10 months ago

When a SD card is inserted into a board defined SD card port, we should automount it in CircuitPython and make it available over the CP workflow. The SPI or SDIO bus will need to be board defined so it is statically allocated.

bill88t commented 10 months ago

May I instead suggest an fstab of sorts?

settings.toml:

*insert root table items here*

[FILESYSTEMS] # Boards that can afford to spend time to search, have flash space for parsing tables. This can be made into a #ifdef
SPI = "/lib" # This would try to autodetect if an sdcard can be found on board.SPI and try to mount it to "/lib"
whateverSPI = "/mnt/test" # This would try to autodetect if an sdcard can be found on board.whateverSPI and try to mount it to "/mnt/test", if "/mnt" does not exist, this should fail with a message.

This way, future storage methods, like usb-host (or maybe years down the line emmc, sata or even nvme?) can hook into this api. The only downside this api has is that it could only work for board. objects. But I guess, like fstab, it would only be for the statically mounted filesystems.

tannewt commented 10 months ago

My idea was to automount to a predictable location. /automount/<fslabel> for example. User code can manually mount to a different path.

bill88t commented 10 months ago

Sure, that could be the default behavior, but if an fstab-like thing was made, it could pretty much mean nobody would need to manually mount stuff.

It wouldn't even be that much code to add on top of the rest. It could just be a determine_mountpoint function that calls an upgraded getenv that has minimal table support. If the key is found & can be used, it would mount it there, in any other case, /automount.