upstream: https://github.com/mirage/ocaml-mbr
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

gpt, mbr: Update CLI tools to use bytesrw API

- Update mbr_inspect, read_partition, write_partition, resize_partition
to use Mbr.of_string and Mbr.to_string instead of cstruct-based API
- Update gpt_inspect to use Gpt.of_string instead of cstruct-based API
- Remove cstruct dependency from bin/dune files

+10 -10
+1 -1
bin/dune
··· 1 1 (executables 2 2 (names mbr_inspect read_partition write_partition resize_partition) 3 - (libraries mbr cstruct cmdliner unix)) 3 + (libraries mbr cmdliner unix))
+4 -2
bin/mbr_inspect.ml
··· 4 4 Printf.printf "MBR fields:\n"; 5 5 if print_bootstrap_code then 6 6 Printf.printf " bootstrap_code: %s\n" 7 - (Cstruct.to_hex_string (Cstruct.of_string mbr.Mbr.bootstrap_code)); 7 + (String.concat "" 8 + (List.init (String.length mbr.Mbr.bootstrap_code) (fun i -> 9 + Printf.sprintf "%02x" (Char.code mbr.Mbr.bootstrap_code.[i])))); 8 10 Printf.printf " original_physical_drive: %d\n" 9 11 mbr.Mbr.original_physical_drive; 10 12 Printf.printf " seconds: %d\n" mbr.Mbr.seconds; ··· 40 42 let buf = Bytes.create Mbr.sizeof in 41 43 let () = really_input ic buf 0 Mbr.sizeof in 42 44 close_in ic; 43 - match Mbr.unmarshal (Cstruct.of_bytes buf) with 45 + match Mbr.of_string (Bytes.to_string buf) with 44 46 | Ok mbr -> print_mbr_fields print_bootstrap_code mbr 45 47 | Error msg -> 46 48 Printf.printf "Failed to read MBR from %s: %s\n" mbr msg;
+1 -1
bin/read_partition.ml
··· 5 5 let buf = Bytes.create Mbr.sizeof in 6 6 let () = really_input ic buf 0 Mbr.sizeof in 7 7 close_in ic; 8 - match Mbr.unmarshal (Cstruct.of_bytes buf) with 8 + match Mbr.of_string (Bytes.to_string buf) with 9 9 | Ok mbr -> mbr 10 10 | Error msg -> 11 11 Printf.printf "Failed to read MBR from %s: %s\n" mbr msg;
+3 -5
bin/resize_partition.ml
··· 5 5 let buf = Bytes.create Mbr.sizeof in 6 6 let () = really_input ic buf 0 Mbr.sizeof in 7 7 close_in ic; 8 - match Mbr.unmarshal (Cstruct.of_bytes buf) with 8 + match Mbr.of_string (Bytes.to_string buf) with 9 9 | Ok mbr -> (mbr, Mbr.sizeof) 10 10 | Error msg -> 11 11 Printf.printf "Failed to read MBR from %s: %s\n" mbr msg; ··· 70 70 let new_mbr = make_new_mbr mbr new_partition_table in 71 71 let oc = open_out_gen [ Open_wronly; Open_binary ] 0o644 disk in 72 72 seek_out oc 0; 73 - let buf = Cstruct.create Mbr.sizeof in 74 - Mbr.marshal buf new_mbr; 75 - let mbr_bytes = Cstruct.to_bytes buf in 76 - output oc mbr_bytes 0 Mbr.sizeof; 73 + let mbr_str = Mbr.to_string new_mbr in 74 + output_string oc mbr_str; 77 75 close_out_noerr oc 78 76 79 77 let mbr =
+1 -1
bin/write_partition.ml
··· 5 5 let buf = Bytes.create Mbr.sizeof in 6 6 let () = really_input ic buf 0 Mbr.sizeof in 7 7 close_in ic; 8 - match Mbr.unmarshal (Cstruct.of_bytes buf) with 8 + match Mbr.of_string (Bytes.to_string buf) with 9 9 | Ok mbr -> (mbr, Mbr.sizeof) 10 10 | Error msg -> 11 11 Printf.printf "Failed to read MBR from %s: %s\n" mbr msg;