Suggested enhancements for pyb.mount()

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Suggested enhancements for pyb.mount()

Post by pythoncoder » Tue Jul 28, 2015 3:30 pm

There is no obvious way for a user of a block device to format it. While it's trivial for anyone developing a block device, someone using a driver written by someone else might have problems. I'd suggest a force_format argument, defaulting False and only working if mkfs is True.

Secondly, and arguably a little specialised, but for developers of block devices it would be handy to have a way of registering object methods as callbacks when someone attempts to mount or unmount a device. The mount callback would be called at the start of a mount to initialise hardware, the umount one after a mount(None ...) was complete to de-initialise it. The unmount callback would look up the correct callback using the mountpoint.

A block device could include its own mount() method to achieve this (thereby losing a little generality) but perhaps it's food for thought?
Peter Hinch
Index to my micropython libraries.

User avatar
danicampora
Posts: 342
Joined: Tue Sep 30, 2014 7:20 am
Contact:

Re: Suggested enhancements for pyb.mount()

Post by danicampora » Tue Jul 28, 2015 4:01 pm

what about adding a new method

Code: Select all

pyb.mkfs()
or

Code: Select all

os.mkfs()
?

Damien
Site Admin
Posts: 647
Joined: Mon Dec 09, 2013 5:02 pm

Re: Suggested enhancements for pyb.mount()

Post by Damien » Tue Jul 28, 2015 9:51 pm

The semantics of pyb.mount(..., mkfs=True) are that it will make a new filesystem (ie format the device) only if one does not already exist. Maybe it should be changed to *always* make a new filesystem if mkfs=True. Would this satisfy the criteria of "format"?

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Suggested enhancements for pyb.mount()

Post by pythoncoder » Thu Jul 30, 2015 4:35 am

The only issue I can see with changing the semantics is that it might break (poorly written) existing code. But I think it's the neatest solution.

To expand on my point about callbacks. It's easy for the developer of a block device to detect that an attempt is being made to mount it: on any access check that the hardware is running, and if not, start it. However I can't see a clean way of detecting that it has been unmounted (or even determining where it is mounted). There are a number of reasons why you might want to detect an unmount: to conserve power, to save internal state such as flash block erase counts, or to issue an instruction to a processor local to the hardware.

The crude solution is for the driver to provide a shutdown function and rely on the user to call it - but it would be more elegant if the driver could detect the unmount and handle it. Incidentally this isn't a practical problem in my application; I'm merely floating a thought.
Peter Hinch
Index to my micropython libraries.

Post Reply