diff options
author | Richard W.M. Jones <rjones@redhat.com> | 2011-11-22 09:39:54 +0000 |
---|---|---|
committer | Richard W.M. Jones <rjones@redhat.com> | 2011-11-22 14:44:54 +0000 |
commit | 7e1b479f7e7fccc79a34caaf8349d6e941b8344e (patch) | |
tree | 449f9b47daea6c2553b97ae5253626455380e7ad | |
parent | 0b5f08137825803b3a9d3afe05a7462a6b652144 (diff) | |
download | libguestfs-7e1b479f7e7fccc79a34caaf8349d6e941b8344e.tar.gz libguestfs-7e1b479f7e7fccc79a34caaf8349d6e941b8344e.tar.xz libguestfs-7e1b479f7e7fccc79a34caaf8349d6e941b8344e.zip |
sparsify: Add auto-detection of .vdi files.
Note that for this to work properly, it requires a patch to
the 'file' command. See:
https://www.redhat.com/archives/libguestfs/2011-November/msg00120.html
(cherry picked from commit 342b4a55d056734a0344db8b4bcf1a90104a8a59)
-rw-r--r-- | sparsify/sparsify.ml | 2 | ||||
-rw-r--r-- | sparsify/utils.ml | 19 | ||||
-rw-r--r-- | sparsify/virt-sparsify.pod | 5 |
3 files changed, 23 insertions, 3 deletions
diff --git a/sparsify/sparsify.ml b/sparsify/sparsify.ml index 4782983d..956fccbe 100644 --- a/sparsify/sparsify.ml +++ b/sparsify/sparsify.ml @@ -274,6 +274,8 @@ let output_format = ); if string_prefix line "QEMU QCOW Image (v2)" then "qcow2" + else if string_find line "VirtualBox" >= 0 then + "vdi" else "raw" (* XXX guess *) diff --git a/sparsify/utils.ml b/sparsify/utils.ml index 4f5631d6..b7c531d8 100644 --- a/sparsify/utils.ml +++ b/sparsify/utils.ml @@ -57,6 +57,25 @@ let string_prefix str prefix = let n = String.length prefix in String.length str >= n && String.sub str 0 n = prefix +let rec string_find s sub = + let len = String.length s in + let sublen = String.length sub in + let rec loop i = + if i <= len-sublen then ( + let rec loop2 j = + if j < sublen then ( + if s.[i+j] = sub.[j] then loop2 (j+1) + else -1 + ) else + i (* found *) + in + let r = loop2 0 in + if r = -1 then loop (i+1) else r + ) else + -1 (* not found *) + in + loop 0 + let string_random8 = let chars = "abcdefghijklmnopqrstuvwxyz0123456789" in fun () -> diff --git a/sparsify/virt-sparsify.pod b/sparsify/virt-sparsify.pod index 9579640e..77467b61 100644 --- a/sparsify/virt-sparsify.pod +++ b/sparsify/virt-sparsify.pod @@ -113,11 +113,10 @@ Display help. Use C<output-format> as the format for the destination image. If this is not specified, then the input format is used. -Supported and known-working output formats are: C<raw>, C<qcow2>. +Supported and known-working output formats are: C<raw>, C<qcow2>, C<vdi>. You can also use any format supported by the L<qemu-img(1)> program, -eg. C<vdi> or C<vmdk>, but support for other formats is reliant on -qemu. +eg. C<vmdk>, but support for other formats is reliant on qemu. Specifying the I<--convert> option is usually a good idea, because then virt-sparsify doesn't need to try to guess the input format. |