test/dummy_libs/devices/virt_disk/virt_disk.cpp
// This function is a bit confusing because the parameters "start_block" and "num_blocks" refer to sectors on the
// virtual disk, rather than the blocks used within the VDI.
This function is a bit confusing because the parameters "start_block" and "num_blocks" refer to sectors on the
virtual disk, rather than the blocks used within the VDI.
This function is a bit confusing because the parameters " start_block " and " num_blocks " refer to sectors on the virtual disk rather than the blocks used within the VDI .
ERR_CODE virtual_disk_dummy_device::write_blocks(uint64_t start_block,
                                                 uint64_t num_blocks,
                                                 const void *buffer,
                                                 uint64_t buffer_length)
{
  ERR_CODE return_val = ERR_CODE::UNKNOWN;
  if ((start_block > this->_num_blocks) ||
      ((start_block + num_blocks) > this->_num_blocks) ||
      (buffer_length < (num_blocks * this->_block_size)) ||
      (buffer == nullptr))
  {
    return_val = ERR_CODE::INVALID_PARAM;
  }
  else if (get_device_status() != DEV_STATUS::OK)
  {
    return_val = ERR_CODE::DEVICE_FAILED;
  }
  else
  {
    try
    {
      backing_device->write(buffer, start_block * this->_block_size, num_blocks * this->_block_size, buffer_length);
      return_val = ERR_CODE::NO_ERROR;
    }
    catch(std::fstream::failure &f)
    {
      return_val = ERR_CODE::DEVICE_FAILED;
    }
  }
  return return_val;
}
ERR_CODE virtual_disk_dummy_device :: write_blocks ( uint64_t start_block , uint64_t num_blocks , const void * buffer , uint64_t buffer_length ) { ERR_CODE return_val = ERR_CODE :: UNKNOWN ; if ( ( start_block > this -> _num_blocks ) || ( ( start_block + num_blocks ) > this -> _num_blocks ) || ( buffer_length < ( num_blocks * this -> _block_size ) ) || ( buffer == nullptr ) ) { return_val = ERR_CODE :: INVALID_PARAM ; } else if ( get_device_status ( ) != DEV_STATUS :: OK ) { return_val = ERR_CODE :: DEVICE_FAILED ; } else { try { backing_device -> write ( buffer , start_block * this -> _block_size , num_blocks * this -> _block_size , buffer_length ) ; return_val = ERR_CODE :: NO_ERROR ; } catch ( std :: fstream :: failure & f ) { return_val = ERR_CODE :: DEVICE_FAILED ; } } return return_val ; }
This function is a bit confusing because the parameters "start_block" and "num_blocks" refer to sectors on the
virtual disk, rather than the blocks used within the VDI.
This function is a bit confusing because the parameters " start_block " and " num_blocks " refer to sectors on the virtual disk rather than the blocks used within the VDI .