pub trait BlckExt:
Seek
+ Read
+ Write {
// Required methods
fn is_block_device(&self) -> bool;
fn get_block_device_size(&self) -> Result<u64>;
fn get_size_of_block(&self) -> Result<u64>;
fn get_block_count(&self) -> Result<u64>;
fn block_reread_paritions(&self) -> Result<()>;
fn block_discard_zeros(&self) -> Result<bool>;
fn block_discard(&self, offset: u64, len: u64) -> Result<()>;
fn sync_data(&self) -> Result<()>;
// Provided methods
fn block_zero_out(&mut self, offset: u64, len: u64) -> Result<()> { ... }
fn block_fast_zero_out(&mut self, offset: u64, len: u64) -> Result<()> { ... }
}Expand description
Block device specific extensions to File.
Required Methods§
Sourcefn is_block_device(&self) -> bool
fn is_block_device(&self) -> bool
Test if the file is a block device
This will return true for a block device e.g. "/dev/sda1" and false for other files
If it returns false using the other BlckExt methods on this file will almost certainly be an error.
Sourcefn get_block_device_size(&self) -> Result<u64>
fn get_block_device_size(&self) -> Result<u64>
Get the total size of the block device in bytes.
Sourcefn get_size_of_block(&self) -> Result<u64>
fn get_size_of_block(&self) -> Result<u64>
Get the size of one logical block in bytes.
Sourcefn get_block_count(&self) -> Result<u64>
fn get_block_count(&self) -> Result<u64>
Get the number of blocks on the device.
Sourcefn block_reread_paritions(&self) -> Result<()>
fn block_reread_paritions(&self) -> Result<()>
Ask the OS to re-read the partition table from the device.
When writing an image to a block device the partions layout may change this ask the OS to re-read the partion table
Sourcefn block_discard_zeros(&self) -> Result<bool>
fn block_discard_zeros(&self) -> Result<bool>
Does this device support zeroing on discard.
Some device (e.g. SSDs with TRIM support) have the ability to mark blocks as unused in a way that means they will return zeros on future reads.
If this returns true then all calls to block_discard will cause following reads to return zeros
Some device only support zeroing on discard for certain sizes and alignements, in which case this
will return false but some calls to block_discard may still result in zeroing some or all of the discared range.
Since this is a linux only feature other systems will always return false
Your best bet for knowing if block discarding zeros is to discard some blocks and test that it worked using block_fast_zero_out.
Sourcefn block_discard(&self, offset: u64, len: u64) -> Result<()>
fn block_discard(&self, offset: u64, len: u64) -> Result<()>
Discard a section of the block device.
Some device e.g. thinly provisioned arrays or SSDs with TRIM support have the ability to mark blocks as unused
to free them up for other use. This may or may not result in future reads to the discarded section to return
zeros, see block_discard_zeros for more detail.
offset and length should be given in bytes.
fn sync_data(&self) -> Result<()>
Provided Methods§
Sourcefn block_zero_out(&mut self, offset: u64, len: u64) -> Result<()>
fn block_zero_out(&mut self, offset: u64, len: u64) -> Result<()>
Zeros out a section of the block device.
There is no guaranty that there special kernel support for this even block_discard_zeros returns true
so it is unlikely to be much faster that writing zeros the normal way, apart from saving a bunch of syscalls.
If there is no system call on a platfrom it will be implement by writing zeros in the normal way
offset and length should be given in bytes.
Sourcefn block_fast_zero_out(&mut self, offset: u64, len: u64) -> Result<()>
fn block_fast_zero_out(&mut self, offset: u64, len: u64) -> Result<()>
Try to zero out a block using discard and return an error if the data is not zeroed.
Some devices will (SSDs, thinly provisioned RAID arrays) will return zeros if a sufficiently large area is discarded. This method writes some data to the start of the range to be zerod, disards the range then reads the data back. It returns an error if the data was not zerod.
offset and length should be given in bytes.