Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mount point directory is not hidden when a filesystem is mounted on it #9954

Open
dhalbert opened this issue Jan 12, 2025 · 6 comments · May be fixed by #10129
Open

Mount point directory is not hidden when a filesystem is mounted on it #9954

dhalbert opened this issue Jan 12, 2025 · 6 comments · May be fixed by #10129
Assignees
Milestone

Comments

@dhalbert
Copy link
Collaborator

Noted as a result of https://forums.adafruit.com/viewtopic.php?t=215933

Adafruit CircuitPython 9.2.1-54-g26283dcb02 on 2025-01-06; Adafruit Metro ESP32S3 with ESP32S3
>>> import sdcardio,storage,board,os
>>> os.listdir()
['.fseventsd', '.metadata_never_index', '.Trashes', '.Trash-1000', 'sd', 'settings.toml', 'lib', 'boot_out.txt',  'ble_uart_echo_client.py']
>>> sdcard = sdcardio.SDCard(board.SPI(), board.SD_CS)
>>> vfs = storage.VfsFat(sdcard)
>>> storage.mount(vfs,"/sd")
>>> os.listdir()
# Now there are two 'sd` entries.
['sd', '.fseventsd', '.metadata_never_index', '.Trashes', '.Trash-1000', 'sd', 'settings.toml', 'lib', 'boot_out.txt',  'ble_uart_echo_client.py']
# But in this filesystem, there is only one.
>>> os.listdir(".")
['.fseventsd', '.metadata_never_index', '.Trashes', '.Trash-1000', 'sd', 'settings.toml', 'lib', 'boot_out.txt',  'ble_uart_echo_client.py']
>>> 
@dhalbert dhalbert added this to the Long term milestone Jan 12, 2025
@RetiredWizard
Copy link

This might be simpler to solve than the other VfsFat mount point issues, but just in case someone's digging around, I figured I'd link a couple possibly related issues #9045 and #8409

@dhalbert
Copy link
Collaborator Author

Though the extra listing is confusing, it does not seem to affect actual functionality.

@tannewt tannewt added the bug label Jan 13, 2025
@bablokb
Copy link

bablokb commented Mar 12, 2025

This problem should be solved, because of the recent PR from @tannewt (#10122). Now we have a saves-partition which is internally mounted on /saves. If you mount your CIRCUITPY-drive from the host computer, you can see the files within
/saves, you can add and delete and modify files, although the C-source code promises something different:

filesystem_set_writable_by_usb(saves, false);
.

But every change within /saves only changes the FAT on the the CIRCUITPY-drive, not on the internal mounted second partition, so the promise is true. It is creating two different truths about the /saves directory though and this will certainly confuse users.

Basically it just does not work to mount the same storage from two computers without causing problems. That is why we have network and cluster filesystems, that take care of keeping the truth.

The clean solution would probably be to expose the second partition as a read-only partition to the host and let the host do the mounting. A workaround would be to change all the filesystem-related APIs, i.e. not only read the FAT, but also filter all entries that are hidden by mounted filesystems. This won't change the user-view, but the view from within CP will at least be correct.

@jepler
Copy link
Member

jepler commented Mar 12, 2025

I didn't check but I suspect the duplicate directory listing in os.listdir() is coming from this code block in extmod/vfs.c:

389         } else {
390             // a mounted directory
391             mp_obj_tuple_t *t = MP_OBJ_TO_PTR(mp_obj_new_tuple(3, NULL));

since we've decided mount points should exist as directories in CIRCUITPY, we might just want to remove that block as a CIRCUITPY-CHANGE.

@jepler
Copy link
Member

jepler commented Mar 12, 2025

@bablokb This PR is about how the filesystem shows up in CircuitPython using functions like os.listdir. It's not about how the filesystem shows up on a host computer when mounted as a drive. The fact that the host computer will see the placeholder file in saves on the CIRCUITPY drive, instead of the real save content, would be a separate issue (and likely one without a good easy solution, sadly; but that may just be my natural pessimism showing)

@tannewt
Copy link
Member

tannewt commented Mar 12, 2025

since we've decided mount points should exist as directories in CIRCUITPY, we might just want to remove that block as a CIRCUITPY-CHANGE.

I'll look into this. I'm looking at SD card automounting again.

@tannewt tannewt self-assigned this Mar 12, 2025
@tannewt tannewt linked a pull request Mar 12, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants