-
Notifications
You must be signed in to change notification settings - Fork 23
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
Add BlockDevice trait. #59
base: master
Are you sure you want to change the base?
Conversation
Shouldn't |
I tried that but unfortunately it doesn't work, as Rust doesn't allow associated constants to be used in the types of trait methods. We can make it a trait parameter though. In practice the crates I've checked so far both use 512 byte blocks. virtio-drivers uses 512 byte blocks for VirtIO block devices (as required by the VirtIO specification), embedded-sdmmc uses 512 blocks for SD cards and FAT32. Implementing block devices with other block sizes is less useful, as they won't be able to be used with filesystem drivers which expect 512 byte blocks. (On the other hand filesystems which work with larger blocks can be implemented just fine against a device which has 512 byte blocks, as they can just read or write multiple blocks at once if needed.) |
Any further comments on this? Can it be merged? |
I'm fine with just adding |
@thejpster What do you think of the current approach of the block size being a const parameter to the trait? I think this is is a decent compromise, as the default value makes the usual case easy, while still keeping the flexibility to implement other block sizes if required. It also means that users of the trait can choose to be generic over the block size if they want to. |
I'd like to see a PR for embedded-sdmmc that uses this new trait to know for sure. I guess it's going to use Edit: the lack of a |
This should be consistent with the type used for block indices.
It's a shame to loose I think I'd also prefer to use 32 bit values for the count and the index, which lets you have 2**32 sectors, which is 2 TiB. That seems fine for almost any value of 'embedded'. |
I do definitely think we should use |
OK, so I'll accept The reason for having both those two types is the same as for having And the reason for having either of them is to stop you accidentally sticking an integer into a function argument. |
This is needed for const generics.
Done, and updated rust-embedded-community/embedded-sdmmc-rs#162 to match. |
Looking good. Please can we put the arguments the other way around, like they were in embedded-sdmmc? Just to reduce the diff. Also - should we require that BlockDevice::Error: Debug? It would reduce a bunch of trait bounds needed by anyone who wants to be able to print or unwrap the error. Maybe optionally require defmt::Format too? |
I've swapped the order of parameters. I'd rather not constrain the error type in the trait, as I've seen a fair few embedded driver crates whose error types don't implement |
What about devices, such as SPI where these parameters are probed. I would argue that none of the parameters should be associated constants. |
Wait, what SPI device requires you to probe for the sector size? This is an abstraction for hard disks, floppy disks, SD Cards and NVMe devices, and all use either 512 bytes or maybe sometimes 4096 bytes as the sector size - and on an embedded system you will know in advance which one you want to deal with. |
@MabezDev points out that https://docs.rs/block-device-driver/0.2.0/block_device_driver/trait.BlockDevice.html exists (it's an async version of basically this trait). We should either bring the async version over here, or we should scrap this and send a sync version over there. It doesn't seem to make sense to have the two versions in two different crates. |
Fixes #56.