[vbox-dev] Byte-level read/write access to vdi files through Main API

Maxim Khitrov max at mxcrypt.com
Fri Dec 24 09:00:29 PST 2010

2010/12/24 Achim Hasenmüller <achim.hasenmueller at oracle.com>:
>> I suspect that the answer to my question is 'no', but would like to
>> get a confirmation. Is there functionality in the Main API (which I'm
>> accessing through COM on Windows) for byte-level read/write access to
>> vdi files?
> Hehe, of course not. That would not be good for performance.

But it would be very convenient for situations where performance was
not a concern :)

> However, the VirtualBox storage architecture supports a filter driver model. You can develop a simple filter driver and dynamically insert it into the chain of storage drivers.
> Here's an example filter which we use to perform consistency tests:
> http://www.virtualbox.org/browser/trunk/src/VBox/Devices/Storage/DrvDiskIntegrity.cpp
> In its init routine drvdiskintConstruct, it will install the required handlers so that it receives callbacks on disk read/write. If you configure your VM to "Use Host IO cache", then it will be simpler, because there will be no async IO which is much harder to handle.
> If you want to insert boot sectors, you want to work on the layer above VDI as you only care about sector reads/writes and not how the actual on disk storage looks like.
> Achim

Sounds like your solution would achieve better abstraction, but I
think it's much more complicated that what I actually need. Ideally,
I'd like to avoid messing with VirtualBox components on the other side
of the Main API. I assume that's where filter drivers, such as
DrvDiskIntegrity.cpp, are located?

The API gives me the ability to lock the hard drive for writing and
provides information about its type and location. Given that I don't
need to work with dynamic disks or those that have snapshots, it seems
that the easiest solution is to parse the metadata at the beginning of
the file so that I know what regions correspond to sectors 0, 1, and
so on.

Or is the actual representation of the data on the disk more
complicated than this, even with my set of restrictions?

More information about the vbox-dev mailing list