-
Notifications
You must be signed in to change notification settings - Fork 86
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
#70 implement ext2 #79
Conversation
Sorry, I accidentally uploaded the .idea folder... |
I think it's better to merge this ext2 library once it got a MVP feature like, reading a file from a pseudo disk. Could you keep working on it on this PR so I'll occasionally leave some advices? |
No problem at all, My original plan was to define the struct of ext2 first. What do I need to do in this PR? |
The Disk trait defined in this PR looks good to me so let's move forward. The next step would be creating a pseudo ext2 image by invoking |
Ok, I'm try |
Hello, @nuta . I recently referred to the ext2 implementation in linux. |
@dust1 Are you implying ext2 can store data in either of them? |
Sorry, does
|
@michalfita Maybe I can replace them with |
Yes you should distinguish big/little endian fields for compatibility. It seems a popular crate byteorder provides reader/writer interfaces to handle big/little endian fields while I don't think it's not that convenient to use. How about another byte order handling library like the following? If you prefer this over byteorder, I'll implement this ( use my_neat_byteorder_crate::{BigEndianU32, BigEndianU16};
struct MyStruct {
foo: BigEndianU32,
bar: BigEndianU16,
}
fn dump_my_struct() {
let st: MyStruct = read_my_struct();
println!("foo = {}", st.to_host());
} |
The |
@michalfita I think I know |
For clarity and avoidance of doubt them meant both endianess. @nuta Do we really need to reinvent the wheel in the light of existing solutions, even if they're not greatest? Maybe contribution upstream would help. Linux Kernel implemented absolutely everything for itself and don't have dependencies - that's astonishing achievement, but we have to look at the history of it. From software engineering perspective rewriting potentially faulty code in 2021 is shooting in the foot and increasing of the maintenance burden. ’byteorder’ crate is widely used in embedded software. |
I agree but we still sometimes need to reinvent a wheel if existing wheels are not suitable for us. Of course I'd use byteorder crate but reading structures with reader interfaces (instead of something like I don't have any strong preferences on this at all so would like @dust1 to chose the approach. By the way, it would be helpful to take a look at famous libraries dealing with endianness, for example, scroll looks interesting. |
The reason behind this is they keep numbers in their original layout and help with reading and writing buffers - moreover, from what I've read actually plenty of what they're doing can nicely optimized. You can always stick to:
Eventually, maybe simple_endian would satisfy you? |
When defining the attribute, the number type can be seen intuitively is |
@dust1 I can't guarantee because I haven't used it before but it's worth trying 😃 |
Let me try as a guinea pig |
I tried to define the structure with simple_endian, when i run
I have run
it compile fail in libs/ext2 dir.
Then I tried using byteorder. I found that I cannot specify whether the parameters are |
OK, the fix is publicly available. To used it with your crate put in [dependencies]
simple_endian = { git = "https://github.com/michalfita/simple-endian-rs", branch ="bugfix/4/fix-no_std-support-right-way", default-features = false, features = ["big_endian", "little_endian", "byte_impls", "integer_impls", "comparisons", "format"] } Warning: above line doesn't exhaust all available features, so please double check if you need anything else. I assumed we don't need floating point, but may missed something else. The issue is raised as rexlunae/simple-endian-rs#4 and fix PRed as rexlunae/simple-endian-rs#5. Looking at author's forks he's interested in OS development, so hopefully we get his attention soon. |
The problem is temporarily solved! thank you @michalfita !!! |
Hello, @nuta |
|
v2.0.0-alpha.1 is ok, i will edit my code later, thanks |
I modified the code related to serialization. and re-modified the directory structure. |
I have added the test and completed the reading of SuperBlock. Next, I plan to implement the structure of SuperBlock in memory, or should I say block cache? |
Great! Before moving forward, let's discuss the current implementation. |
libs/ext2_fs/src/layout.rs
Outdated
|
||
/// Structure of the super block | ||
/// disk layout | ||
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you end up with serde?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the serialization tool used in another rust project I am studying, and after searching, I found that the article about this tool is relatively rich.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if we can use serde for our usage as well. How do you plan to deal with endianess?
libs/ext2_fs/src/super_block.rs
Outdated
if data.len() < 2048 { | ||
return Err(FileSysError::Eof); | ||
} | ||
let super_block_data = &data[1024..2048]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you skip the first 1024 bytes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have read the entire image file in, so i read skip the boot block, it was 1024 bytes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity, how did you created a test image?
@dust1 If you committed something, adding that to Use of serde in the filesystem implementation bothers me as well. |
I just learned about |
And that's even more worrying. I'm not convinced it's the right tool for the job here. Serde is a serialiser, turns structures of data into a stream of values in particular format. That's pretty compute intensive process. |
Can we implement a simple serialization tool by ourselves? Due to my misconfiguration, I removed the simple_endian you modified before, I'm sorry. |
I'm puzzled, @dust1. Why do you insist on serialisation for filesystem implementation? For performance purpose structure in the memory shall be 1:1 with structure on the device. I don't expect ext2 to use odd number of bits anywhere, so things shouldn't be complicated on that matter. |
because in my opinion, after reading binary data through BlockDrive, they need to be deserialized into a structure. I read the existing implementation of ext2 and found that they are mapped from disk to data structure according to 1:1. But I don’t know how to implement it in rust. All I know is to serialize and deserialize it through other tools. (When I first saw Linux's operation between memory and structure, I say: wtf?!) |
So, you have to learn about data representation and packing, first in C then in Rust. That's formally part of FFI but it's important part low level and embedded programming. Sorry to be blunt, @dust1, but without these foundations you have nothing to do in the filesystem programming. I/O don't have time for serialisation and deserialisation in the kernel. |
This is exactly what I lack, there are not many courses in this area in my undergraduate studies. so I want to make up for my lack of knowledge in this area through this challenging job. Can this PR remain open for a long time. I will supplement this knowledge in my free time and try to apply it to this file system |
Serde is one of the reasons why I prefer Rust and it's indeed the best way to handle popular data formats like JSON, however, to read a binary format I believe there's a better way, for example, scroll. Since implementing file system in Rust is not that common, you'll need to find best practices on it, and that's what you're currently doing right now! @dust1, you don't need to hurry at all! Let's gradually get used to the kernel development and enjoy exploring best practices on writing OS in Rust 😃 |
thank you, using |
I find it! Rust can also achieve its purpose through pointer type conversion. Although I don’t have a deep understanding yet, this should be the best solution. |
Block replacement algorithm is similar to FIFO
@nuta Sorry it took a long time. |
@dust1 I think you're unsure what you'll do next. How about writing a design proposal (e.g. in Google Doc) first to discuss high-level design of the ext2 support? |
ok, @nuta |
@dust1 You don't need to hesitate about contributing at all! I would be happy if this becomes the chance for you to dive into the kernel development 😃 There're a lot of work towards Kerla's 1.0.0 release. If you find something interesting for you, feel free to open an issue or PR to ask more from me. By the way, talking about Kerla or operating system concepts is not waste of time for me (rather I'd like to). Please ask me anything 👍 |
Summary
it's better to merge this ext2 library once it got a MVP feature like
tasklist
...
to be continue🤔