-
Notifications
You must be signed in to change notification settings - Fork 87
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
Implement ext2 reader/writer library #70
Comments
@nuta hello, I try to implement it, does it mean I need to read and write to the disk directly? |
The first step will be an ext2 reader. You should use a trait to access disks to make it portable and testable as a simple Rust application. For example , if I were to implement it, I would: #![cfg_attr(not(test), no_std)]
trait Disk {
fn read_block(&mut self, lba: usize, buf: &mut [u8]) -> Result<usize /* # of bytes actually read */, DiskError>;
fn write_block(&mut self, lba: usize, buf: &[u8]) -> Result<usize /* # of bytes actually written */, DiskError>;
}
struct Ext2Fs<D: Disk> {
disk: D,
}
impl<D: Disk> Ext2Fs<D> {
pub fn new(disk: D) {
Ext2Fs {
disk,
}
}
}
#[cfg(test)]
mod tests {
struct PseudoDisk;
impl Disk for PseudoDIsk {
fn read_block(...) {
let f = std::fs::File::open("testdata/ext2-test.img");
...
}
}
#[test]
fn test() {
let mut fs = Ext2Fs(PseudoDisk);
}
} |
that means i should implement the way to reader disk in no std, not just defined trait? |
You don't need to provide the implementation of a trait in no_std until you port the library into Kerla. In the library development, as shown in the code above, you can use |
IIRC, |
i get it now. thank you |
Summary
#48 (comment)
The text was updated successfully, but these errors were encountered: