Hi and welcome! a
dd-like tool sounds like a wonderful learning program!
I’ve taken the liberty of clarifying your topic title, in the hopes of getting you more eyeballs. (Feel free to change it back if you dislike my interpretation!)
I am not aware of any low-level disk-access libraries for the rust ecosystem, but I admit that I haven’t searched for them either. The Go-To resource for crates is always the official crates.io repository. You may also like the community experimental crates.rs, which tries a lot of different ways to analyse cargo metadata and thereby improve searching and sorting.
If you only need to work on linux, you can benefit from the Unix/Linux “everything is a file” paradigm: You can then
/dev/hdX node, and do bit-copies from it, exactly as if it was a normal file.
You’ll probably want to to throw in a
BufReader with a few megabytes of buffer; otherwise you’ll be doing a separate syscall for every single byte.
(Rust favours explicitness, so contrary to most other languages, there is no buffering by default; Rust also favours composability, so this buffering implementation is usable for any
Edit 1: If you want to go above-and-beyond with the assignment, maybe have a look at compressing your output image; there are some excellent compression libraries, that already have good Rust bindings: https://crates.rs/compression
Adding them is usually fairly simple: just compose their
Write implementation on top of your output file, exactly like we did for the
BufReader, and compression is transparently added
Caveat: naive compression of uncompressible data (such as encrypted disks, or video/image files) will hurt your performance. Offloading the compression to another thread is probably worthwhile (pass your input data to the compression thread via a
std::sync::mpsc::channel, or use the faster-and-more-featureful crossbeam channels)
Edit 2: There are a lot of good libraries for command line argument parsing; clap is most famous, and provides the basis for, among others, the (more ergonomic) StructOpt. You may be more familiar with GetOpts style, and DocOpt is another great strategy that tries a different approach from
Edit 3: I only just now noticed your “general” question, “hidden” under the specific help request.
It’s completely OK to open a second topic for that; that helps both discussions focussed, instead of mixing library suggestions with waxing expositions about the general features of Rust