mbrman
MBR Partition Management in Rust
Library Usage
A library that allows managing MBR partition tables.
Features
- Create primary partitions and logical volumes
- Delete primary partitions and logical volumes
- Automatically generate logical volume's EBR (or can be provided manually)
- If the disk geometry is set, the partition CHS addresses will be calculated automatically when writing to disk
Examples
Read all the partitions of a disk
let mut f = open
.expect;
let mbr = MBR read_from
.expect;
println!;
for in mbr.iter
Create and delete primary partitions
let mut f = open
.expect;
let mut mbr = MBR read_from
.expect;
let free_partition_number = mbr.iter.find.map
.expect;
let sectors = mbr.get_maximum_partition_size
.expect;
let starting_lba = mbr.find_optimal_place
.expect;
mbr = MBRPartitionEntry ;
mbr = empty;
// NOTE: no modification is committed to the disk until we call mbr.write_into()
Create a new partition table from an empty disk
let ss = 512; // sector size
let data = vec!;
let mut cur = new;
let mut mbr = MBR new_from
.expect;
// NOTE: commit the change to the in-memory buffer
mbr.write_into;
Add a new logical volume to the disk
let ss = 512; // sector size
let data = vec!;
let mut cur = new;
let mut mbr = MBR new_from
.expect;
mbr = MBRPartitionEntry ;
// this helper function will do all the hard work for you
// here it creates a logical volume with Linux filesystem that occupies the entire disk
// NOTE: you will lose 1 sector because it is used by the EBR
mbr.push;
// NOTE: commit the change to the in-memory buffer
mbr.write_into;
Add a new logical volume manually to the disk
This is useful only if you need to specify exactly where goes the EBR and the partition itself.
let ss = 512; // sector size
let data = vec!;
let mut cur = new;
let mut mbr = MBR new_from
.expect;
mbr = MBRPartitionEntry ;
// NOTE: mbrman won't check the consistency of the partition you have created manually
mbr.logical_partitions.push;
// NOTE: commit the change to the in-memory buffer
mbr.write_into;