Wrapper function to satisfy Seek trait implementation for VHDx disk. Updates the offset field in the Vhdx struct.
(&mut self, pos: SeekFrom)
| 166 | /// Wrapper function to satisfy Seek trait implementation for VHDx disk. |
| 167 | /// Updates the offset field in the Vhdx struct. |
| 168 | fn seek(&mut self, pos: SeekFrom) -> std::io::Result<u64> { |
| 169 | let new_offset: Option<u64> = match pos { |
| 170 | SeekFrom::Start(off) => Some(off), |
| 171 | SeekFrom::End(off) => { |
| 172 | if off < 0 { |
| 173 | 0i64.checked_sub(off).and_then(|increment| { |
| 174 | self.virtual_disk_size().checked_sub(increment as u64) |
| 175 | }) |
| 176 | } else { |
| 177 | self.virtual_disk_size().checked_add(off as u64) |
| 178 | } |
| 179 | } |
| 180 | SeekFrom::Current(off) => { |
| 181 | if off < 0 { |
| 182 | 0i64.checked_sub(off) |
| 183 | .and_then(|increment| self.current_offset.checked_sub(increment as u64)) |
| 184 | } else { |
| 185 | self.current_offset.checked_add(off as u64) |
| 186 | } |
| 187 | } |
| 188 | }; |
| 189 | |
| 190 | if let Some(o) = new_offset |
| 191 | && o <= self.virtual_disk_size() |
| 192 | { |
| 193 | self.current_offset = o; |
| 194 | return Ok(o); |
| 195 | } |
| 196 | |
| 197 | Err(std::io::Error::new( |
| 198 | std::io::ErrorKind::InvalidData, |
| 199 | "Failed seek operation", |
| 200 | )) |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | impl BlockBackend for Vhdx { |
no test coverage detected