Skip to content

Commit

Permalink
XSI-19 locate VHD footer based on file size
Browse files Browse the repository at this point in the history
I order to locate the footer in a VHD file or stream, the total length
of that file or stream must be known. This commit passes it when it is
known. This depends on a corresponding change in the ocaml-vhd library.

Signed-off-by: Christian Lindig <christian.lindig@citrix.com>
  • Loading branch information
jonludlam authored and lindig committed Aug 13, 2018
1 parent b982c45 commit f978789
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
19 changes: 11 additions & 8 deletions cli/get_vhd_vsize.ml
Expand Up @@ -14,16 +14,19 @@ let get_vhd_vsize filename =
| End -> return ()
| Cons (hd, tl) ->
begin match hd with
| Fragment.Footer x ->
let size = x.Footer.current_size in
Printf.printf "%Ld\n" size;
exit 0
| _ ->
()
| Fragment.Footer x ->
let size = x.Footer.current_size in
Printf.printf "%Ld\n" size;
exit 0
| _ ->
()
end;
tl () >>= fun x ->
loop x in
openstream (Input.of_fd (Vhd_format_lwt.IO.to_file_descr fd)) >>= fun stream ->
loop x
in
Vhd_format_lwt.IO.get_file_size filename >>= fun file_size ->
openstream (Some file_size)
(Input.of_fd (Vhd_format_lwt.IO.to_file_descr fd)) >>= fun stream ->
loop stream >>= fun () -> Vhd_format_lwt.IO.close fd

let _ =
Expand Down
5 changes: 3 additions & 2 deletions src/impl.ml
Expand Up @@ -108,7 +108,8 @@ let contents common filename =
end;
tl () >>= fun x ->
loop x in
openstream (Input.of_fd (Vhd_format_lwt.IO.to_file_descr fd)) >>= fun stream ->
Vhd_format_lwt.IO.get_file_size filename >>= fun size ->
openstream (Some size) (Input.of_fd (Vhd_format_lwt.IO.to_file_descr fd)) >>= fun stream ->
loop stream in
Lwt_main.run t;
`Ok ()
Expand Down Expand Up @@ -481,7 +482,7 @@ let serve_vhd_to_raw total_size c dest prezeroed progress _ _ =
(match !p with Some p -> p blocks_seen | None -> ());
tl () >>= loop block_size_sectors_shift this_block blocks_seen
| Cons (_, tl) -> tl () >>= loop block_size_sectors_shift last_block blocks_seen in
openstream c >>= fun stream ->
openstream (Some total_size) c >>= fun stream ->
loop 0 (-1L) 0L stream

let serve_tar_to_raw total_size c dest prezeroed progress expected_prefix ignore_checksums =
Expand Down

0 comments on commit f978789

Please sign in to comment.