Is there a clean way to obtain exclusive access to a physical partition under Windows?

I have come across only one possible solution, using the free virtual disk driver imdisk together with devio (remote drive access and acquisition). As imdisk is a kernel driver, it might be able to write to the partition. Unfortunately, as devio works in user-mode, I am not too sure whether this approach will work for you.

devio can acquire a physical partition and publish it on the network. For example:

devio -r 9000 \\.\PhysicalDrive0 2

does publish from the first disk the second partition on TCP port 9000, and will wait for a connection on this port. Better disable the firewall while testing this, and run devio as administrator.

To define this published partition as a new and stand-alone hard disk, use :

imdisk -a -t proxy -o ip -f 127.0.0.1 -m R:

which using localhost will create a new hard disk called R which is not a partition of anything. You can now try whether you can use the pretend real hard disk R in a VMware virtual machine.

This approach is explained in detail in Devio: Remote drive access and acquisition.

If this doesn't work, you will either have to :

  1. Accept a dangerous solution that modifies the MBR.
  2. Abandon using MacOS within Win7 as VM, using files in the Mac partition through Windows applications (with end-of-line character problems).
  3. Use a Virtual File System product, such as ELDOS Callback File System, although I doubt that this problem is worth for you a few thousand dollars.
  4. Abandon Windows 7 and downgrade to XP.
  5. Modify the source of imdisk so that as a kernel driver it will create a pretend disk directly on the physical partition, without the need for devio.

It depends on how desperate you are to get this working, but I would say that it's possible, with "just" two "easy" (read: brutal) steps:

  1. Write a driver to bypass the restriction set by Windows, using the (semi-?)documented flag SL_FORCE_DIRECT_WRITE.

  2. Hook the CreateFile and/or WriteFile call from VMWare using a library like EasyHook (I told you it was easy!) to communicate with the file manually with your driver, perhaps communicating with the driver using DeviceIoControl.

It actually doesn't sound that bad, if you know where to look for the information for bypassing the restrictions... I've hooked applications like Nero myself in order to examine IOCTL_SCSI_PASS_THROUGH calls so I can make my own CD burner library, and this wouldn't be too difficult; writing a driver will be the harder part, but manageable.


Edit:

I'm guessing you already figured this out, but the structure you need to modify is called FLT_IO_PARAMETER_BLOCK for IRP_MJ_READ. Not sure how easy it will be, but it shouldn't be too hard.