Skip to main content

open_device

Function open_device 

Source
pub fn open_device(path: &Path) -> Result<(File, u64)>
Expand description

Open a live block device for reading and return it with its size in bytes.

Block devices report metadata().len() == 0, so the size is obtained by seeking to the end; the handle is rewound to the start before returning, so the caller gets a fresh Read + Seek view ready for partition/filesystem analysis. Reading a raw device typically requires root/Administrator — the returned std::io::Error surfaces a permission failure rather than masking it.

§Errors

Propagates any I/O error from opening or seeking the device.