connorkuehl / xv6-rust

A faithful port of the 32-bit xv6 learner's operating system to the Rust programming language
Other
17 stars 6 forks source link

mkfs.c #27

Open connorkuehl opened 6 years ago

connorkuehl commented 6 years ago

mkfs.c creates the file system for xv6 to use on a clean build.

Port this program over to Rust. It does not belong in the kernel tree, so this will be a separate binary crate (yes, you may use std :-))

If it hasn't already happened, it may be necessary to create a Cargo workspace in the project root to help organize the kernel code base, user programs, and utility programs (like mkfs).

squidboylan commented 6 years ago

I would be interested in working on this, though I might need help getting the build stuff setup so that the rust program can get all the stuff from the C header files that it needs.

connorkuehl commented 6 years ago

get all the stuff from the C header files that it needs.

Ahhh yes, I can see how that'd be tough. We have no preprocessor to include those files for us so it's hard to share those definitions for kernel and non-kernel code with Rust.

I don't know off the top of my head if we would have any meaningful way of accessing the contents of those header files in Rust. It looks like we'd need to duplicate those definitions into our Rust code (as a library crate so that the kernel can include them and the user programs like mkfs can include them).

Then, once all the file system stuff is ported and the C definitions go away we no longer have duplicated code. The mere thought of this will probably strike fear into anyone's heart, but I don't see any other way of doing this. I don't suppose it's nearly as bad considering no one is modifying the file system, so the values wouldn't change. It's just a painstaking process to make sure it's correct in both places and document that heavily.

That said, it might be best to leave the file system stuff alone for now. We'll be able to come back to this with more confidence once we have more of the work complete on the other systems, I think.

squidboylan commented 6 years ago

I was bored yesterday so I started on https://github.com/squidboylan/xv6-rust/compare/master...squidboylan:mkfs_port , the new mkfs program works but I didn't put the constants into their own crate as you suggested (and I agree that is the right way to do that). There's also a lot of unsafe and C hacks that aren't abstracted well that I want to fix. Feel free to take a look, I won't make a PR until it's cleaned up more though.