In an earlier post I asked a question to which I found an answer (I
write a new post because the old thread has expired).
What I wanted to do was writing to a physical disk after having
locked/dismounted all partitions/volumes on this physical disk.
The initial code was this :
LockVolume(LogicalDriveHandle);
// results in access denied
WriteProtectedSector(PhysicalDriveHandle);
DismountVolume(LogicalDriveHandle);
UnlockVolume(LogicalDriveHandle);
The missing part why it did not work is that the physical drive needs to
be opened with denying shared write access. I.e. when calling CreateFile
for PhysicalDriveX either only specify FILE_SHARE_READ or 0 for the file
sharing mode (but not FILE_SHARE_WRITE).
|