Master boot record parsing, manipulation and binary export.
The MBR is a legacy boot sector format that was for example used on old windows systems and is still being used on raspberry pis.
I wrote this library for personal use because I was annoyed by using parted
to work with raspberry pi images, so I mainly paid attention to that usecase. This means not all the different historical MBR structures are supported (for example disk timestamps) and some niche partition type identifiers might not be implemented. Currently we implement the MBR precisely as described on the German wikipedia page. If you encounter a need for other partition types, timestamps or whatever please file an issue (or PR) and I might look into it.
I don't see why you'd ever need it but this crate supports no_std
- just disable the std
feature that's enabled by default.
```rust let raspiosimg = File::open("./raspios.img").unwrap(); let mbr = Mbr::tryfromreader(raspiosimg).unwrap(); // print it dbg!(mbr); // read out the drive signature let partuuid = format!("{:x}", u32::fromlebytes(mbr.drive_signature)); println!("PARTUUID: {}", partuuid);
// read the MBR off a raspberry pi image file let raspiosimg = File::open("./raspios.img").unwrap(); let mut mbr = Mbr::tryfromreader(raspiosimg).unwrap(); // modify the drive signature mbr.drivesignature = 0x090b3d33u32.tolebytes(); // add a new BTRFS 1024 sector big partition mbr.partitiontable.entries[2] = Some( PartInfo::tryfromlba( true, mbr.partitiontable.entries[1].unwrap().endsectorlba(), 1024, PartType::btrfs(), ) .unwrap(), ); // write the modified MBR to a new file let mut outfile = File::create("./out.img").unwrap(); let buf = <[u8; 512]>::tryfrom(&mbr).unwrap(); outfile.writeall(&buf).unwrap(); ```