Skip to content

Commit b2b80aa

Browse files
committed
qcow-stream-tool: Drop read_headers
qemu-img is now used to determine allocated clusters, so this command is no longer needed. Signed-off-by: Andrii Sultanov <andriy.sultanov@vates.tech>
1 parent e93391f commit b2b80aa

1 file changed

Lines changed: 1 addition & 51 deletions

File tree

ocaml/qcow-stream-tool/qcow_stream_tool.ml

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -4,52 +4,13 @@ module Impl = struct
44
let stream_decode output =
55
Qcow_stream.stream_decode Unix.stdin output ;
66
`Ok ()
7-
8-
let read_headers qcow_path =
9-
let open Lwt.Syntax in
10-
let t =
11-
let* fd = Lwt_unix.openfile qcow_path [Unix.O_RDONLY] 0 in
12-
let* virtual_size, cluster_bits, _, data_cluster_map =
13-
Qcow_stream.start_stream_decode fd
14-
in
15-
(* TODO: List.map becomes tail-recursive in OCaml 5.1, and could be used here instead *)
16-
let clusters =
17-
data_cluster_map
18-
|> Qcow_types.Cluster.Map.to_seq
19-
|> Seq.map (fun (_, virt_address) ->
20-
let ( >> ) = Int64.shift_right_logical in
21-
let address =
22-
Int64.to_int (virt_address >> Int32.to_int cluster_bits)
23-
in
24-
`Int address
25-
)
26-
|> List.of_seq
27-
in
28-
let json =
29-
`Assoc
30-
[
31-
("virtual_size", `Int (Int64.to_int virtual_size))
32-
; ("cluster_bits", `Int (Int32.to_int cluster_bits))
33-
; ("data_clusters", `List clusters)
34-
]
35-
in
36-
let json_string = Yojson.to_string json in
37-
let* () = Lwt_io.print json_string in
38-
let* () = Lwt_io.flush Lwt_io.stdout in
39-
Lwt.return_unit
40-
in
41-
Lwt_main.run t ; `Ok ()
427
end
438

449
module Cli = struct
4510
let output default =
4611
let doc = Printf.sprintf "Path to the output file." in
4712
Arg.(value & pos 0 string default & info [] ~doc)
4813

49-
let input =
50-
let doc = Printf.sprintf "Path to the input file." in
51-
Arg.(required & pos 0 (some string) None & info [] ~doc)
52-
5314
let stream_decode_cmd =
5415
let doc = "decode qcow2 formatted data from stdin and write a raw image" in
5516
let man =
@@ -62,18 +23,7 @@ module Cli = struct
6223
(Cmd.info "stream_decode" ~doc ~man)
6324
Term.(ret (const Impl.stream_decode $ output "test.raw"))
6425

65-
let read_headers_cmd =
66-
let doc =
67-
"Determine allocated clusters by parsing qcow2 file at the provided \
68-
path. Returns JSON like the following: {'virtual_size': X, \
69-
'cluster_bits': Y, 'data_clusters': [1,2,3]}"
70-
in
71-
let man = [`S "DESCRIPTION"; `P doc] in
72-
Cmd.v
73-
(Cmd.info "read_headers" ~doc ~man)
74-
Term.(ret (const Impl.read_headers $ input))
75-
76-
let cmds = [stream_decode_cmd; read_headers_cmd]
26+
let cmds = [stream_decode_cmd]
7727
end
7828

7929
let info =

0 commit comments

Comments
 (0)