For In and Out requests, checks that the descriptors collectively fit in a backing disk of the given size. Returns `Ok(())` if they fit, or `ExecuteError::BadRequest` otherwise.
(&self, disk_nsectors: u64)
| 548 | /// For In and Out requests, checks that the descriptors collectively fit in a backing disk of |
| 549 | /// the given size. Returns `Ok(())` if they fit, or `ExecuteError::BadRequest` otherwise. |
| 550 | fn check_data_bounds(&self, disk_nsectors: u64) -> Result<(), ExecuteError> { |
| 551 | if !matches!(self.request_type, RequestType::In | RequestType::Out) { |
| 552 | return Ok(()); |
| 553 | } |
| 554 | let mut total_bytes: u64 = 0; |
| 555 | for (_, data_len) in &self.data_descriptors { |
| 556 | total_bytes = total_bytes |
| 557 | .checked_add(u64::from(*data_len)) |
| 558 | .ok_or(ExecuteError::BadRequest(Error::InvalidOffset))?; |
| 559 | } |
| 560 | if total_bytes == 0 { |
| 561 | return Ok(()); |
| 562 | } |
| 563 | let total_sectors = total_bytes.div_ceil(SECTOR_SIZE); |
| 564 | let end_sector = self |
| 565 | .sector |
| 566 | .checked_add(total_sectors) |
| 567 | .ok_or(ExecuteError::BadRequest(Error::InvalidOffset))?; |
| 568 | if end_sector > disk_nsectors { |
| 569 | return Err(ExecuteError::BadRequest(Error::InvalidOffset)); |
| 570 | } |
| 571 | Ok(()) |
| 572 | } |
| 573 | } |
no outgoing calls
no test coverage detected