Comments (9)
So I haven't thought about this crate in a long time.
My recollection is that a function like read_data
doesn't mutate the underlying blocks on disk. So it seemed reasonable to only require &self
and allow multiple references to that block device exist in the system simulataneously.
The std::fs::File
type doesn't require an &mut Kernel
reference to operate - it all just works because the kernel handles mutability internally.
If you'd like to submit a PR that removes the RefCell and makes the user deal with &mut
refs everywhere, please do feel free - provided they are accompanied by examples that demonstrate that we haven't made the library impractical to use. Remember, the use case was "kinda do what the Arduino SdFat library does" - not writing operating systems, or making a more general purpose FAT implementation.
from embedded-sdmmc-rs.
I also looked through some of the dependents on crates.io:
The only implementor of BlockDevice
that I could find was in stm32h7xx-hal
(the rest use it only in examples), and that uses the same RefCell
hack to get around the non-mutability problem
from embedded-sdmmc-rs.
I'm working on an alternative implementation here:
https://github.com/datdenkikniet/embedded-sdmmc-rs/tree/no_more_immutable
from embedded-sdmmc-rs.
Have you looked through the closed issues? There have been related discussions in the past.
from embedded-sdmmc-rs.
I tried my best to find similar issues, and linked some of them.
However, in those issues the reasoning given is that it would be impossible/very impractical to have multiple file systems on a single block device.
I don't understand why the choice was made to make BlockDevice
take &self
, effectively forcing implementors of that trait to choose some form of synchronization primitive or runtime-borrowchecked type. Why doesn't the trait take &mut self
(since it effectively always requires that anyways. Perhaps not for reading, but it sounds rather counterintuitive to say that a write
function somehow does not require to mutate the state of the block device), and delegate decisions regarding the synchronization of accesses to the BlockDevice
to a higher layer (i.e. the MBR, file system, or even to the end user, depending on if they choose to wrap the BlockDevice
in a RefCell or not).
For an example of what I mean, see for instance here and here. Instead of forcing the user to accept the usage of a RefCell
in the SdMmcSpi
, the user gets to choose the type of of BlockDevice
that the Mbr
uses (either a plain SdMmcSpi
, or RefCell<SdMmcSpi>
if they wish to have multiple partitions open at the same time), and allows them to open multiple partitions at once if the underlying BlockDevice
supports it.
I'm trying to understand why the design choice was made (presumably because it is definitely the most straightforward: users of the library don't have to think about how it works), and why (if for any specific reason at all) changing it would be off the table.
from embedded-sdmmc-rs.
Maybe @thejpster has some further reasoning for this interface choice?
from embedded-sdmmc-rs.
Yeah, that's what I was hoping for too :)
from embedded-sdmmc-rs.
I see, thanks for the info!
I'm cooking up a little something, and can ping again here once it's more or less done, and if it seems like the API can be on a similar level of user-friendliness.
So far I've finished implementing reading files and directories, but need to figure out how to do writing and reading at some point while staying ergonomic.
from embedded-sdmmc-rs.
I never did finish my work on this, and with #79 it may not make any sense at all :)
I'm closing this for now
from embedded-sdmmc-rs.
Related Issues (20)
- File.current_offset is private to the crate and there is no tell() HOT 5
- Make File and Directory safely droppable HOT 1
- No no-std example HOT 1
- Support different codepages
- Errors with initialization with latest develop: respone 8 and 3f HOT 2
- Async support HOT 1
- Reason for MS-DOS 8.3 filename compability HOT 3
- Update dependency to heapless = "0.8" HOT 1
- In case of early ejection of SD card, allow "closing" `RawFile` handle anyway HOT 3
- How to do multi-block writes? HOT 10
- Make Directory::iterate_dir version returning an Iterator HOT 3
- should use SpiBus, not SpiDevice HOT 12
- Ensuring generic device-level reset HOT 2
- warning: field `0` is never read HOT 3
- new() without chip-select? HOT 2
- `find_data_on_disk()` panics due to attempt to subtract with overflow HOT 2
- Do a release HOT 4
- Simplify dir calcs
- Add a flush API HOT 3
- Re-add the File methods HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from embedded-sdmmc-rs.