### Install gptman Crate Source: https://docs.rs/gptman Add the gptman crate to your Cargo.toml file to include it in your project dependencies. ```toml [dependencies] gptman = "3" ``` -------------------------------- ### Create a New Partition Entry Source: https://docs.rs/gptman Finds an unused partition slot, determines the maximum available size, and finds an optimal starting LBA to create a new partition entry. Modifies an existing GPT object. ```rust let mut f = std::fs::File::open("tests/fixtures/disk1.img") .expect("could not open disk"); let mut gpt = gptman::GPT::find_from(&mut f) .expect("could not find GPT"); let free_partition_number = gpt.iter().find(|(i, p)| p.is_unused()).map(|(i, _)| i) .expect("no more places available"); let size = gpt.get_maximum_partition_size() .expect("no more space available"); let starting_lba = gpt.find_optimal_place(size) .expect("could not find a place to put the partition"); let ending_lba = starting_lba + size - 1; gpt[free_partition_number] = gptman::GPTPartitionEntry { partition_type_guid: [0xff; 16], unique_partition_guid: [0xff; 16], starting_lba, ending_lba, attribute_bits: 0, partition_name: "A Robot Named Fight!".into(), }; ``` -------------------------------- ### Read GPT and Iterate Partitions Source: https://docs.rs/gptman Opens a disk image, finds the GPT, and iterates through its partitions, printing details for used partitions. Requires a file path to a disk image. ```rust let mut f = std::fs::File::open("tests/fixtures/disk1.img") .expect("could not open disk"); let gpt = gptman::GPT::find_from(&mut f) .expect("could not find GPT"); println!("Disk GUID: {:?}", gpt.header.disk_guid); for (i, p) in gpt.iter() { if p.is_used() { println!("Partition #{}: type = {:?}, size = {} bytes, starting lba = {}", i, p.partition_type_guid, p.size().unwrap() * gpt.sector_size, p.starting_lba); } } ``` -------------------------------- ### Create New GPT with One Entry Source: https://docs.rs/gptman Initializes a new GPT on a byte vector with a specified sector size and a single partition entry that spans the entire usable disk space. Requires a mutable byte vector and sector size. ```rust let ss = 512; let data = vec![0; 100 * ss as usize]; let mut cur = std::io::Cursor::new(data); let mut gpt = gptman::GPT::new_from(&mut cur, ss as u64, [0xff; 16]) .expect("could not create partition table"); gpt[1] = gptman::GPTPartitionEntry { partition_type_guid: [0xff; 16], unique_partition_guid: [0xff; 16], starting_lba: gpt.header.first_usable_lba, ending_lba: gpt.header.last_usable_lba, attribute_bits: 0, partition_name: "A Robot Named Fight!".into(), }; ``` -------------------------------- ### Disable Default Features for gptman Source: https://docs.rs/gptman To disable default features, such as Linux-specific ioctl operations, specify the version with `default-features = false` in Cargo.toml. ```toml [dependencies] gptman = { version = "3", default-features = false } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.