Extract VHD using guestfs
Hi, I have tried to extract *.vhd* file using guestfs library. I am able to list all files inside my archive using *guestfs_ls* also * guestfs_list_filesystems()* retruns right File system information. I am trying to extract files from inside archive using *guestfs_copy_device_to_file() * but it returns following error (error: copy_device_to_file: unknown option 689330304 (this can happen if a program is compiled against a newer version of libguestfs, then dynamically linked to an older version)). Please see attached main.c for my sample code. Regards MUHAMMAD MOSHIN
On Thu, Feb 09, 2017 at 03:24:53PM +0500, MUHAMMAD MOHSIN wrote:
* but it returns following error (error: copy_device_to_file: unknown option 689330304 (this can happen if a program is compiled against a newer version of libguestfs, then dynamically linked to an older version)). Please see attached main.c for my sample code.
I don't know about the above error, but the way you've used copy-device-to-file is clearly wrong:
guestfs_mount (g, "/dev/sda1", "/");
//guestfs_mount_local (g, "/home/mohsin/VHD/"); guestfs_ls(g, "/"); guestfs_copy_device_to_file(g, "/dev/sda1/file-to extract.exe", "/abc.exe");
It's actually not clear to me what you're trying to achieve here. Download the file to the local host? If so use guestfs_download: guestfs_download (g, "/file-to-extract.exe", "local-file.exe"); BTW you should check for errors from C API calls. http://libguestfs.org/guestfs.3.html#downloading http://libguestfs.org/guestfs.3.html#error-handling Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-builder quickly builds VMs from scratch http://libguestfs.org/virt-builder.1.html
On Thu, Feb 09, 2017 at 09:13:24PM +0000, Richard W.M. Jones wrote:
On Thu, Feb 09, 2017 at 03:24:53PM +0500, MUHAMMAD MOHSIN wrote:
* but it returns following error (error: copy_device_to_file: unknown option 689330304 (this can happen if a program is compiled against a newer version of libguestfs, then dynamically linked to an older version)). Please see attached main.c for my sample code.
I don't know about the above error,
Actually I've realized what's wrong that's giving the above error too.
guestfs_copy_device_to_file(g, "/dev/sda1/file-to extract.exe", "/abc.exe");
This API takes a variable list of parameters terminated with -1, and since you've omitted that, it's reading off the end of the args. http://libguestfs.org/guestfs.3.html#guestfs_copy_device_to_file You probably shouldn't be using that API so this doesn't matter, but it's best to clear it up. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://people.redhat.com/~rjones/virt-top
Thanks a lot. I was trying to copy on local disk and guestfs_download () solved my problem. Now I am trying to modify source code of guestfs_download () to extract file in memory. Can you guide me what should i do to achieve that. Mohsin On Fri, Feb 10, 2017 at 2:13 AM, Richard W.M. Jones <rjones@redhat.com> wrote:
On Thu, Feb 09, 2017 at 03:24:53PM +0500, MUHAMMAD MOHSIN wrote:
* but it returns following error (error: copy_device_to_file: unknown option 689330304 (this can happen if a program is compiled against a newer version of libguestfs, then dynamically linked to an older version)). Please see attached main.c for my sample code.
I don't know about the above error, but the way you've used copy-device-to-file is clearly wrong:
guestfs_mount (g, "/dev/sda1", "/");
//guestfs_mount_local (g, "/home/mohsin/VHD/"); guestfs_ls(g, "/"); guestfs_copy_device_to_file(g, "/dev/sda1/file-to extract.exe",
"/abc.exe");
It's actually not clear to me what you're trying to achieve here. Download the file to the local host? If so use guestfs_download:
guestfs_download (g, "/file-to-extract.exe", "local-file.exe");
BTW you should check for errors from C API calls.
http://libguestfs.org/guestfs.3.html#downloading http://libguestfs.org/guestfs.3.html#error-handling
Rich.
-- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~ rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-builder quickly builds VMs from scratch http://libguestfs.org/virt-builder.1.html
-- MUHAMMAD MOSHIN CIIT, ABBOTTABAD
Hi, On Monday, 13 February 2017 12:33:11 CET MUHAMMAD MOHSIN wrote:
Now I am trying to modify source code of guestfs_download () to extract file in memory.
There is no need to do that, since there is already an API for this: guestfs_read_file. For example, you can do: size_t file_size = 0; char *content = guestfs_read_file (g, "/path/in/the/guest", &file_size); 'content' will hold all the content of the file, and 'file_size' how many bytes are in the 'content' buffer). -- Pino Toscano
On Mon, Feb 13, 2017 at 12:33:11PM +0500, MUHAMMAD MOHSIN wrote:
Thanks a lot. I was trying to copy on local disk and guestfs_download () solved my problem. Now I am trying to modify source code of guestfs_download () to extract file in memory. Can you guide me what should i do to achieve that.
Use guestfs_pread maybe? Or guestfs_download with a target of /dev/mapper? It really depends what exactly you mean by "file in memory", however libguestfs (by design) cannot memory-map a file. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-df lists disk usage of guests without needing to install any software inside the virtual machine. Supports Linux and Windows. http://people.redhat.com/~rjones/virt-df/
participants (3)
-
MUHAMMAD MOHSIN -
Pino Toscano -
Richard W.M. Jones