← index #15963PR #17177
Related · high · value 1.669
QUERY · ISSUE

mpremote: Behaviour is confusing with multiple mountpoints

openby peterhinchopened 2024-10-04updated 2024-11-02
enhancementtools

Description

Follow on from https://github.com/micropython/micropython/pull/11777#issuecomment-2390338451.

To the naive user of a system with multiple mounted filesystems the behaviour of

$ mpremote cp foo.py :  

seems nondeterministic, because the destination of the copy can only be established with knowledge of the state of the target (its current directory). The same applies to

$ mpremote ls : 

The following change would provide a deterministic and more discoverable interface.

  1. Where there is only one mounted filesystem, behaviour remains exactly as currently.
  2. Where there are multiple filesystems behaviour is as follows:

mpremote ls : produces a list of mountpoints (as per ls : /).
mpremote cp foo.py : throws an exception because you cannot write to '/'.
mpremote cp foo.py :/sd/ works as at present.

While this is a breaking change, an inability to write to '/' will not surprise anyone familiar with the MP directory structure.

Code Size

No response

Implementation

I hope the MicroPython maintainers or community will implement this feature

Code of Conduct

Yes, I agree

CANDIDATE · PULL REQUEST

tools/mpremote: Improve df command to use new no-arg vfs.mount() query.

mergedby dpgeorgeopened 2025-04-24updated 2025-06-16
tools

Summary

The existing mpremote df command is not very good, because it needs to assume that all directories in the root directory are mount points, and also doesn't correctly stat filesystems when the current directory is not the root. This leads to wrong results, eg on PYBD-SF2:

$ mpremote df
mount 	size 	used 	avail 	use%
	2076672	670720	1405952	32
rom	2076672	670720	1405952	32
flash	2076672	670720	1405952	32

and on RPI_PICO2:

$ mpremote df
mount 	size 	used 	avail 	use%
	3145728	49152	3096576	1
lib	3145728	49152	3096576	1

With the introduction of vfs.mount() to return a list of mounted filesystems and their path (see #16939), we can implement a much better df, as done in this PR.

Now the above examples are:

$ mpremote df
filesystem     size     used    avail use% mounted on
<VfsRom>      66010    66010        0  100 /rom
<VfsFat>    2076672   670720  1405952   32 /flash

and

$ mpremote df
filesystem     size     used    avail use% mounted on
<VfsLfs2>   3145728    49152  3096576    1 /

Testing

Tested on PYBD_SF2 and RPI_PICO2, and also a board without any mount points (to verify that only the heading row is printed).

Also, it now works on boards without floating point because it uses // instead of / to calculate the percentage used.

Trade-offs and Alternatives

This new df wont work with MicroPython versions earlier than v1.25.0 due to the required no-arg vfs.mount() function. I'm not sure it's worth auto-detecting this feature and supporting old versions?

EDIT: the new df now works with all versions of MicroPython, falling back to os.listdir("/") when vfs.mount() doesn't work.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied