In Amazon, it is named "[Try and understand] How Linux works ~ Basic knowledge of OS and hardware learned through experiments and illustrations". .. It is often called a sat book because of the handle name of author Takeuchi-san.
The C code distributed by Mr. Takeuchi is here, and the code I rewrote in Rust is [here](https: //) You can find it at github.com/gyu-don/linux-in-practice).
Below is the poem.
I was interested in Linux and memory to some extent, so there wasn't much new content. However, I feel very good to read it. As it is labeled "Try and Understand," you can actually try what is written to deepen your understanding. I've heard it somehow, but I'm really glad that I was able to actually try something I hadn't actually tried.
--There is no doubt (at least for me) that Rust is easier to write than C for anything other than system call calls.
――The crate called
nix is a very nice wrapper, and you can handle it with Rust's Result type without saying" See if the return value is -1, read errno ... "(nix document)
--You could do something like make a mess of
struct and immplate
Drop so you don't forget to close the file (although this is difficult in C but can be done in C ++).
――I decided to do my best to write the parts that didn't have a rapper or didn't feel very good.
--C NUL-terminated strings are hard to make without using the heap (
CString :: new (...) looks good if heap is fine)
macro is awkward. I didn't know how to handle theBLKSSZGET
required in the sat book with the ʻioctl macro, so I used the
. --It was a hassle twice because I often wanted to refer to both the Rust docs such as nix
and the C docs. ――The handling of types is strict, and the cast was troublesome because they didn't give special attention tovoid *`.
I wanted to end it with Rust hurray, but after all, as long as the interface was originally based on C, it wouldn't be convenient if I didn't rely on the wrapper, and I felt that the wrapper wasn't perfect.
Still, I think it's really convenient to be able to handle errors with
Result, and even if you don't like the wrapper, you can make it yourself without much hassle, and it doesn't seem to be bad.