gptman
Pure Rust library to read and modify GUID partition tables.
Things you can do
- Read/Write GPT from 512 and 4096 bytes sector size disks
- Create a new GPT on a disk
- Insert/delete a partition in the table
- Align partitions automatically (to sector size)
- Resize a partition
- Copy/clone a partition from one disk and insert it into another
- Change partition type
- Fix partitions order
- Change disk GUID
- Change partition name
- Change partition GUID
- Toggle legacy BIOS bootable
- Toggle no block IO protocol
- Toggle required partition flag
- Toggle attributes
- Swap partition indexes
- Copy/clone all partitions from one disk and insert it to another
- Write protective MBR
Installation
Cargo.toml:
[]
= "3"
Feature Flags
| Feature | Default | Description |
|---|---|---|
nix |
enabled | Linux-only. Uses ioctl to auto-detect sector size from a block device and to ask the kernel to re-read the partition table after writing. Disable if you are cross-compiling for Linux from a non-Linux host or if you do not need block device support. |
To disable default features:
[]
= { = "3", = false }
Usage
Reading all the partitions of a disk:
let mut f = open
.expect;
let gpt = GPTfind_from
.expect;
println!;
for in gpt.iter
Creating new partitions:
let mut f = open
.expect;
let mut gpt = GPTfind_from
.expect;
let free_partition_number = gpt.iter.find.map
.expect;
let size = gpt.get_maximum_partition_size
.expect;
let starting_lba = gpt.find_optimal_place
.expect;
let ending_lba = starting_lba + size - 1;
gpt = GPTPartitionEntry ;
Creating a new partition table with one entry that fills the entire disk:
let ss = 512;
let data = vec!;
let mut cur = new;
let mut gpt = GPTnew_from
.expect;
gpt = GPTPartitionEntry ;