fn write(&mut self, buf: &[u8]) -> std::result::Result<usize, std::io::Error> {
        let sector_count =
            div_round_up!(buf.len() as u64, self.disk_spec.logical_sector_size as u64);
        let sector_index = self.current_offset / self.disk_spec.logical_sector_size as u64;

        if self.first_write {
            self.first_write = false;
            self.vhdx_header.update(&mut self.file).map_err(|e| {
                std::io::Error::new(
                    std::io::ErrorKind::Other,
                    format!("Failed to update VHDx header: {}", e),
                )
            })?;
        }

        vhdx_io::write(
            &mut self.file,
            buf,
            &mut self.disk_spec,
            self.bat_entry.file_offset,
            &mut self.bat_entries,
            sector_index,
            sector_count,
        )
        .map_err(|e| {
            std::io::Error::new(
                std::io::ErrorKind::Other,
                format!(
                    "Failed writing {} sectors on VHDx at index {}: {}",
                    sector_count, sector_index, e
                ),
            )
        })
    }
/// Wrapper function to satisfy Write trait implementation for VHDx disk.
/// Convert the offset to sector index and buffer length to sector count.
Wrapper function to satisfy Write trait implementation for VHDx disk.
Convert the offset to sector index and buffer length to sector count.
Wrapper function to satisfy Write trait implementation for VHDx disk . Convert the offset to sector index and buffer length to sector count .
fn write(&mut self, buf: &[u8]) -> std::result::Result<usize, std::io::Error> {
        let sector_count =
            div_round_up!(buf.len() as u64, self.disk_spec.logical_sector_size as u64);
        let sector_index = self.current_offset / self.disk_spec.logical_sector_size as u64;
        if self.first_write {
            self.first_write = false;
            self.vhdx_header.update(&mut self.file).map_err(|e| {
                std::io::Error::new(
                    std::io::ErrorKind::Other,
                    format!("Failed to update VHDx header: {}", e),
                )
            })?;
        }
        vhdx_io::write(
            &mut self.file,
            buf,
            &mut self.disk_spec,
            self.bat_entry.file_offset,
            &mut self.bat_entries,
            sector_index,
            sector_count,
        )
        .map_err(|e| {
            std::io::Error::new(
                std::io::ErrorKind::Other,
                format!(
                    "Failed writing {} sectors on VHDx at index {}: {}",
                    sector_count, sector_index, e
                ),
            )
        })
    }
fn write ( & mut self , buf : & [ u8 ] ) -> std :: result :: Result < usize , std :: io :: Error > { let sector_count = div_round_up ! ( buf len ( ) as u64 self disk_spec logical_sector_size as u64 ) ; let sector_index = self . current_offset / self . disk_spec . logical_sector_size as u64 ; if self . first_write { self . first_write = false ; self . vhdx_header . update ( & mut self . file ) . map_err ( | e | { std :: io :: Error :: new ( std :: io :: ErrorKind :: Other , format ! ( " " e ) , ) } ) ? ; } vhdx_io :: write ( & mut self . file , buf , & mut self . disk_spec , self . bat_entry . file_offset , & mut self . bat_entries , sector_index , sector_count , ) . map_err ( | e | { std :: io :: Error :: new ( std :: io :: ErrorKind :: Other , format ! ( " " sector_count sector_index e ) , ) } ) }
Wrapper function to satisfy Write trait implementation for VHDx disk.
Wrapper function to satisfy Write trait implementation for VHDx disk .
&mut self
buf
&[u8]
&mut self
buf
&[u8]