Wrapper function to satisfy Write trait implementation for VHDx disk. Convert the offset to sector index and buffer length to sector count.
(&mut self, buf: &[u8])
| 131 | /// Wrapper function to satisfy Write trait implementation for VHDx disk. |
| 132 | /// Convert the offset to sector index and buffer length to sector count. |
| 133 | fn write(&mut self, buf: &[u8]) -> std::result::Result<usize, std::io::Error> { |
| 134 | let sector_count = (buf.len() as u64).div_ceil(self.disk_spec.logical_sector_size as u64); |
| 135 | let sector_index = self.current_offset / self.disk_spec.logical_sector_size as u64; |
| 136 | |
| 137 | if self.first_write { |
| 138 | self.first_write = false; |
| 139 | self.vhdx_header |
| 140 | .update(&mut self.file) |
| 141 | .map_err(|e| std::io::Error::other(format!("Failed to update VHDx header: {e}")))?; |
| 142 | } |
| 143 | |
| 144 | let result = vhdx_io::write( |
| 145 | &mut self.file, |
| 146 | buf, |
| 147 | &mut self.disk_spec, |
| 148 | self.bat_entry.file_offset, |
| 149 | &mut self.bat_entries, |
| 150 | sector_index, |
| 151 | sector_count, |
| 152 | ) |
| 153 | .map_err(|e| { |
| 154 | std::io::Error::other(format!( |
| 155 | "Failed writing {sector_count} sectors on VHDx at index {sector_index}: {e}" |
| 156 | )) |
| 157 | })?; |
| 158 | |
| 159 | self.current_offset = self.current_offset.checked_add(result as u64).unwrap(); |
| 160 | |
| 161 | Ok(result) |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | impl Seek for Vhdx { |
no test coverage detected