pub fn read(&mut self, buffer: &mut [u8], offset: usize) -> Result<usize, &'static str> {
        let BlockBounds { range, first_block_offset, .. } = BlockBounds::block_bounds(offset, buffer.len(), &self.block_size)?;
        let block_size_in_bytes = self.block_size.block_size_in_bytes;

        // Read the actual data, one block at a time.
		let mut src_offset = first_block_offset; 
		let mut dest_offset = 0;
		for block_num in range {
			// don't copy past the end of `buffer`
			let num_bytes_to_copy = core::cmp::min(block_size_in_bytes - src_offset, buffer.len() - dest_offset);
            let block_bytes = BlockCache::read_block(&mut self.cache, block_num)?;
			buffer[dest_offset .. (dest_offset + num_bytes_to_copy)].copy_from_slice(&block_bytes[src_offset .. (src_offset + num_bytes_to_copy)]);
			trace!("BlockIo::read(): for block {}, copied bytes into buffer[{}..{}] from block[{}..{}]",
				block_num, dest_offset, dest_offset + num_bytes_to_copy, src_offset, src_offset + num_bytes_to_copy,
			);
			dest_offset += num_bytes_to_copy;
			src_offset = 0;
		}

        Ok(dest_offset)
    }
/// Reads data from this block storage device and places it into the provided `buffer`.
/// The length of the given `buffer` determines the maximum number of bytes to be read.
/// 
/// Returns the number of bytes that were successfully read from the drive
/// and copied into the given `buffer`.
/// 
/// The read blocks will be cached in this `BlockIo` struct to accelerate future storage device access.
Reads data from this block storage device and places it into the provided `buffer`.
The length of the given `buffer` determines the maximum number of bytes to be read.

Returns the number of bytes that were successfully read from the drive
and copied into the given `buffer`.

The read blocks will be cached in this `BlockIo` struct to accelerate future storage device access.
Reads data from this block storage device and places it into the provided ` buffer ` . The length of the given ` buffer ` determines the maximum number of bytes to be read . Returns the number of bytes that were successfully read from the drive and copied into the given ` buffer ` . The read blocks will be cached in this ` BlockIo ` struct to accelerate future storage device access .
pub fn read(&mut self, buffer: &mut [u8], offset: usize) -> Result<usize, &'static str> {
        let BlockBounds { range, first_block_offset, .. } = BlockBounds::block_bounds(offset, buffer.len(), &self.block_size)?;
        let block_size_in_bytes = self.block_size.block_size_in_bytes;
        // Read the actual data, one block at a time.
		let mut src_offset = first_block_offset; 
		let mut dest_offset = 0;
		for block_num in range {
			// don't copy past the end of `buffer`
			let num_bytes_to_copy = core::cmp::min(block_size_in_bytes - src_offset, buffer.len() - dest_offset);
            let block_bytes = BlockCache::read_block(&mut self.cache, block_num)?;
			buffer[dest_offset .. (dest_offset + num_bytes_to_copy)].copy_from_slice(&block_bytes[src_offset .. (src_offset + num_bytes_to_copy)]);
			trace!("BlockIo::read(): for block {}, copied bytes into buffer[{}..{}] from block[{}..{}]",
				block_num, dest_offset, dest_offset + num_bytes_to_copy, src_offset, src_offset + num_bytes_to_copy,
			);
			dest_offset += num_bytes_to_copy;
			src_offset = 0;
		}
        Ok(dest_offset)
    }
pub fn read ( & mut self , buffer : & mut [ u8 ] , offset : usize ) -> Result < usize , & ' static str > { let BlockBounds { range , first_block_offset , .. } = BlockBounds :: block_bounds ( offset , buffer . len ( ) , & self . block_size ) ? ; let block_size_in_bytes = self . block_size . block_size_in_bytes ; // Read the actual data, one block at a time. let mut src_offset = first_block_offset ; let mut dest_offset = 0 ; for block_num in range { // don't copy past the end of `buffer` let num_bytes_to_copy = core :: cmp :: min ( block_size_in_bytes - src_offset , buffer . len ( ) - dest_offset ) ; let block_bytes = BlockCache :: read_block ( & mut self . cache , block_num ) ? ; buffer [ dest_offset .. ( dest_offset + num_bytes_to_copy ) ] . copy_from_slice ( & block_bytes [ src_offset .. ( src_offset + num_bytes_to_copy ) ] ) ; trace ! ( " " block_num dest_offset dest_offset num_bytes_to_copy src_offset src_offset num_bytes_to_copy ) ; dest_offset += num_bytes_to_copy ; src_offset = 0 ; } Ok ( dest_offset ) }
Reads data from this block storage device and places it into the provided `buffer`.
Reads data from this block storage device and places it into the provided ` buffer ` .
&mut self
buffer
&mut [u8]
offset
usize