Crate block_devs[][src]

Expand description

Block Devs provides safe wrappers for the ioctl calls for dealing with block devices (USB sticks, SSDs, hard drives etc).

It aims to provide a consitent interface across all platforms for things like getting the number of bytes a disk has.

So far Linux, macOS and Open BSD are supported

It does this by a extention trait (BlckExt) on the standard File struct.

    use block_devs::BlckExt;
    use std::fs::File;

    let path = "/dev/sda2";
    let file = File::open(path).unwrap();
    let count = file.get_block_count().unwrap();
    let bytes = file.get_block_device_size().unwrap();
    let gb = bytes >> 30;

    println!("disk is {} blocks totaling {}gb", count, gb);

Traits

BlckExt

Block device specific extensions to File.