Reading the contents of a qcow2 image using `bdrv_pread (..)` or alternatives

I wanted to read content with an image .qcow2

using functions bdrv_pread(...)

in QEMU. Let's say the full path to my image /path/to/myimage.qcow2

, I want to be able to read "n" bytes of data from that image at a specific offset. Now the functions bdrv_pread

take these arguments BlockDriverState *bs, int64_t offset, void *buf, int count1

' how exactly do I initialize BlockDriverState

(device?) Along the image path. All other parameters, other than BlockDriverState

, are clear to me.

Thank.

+3


source to share


1 answer


If your goal is to access the qcow2 file from your own program, then I would recommend not trying to use QEMU functions. They will have many states associated with QEMU, which is not necessary if all you want to do is read the contents of the qcow2. You can look at the qcow2 spec instead, or if you want to work at one higher level of abstraction, you can look at libguestfs , which says it has an API to access the supported VM disk formats (although I've never used it myself). Below is some sample code here to help you get started.



+1


source







All Articles