I wanted to read contents off a .qcow2
image using bdrv_pread(...)
functions in QEMU.
Say, the full path of my image is /path/to/myimage.qcow2
, I want to be able to read 'n' bytes of data off of this image at a particular offset. Now the bdrv_pread
functions takes these arguments 'BlockDriverState *bs, int64_t offset, void *buf, int count1
', how exactly do I initialize the BlockDriverState
(device?) from the path of the image. All other parameters other than BlockDriverState
are clear to me.
Thanks.
If your goal is to access a qcow2 file from your own program I would recommend not trying to use the QEMU functions. These are going to have a lot of state associated with QEMU that is not necessary if all you want to do is read the contents of the qcow2 file. Instead you could look at the qcow2 specification or if you want to work at one higher level of abstraction you could look at the libguestfs library, which states that it has an API for accessing the supported VM disk formats (although I have never used it myself). There is some example code here that can help you get started.