MCPcopy Create free account
hub / github.com/cloud-hypervisor/cloud-hypervisor / seek

Method seek

block/src/vhdx/mod.rs:168–201  ·  view source on GitHub ↗

Wrapper function to satisfy Seek trait implementation for VHDx disk. Updates the offset field in the Vhdx struct.

(&mut self, pos: SeekFrom)

Source from the content-addressed store, hash-verified

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
204impl BlockBackend for Vhdx {

Callers 7

collect_bat_entriesMethod · 0.45
write_bat_entriesMethod · 0.45
newMethod · 0.45
update_headerMethod · 0.45
readFunction · 0.45
writeFunction · 0.45
newMethod · 0.45

Calls 2

newFunction · 0.85
virtual_disk_sizeMethod · 0.80

Tested by

no test coverage detected