/// The function writes block header(s) to the buffer. We write block_header
/// the beginning of each block. Some buffer may range over multiple blocks.
/// If so this routine writes to each such block start.
/// Buffers may very in size and offset. Not all buffers may be large enough
/// to hold the header and not all buffers may overlap with beginning of the
/// block.
/// TODO(auradkar): Since current IOs are always 4KiB aligned, this function
/// works well. Not all unaligned cases are covered by this function.
The function writes block header(s) to the buffer. We write block_header
the beginning of each block. Some buffer may range over multiple blocks.
If so this routine writes to each such block start.
Buffers may very in size and offset. Not all buffers may be large enough
to hold the header and not all buffers may overlap with beginning of the
block.
TODO(auradkar): Since current IOs are always 4KiB aligned, this function
works well. Not all unaligned cases are covered by this function.
The function writes block header ( s ) to the buffer . We write block_header the beginning of each block . Some buffer may range over multiple blocks . If so this routine writes to each such block start . Buffers may very in size and offset . Not all buffers may be large enough to hold the header and not all buffers may overlap with beginning of the block . TODO ( auradkar ) : Since current IOs are always 4KiB aligned this function works well . Not all unaligned cases are covered by this function .
fn write_headers(
        &self,
        buf: &mut Vec<u8>,
        sequence_number: u64,
        offset_range: Range<u64>,
    ) -> Result<()> {
        let start = round_up(offset_range.start as usize, self.block_size as usize);
        let end = offset_range.end as usize;
        let header_size = IoHeader::size() as usize;
        let mut offset = start;
        while offset + header_size < end {
            let header = IoHeader {
                magic_number: self.magic_number,
                process_id: self.process_id,
                fd_unique_id: self.fd_unique_id,
                generator_unique_id: self.generator_unique_id,
                io_op_unique_id: sequence_number,
                file_offset: offset as u64,
                size: buf.capacity() as u64,
                seed: self.last_number,
            };
            let buf_offset = offset - start;
            header.write_header(&mut buf[buf_offset..(buf_offset + header_size)])?;
            offset += self.block_size as usize;
        }
        Ok(())
    }
fn write_headers ( & self , buf : & mut Vec < u8 > , sequence_number : u64 , offset_range : Range < u64 > , ) -> Result < ( ) > { let start = round_up ( offset_range . start as usize , self . block_size as usize ) ; let end = offset_range . end as usize ; let header_size = IoHeader :: size ( ) as usize ; let mut offset = start ; while offset + header_size < end { let header = IoHeader { magic_number : self . magic_number , process_id : self . process_id , fd_unique_id : self . fd_unique_id , generator_unique_id : self . generator_unique_id , io_op_unique_id : sequence_number , file_offset : offset as u64 , size : buf . capacity ( ) as u64 , seed : self . last_number , } ; let buf_offset = offset - start ; header . write_header ( & mut buf [ buf_offset .. ( buf_offset + header_size ) ] ) ? ; offset += self . block_size as usize ; } Ok ( ( ) ) }
The function writes block header(s) to the buffer.
The function writes block header ( s ) to the buffer .
&self
buf
&mut Vec<u8>
sequence_number
u64
offset_range
Range<u64>