libyal / libvmdk

Library and tools to access the VMware Virtual Disk (VMDK) format
GNU Lesser General Public License v3.0
163 stars 66 forks source link

Does the library support converting VMDK to raw disk image #21

Closed leslie-qiwa closed 4 years ago

leslie-qiwa commented 5 years ago

Thanks for the great library. We want a simple library to convert VMDK image to raw disk image. qemu-img can support it, but we do want a library like libvmdk to achieve. So if yes, can you please provide some sample codes? Is libvmdk_handle_read_buffer the one I should use and continuously read until EOF?

joachimmetz commented 5 years ago

Is libvmdk_handle_read_buffer the one I should use and continuously read until EOF?

yes, the API is very straightforward open (descriptor file), (open data files), read_buffer, close For an example have a look at vmdkmount (mount_file_entry.c).

leslie-qiwa commented 5 years ago

Perfect and thanks for the quick reply. Would you mind me submitting one PR to add one vmdkconvert utility tool into vmdktools folder. I thought other people may benefit from it, and I can also get your help to review it.

joachimmetz commented 5 years ago

The reason why I never added such a tool (which I would have named vmdkexport) is that with vmdkmount you technically have a raw image without the additional storage overhead. With dd or equiv you can easily create such a copy.

What is your use case for having such tool?

BTW I can help review such a tool also in another repo, as long as the code is under an Open Source license I can work with.

leslie-qiwa commented 5 years ago

The use case is to download vmdk file and convert to raw disk image file on the fly, while Golang is the main language. So I probably need write one Golang binding for this library. With the vmdkexport tool, I can get some understanding on the APIs and verify the result, then can work on binding part.

Anyway, let me create such a tool on my repo, and invite you for review. Thanks a lot

joachimmetz commented 5 years ago

I see, the outline of the C API usage would look something like:

  1. libvmdk_error_t *error = NULL;
  2. libvmdk_handle_t *handle = NULL;
  3. libvmdk_handle_initialize(&handle, &error);
  4. libvmdk_handle_open(handle, descriptor_file, LIBVMDK_OPEN_READ, &error);
  5. libvmdk_handle_open_extent_data_files(handle, &error)
  6. libvmdk_handle_read_buffer(handle, buffer, read_size, &error)
  7. libvmdk_handle_close(handle, &error);
  8. libvmdk_handle_free(&handle, &error);

Make sure to check the return values of the functions, they indicate success/error status and error contains some diagnostic information about the error. Also free error if it has been set.

More detail is about the C API are in man 3 libvmdk or the main include file include/libvmdk.h

leslie-qiwa commented 5 years ago

thanks a lot!