Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wrong data written #13

Open
martin-kudlicka opened this issue May 29, 2021 · 0 comments
Open

wrong data written #13

martin-kudlicka opened this issue May 29, 2021 · 0 comments

Comments

@martin-kudlicka
Copy link

Hello,
I am writing sort of disk cache using WinSpd. At the moment I am just mirroring real volume with virtual WinSpd volume. It means all reads/writes are just redirected to real volume. For example my WinSpd write callback contains

  ...
  LARGE_INTEGER distanceToMove;
  distanceToMove.QuadPart = BlockAddress * _sectorSize;
  if (!SetFilePointerEx(_sourceVolume, distanceToMove, Q_NULLPTR, FILE_BEGIN))
  {
    SpdStorageUnitStatusSetSense(Status, SCSI_SENSE_MEDIUM_ERROR, SCSI_ADSENSE_SEEK_ERROR, Q_NULLPTR);
    return FALSE;
  }

  DWORD bytesWritten = 0;
  if (!WriteFile(_sourceVolume, Buffer, BlockCount * _sectorSize, &bytesWritten, Q_NULLPTR))
  {
    SpdStorageUnitStatusSetSense(Status, SCSI_SENSE_MEDIUM_ERROR, SCSI_ADSENSE_WRITE_ERROR, Q_NULLPTR);
    return FALSE;
  }
  ...

_sectorSize is 512 bytes, _sourceVolume is HANDLE to testing volume on VHDX disk.
When writing 60 MB of data some of the data is not correctly written (content doesn't match). It's usually about 10 blocks of size SPD_IOCTL_STORAGE_UNIT_PARAMS::MaxTransferLength which I have set to 65 kB.
I found out when I set SpdStorageUnitStartDispatcher to 1 thread all data are correctly written. It could be somehow connected to #10 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant