Thanks to visit codestin.com
Credit goes to lib.rs

1 unstable release

Uses new Rust 2024

0.1.0 Nov 19, 2025

#401 in Unix APIs


Used in diskfmt

MIT and LGPL-2.1

31KB
741 lines

fudisks

A high-level wrapper around the udisks2 crate. A work in progress!

Example: List Devices

cargo run --example list_devices

Example: Format a Partition (DANGEROUS)

ALLOW_DESTRUCTIVE=1 cargo run --example format_partition -- <udisks_object_path>

Quick Start

use fudisks::{Udisks, FormatOptions, JobEvent};
use futures_util::StreamExt;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let ud = Udisks::connect_system().await?;

    // Choose a partition object path from list_devices output
    let part = "/org/freedesktop/UDisks2/block_devices/sdb1";

    let opts = FormatOptions::Exfat { label: Some("USB".into()), cluster_size: None, quick: true };
    let handle = ud.format_partition(part, &opts).await?;

    let mut stream = handle.watch();
    while let Some(evt) = stream.next().await {
        match evt {
            JobEvent::Percent(p) => println!("{p:.1}%"),
            JobEvent::RateBytesPerSec(r) => println!("{r} B/s"),
            JobEvent::Completed(res) => match res {
                Ok(()) => break,
                Err(e) => { eprintln!("error: {}", e); return Err(e.into()); }
            }
        }
    }
    Ok(())
}

Format a whole disk using GPT (default) or DOS/MBR (DANGEROUS):

ALLOW_DESTRUCTIVE=1 cargo run --example format_disk -- <disk_object_path> gpt
ALLOW_DESTRUCTIVE=1 cargo run --example format_disk -- <disk_object_path> dos

Dependencies

~26–36MB
~425K SLoC