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?
Suggested enhancements for pyb.mount()
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Suggested enhancements for pyb.mount()
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
- danicampora
- Posts: 342
- Joined: Tue Sep 30, 2014 7:20 am
- Contact:
Re: Suggested enhancements for pyb.mount()
what about adding a new method or ?
Code: Select all
pyb.mkfs()
Code: Select all
os.mkfs()
Re: Suggested enhancements for pyb.mount()
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"?
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Suggested enhancements for pyb.mount()
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.
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.
Index to my micropython libraries.