[][src]Struct linapi::system::devices::block::Block

pub struct Block { /* fields omitted */ }

A Block Device

Methods

impl Block[src]

pub fn get_connected() -> Result<Vec<Self>>[src]

Get connected Block Devices.

Note

Partitions are not included. Use Block::partitions.

The returned Vec is sorted by kernel name.

Errors

pub fn from_dev(path: &Path) -> Result<Self>[src]

Create from a device file in /dev

Errors

pub fn path(&self) -> &Path[src]

Canonical path to the block device.

You normally shouldn't need this, but it could be useful if you want to manually access information not exposed by this crate.

pub fn dev_path(&self) -> Result<Option<PathBuf>>[src]

Path to the device file, usually in /dev.

pub fn name(&self) -> &str[src]

Kernel name for this device.

This does not have to match whats in /dev

pub fn partitions(&self) -> Result<Vec<Partition>>[src]

Get this devices partitions, if any.

Errors

  • If I/O does

pub fn open(&self) -> Result<Option<File>>[src]

Open the device special file in /dev associated with this block device, if it exists.

The device file is opened for reading and writing

Errors

  • If I/O does

pub fn major(&self) -> u64[src]

Device major number

pub fn minor(&self) -> u64[src]

Device minor number

pub fn size(&self) -> Result<u64>[src]

Get the byte size of the device, if possible.

pub fn capability(&self) -> Result<BlockCap>[src]

Get device capabilities.

Unknown flags are preserved

See BlockCap for more details.

pub fn power(&self) -> Power[src]

Get device power information

See Power for details

pub fn add_partition(&mut self, num: u64, start_end: Range<i64>) -> Result<()>[src]

Tell linux that partition num exists in the range start_end.

start_end is a byte range within the whole device. This range is NOT inclusive of end.

This does NOT modify partitions or anything on disk, only the kernels view of the device.

This can be useful in cases where the kernel doesn't support your partition table, you can read it yourself and tell it.

Examples

Add a partition

let mut block = Block::get_connected().unwrap().remove(0);
// Tell Linux there is one partition, starting at (1024 * 512) bytes
// and covering the whole device.
block.add_partition(0, 1024*512..block.size().unwrap());

Errors

  • If the ioctl does.

Implementation

This uses the ioctls from include/linux/blkpg.h.

pub fn remove_partition(&mut self, num: u64) -> Result<()>[src]

Tell Linux to forget about partition num.

Examples

Remove a partition

let mut block = Block::get_connected().unwrap().remove(0);
let part = block.partitions().unwrap().remove(0);
block.remove_partition(part.number().unwrap());

pub fn remove_existing_partitions(&mut self) -> Result<()>[src]

Convenience function for looping through Block::partitions yourself.

Implementation

For now this is slightly more efficient than doing it manually, opening the device only once instead of for each partition.

pub fn model(&self) -> Result<Option<String>>[src]

Get device model, if it exists.

pub fn logical_block_size(&self) -> Result<u64>[src]

Device logical block size, the smallest unit the device can address.

This is usually 512

Trait Implementations

impl Clone for Block[src]

impl Debug for Block[src]

Auto Trait Implementations

impl RefUnwindSafe for Block

impl Send for Block

impl Sync for Block

impl Unpin for Block

impl UnwindSafe for Block

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.