How to write the physical sectors of a BitLocker-encrypted volume?

2

I call CreateFile() and I open \\.\PhysicalDrive0, then I read the sectors of a BitLocker-encrypted volume, and everything works fine. This way I create a backup copy of the physical (encrypted) sectors of a volume that is encrypted with BitLocker.

Then, I call CreateFile() again and I open \\.\PhysicalDrive0 again, then I try to write the sectors of said BitLocker-encrypted volume (I'm trying to restore the backup), and it doesn't work.

If the volume is unlocked, I get an IOException with HResult = 0x80370000 and text "This drive is locked by BitLocker Drive Encryption. You must unlock this drive from Control Panel."

After I unlock the volume from the UI, the exception changes to HResult = 0x80070013 and text "The media is write protected."

Question: What do I have to do to be allowed to write the physical sectors of a BitLocker-encrypted volume? I mention that I do run the code as an admin, and I do lock the volume, to no avail. The same code works fine with non-encrypted volumes.

So far, I only have 2 options, and neither of them is good:

  1. Writing the physical sectors of the BitLocker volume works fine if I take the ENTIRE drive offline (calling DeviceIOControl()), but I cannot do this, since the drive also contains other volumes, that need to be online.

  2. It also works if (before restoring) I format the volume as a non-encrypted volume, thus removing the BitLocker encryption. After doing this, writing the physical sectors works fine, but Windows does not detect the new written sectors as a BitLocker volume. However, after removing and re-inserting the drive (or after a restart if the drive is fixed) it does detect the volume as a BitLocker encrypted volume.

Thanks a lot.

windows
winapi
filesystems
bitlocker
sector
asked on Stack Overflow Apr 14, 2020 by TheodoreJohn

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0