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

Configure Feed

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

aos, uslp, gpt: drop unused FFI scaffolding and inline dead helpers

Same pattern as tc/tm/clcw: [struct_], [module_], [c_stubs],
[ml_stubs] are derived on the fly by the [c/gen.ml] generators via
[Wire.Everparse.schema codec], so the pre-materialized copies in
the main library are dead weight.

Also remove [decode_header] / [encode_header] in aos and uslp
(neither exposed in the .mli nor called internally; the full-frame
[decode] / [encode] path is the only public entry point) and the
unused [w_data_zone] field builder in aos, the dead variable-width
[be_uint] / [be_uint_map] / [fecf_to_string] helpers in uslp, and
the redundant [header_struct_] in gpt. The one exception is
[Gpt.signature]: move it up before the header codec and reuse it
in [f_signature] and [validate_signature] so the "EFI PART"
constant has exactly one definition.

Drive-by: the [Json.Error.to_string e] error-formatting pattern in
five interop tests never made sense (the error values are already
[string]); drop the wrapper. This was fallout from the in-progress
json restructure but is a trivial bug in the tests.

+14 -12
+3 -8
lib/gpt.ml
··· 128 128 (f_name $ fun t -> t.name); 129 129 ] 130 130 131 - let struct_ = Wire.Everparse.struct_of_codec codec 132 - 133 131 let unmarshal buf off = 134 132 if Bytes.length buf < off + sizeof then 135 133 Fmt.kstr invalid_arg "Partition entry too small: %d < %d" ··· 182 180 partitions_crc32; 183 181 } 184 182 183 + let signature = "EFI PART" 185 184 let f_signature = Wire.Field.v "signature" (Wire.byte_array ~size:(Wire.int 8)) 186 185 let f_revision = Wire.Field.v "revision" uint32_as_int32 187 186 let f_header_size = Wire.Field.v "header_size" uint32_as_int32 ··· 204 203 Wire.Codec.v "GptHeader" raw_header 205 204 Wire.Codec. 206 205 [ 207 - (f_signature $ fun _ -> "EFI PART"); 206 + (f_signature $ fun _ -> signature); 208 207 (f_revision $ fun h -> h.revision); 209 208 (f_header_size $ fun h -> h.header_size); 210 209 (f_header_crc32 $ fun h -> h.header_crc32); ··· 220 219 (f_partitions_crc32 $ fun h -> h.partitions_crc32); 221 220 ] 222 221 223 - let header_struct_ = Wire.Everparse.struct_of_codec header_codec 224 - 225 222 type t = { 226 223 revision : int32; 227 224 header_size : int32; ··· 243 240 Fmt.pf ppf "@[<v>GPT rev=%lx disk=%a lba=[%Ld..%Ld] partitions=%d@]" 244 241 t.revision Uuidm.pp t.disk_guid t.first_usable_lba t.last_usable_lba 245 242 (List.length t.partitions) 246 - 247 - let signature = "EFI PART" 248 243 249 244 let raw_header_of_t t = 250 245 { ··· 486 481 487 482 let validate_signature buf = 488 483 let sig_str = Bytes.sub_string buf 0 8 in 489 - match sig_str with "EFI PART" -> Ok () | x -> err_bad_signature x 484 + if sig_str = signature then Ok () else err_bad_signature sig_str 490 485 491 486 let validate_revision (raw : raw_header) = 492 487 if raw.revision = 0x010000l then Ok ()
+11 -4
test/test_gpt.ml
··· 226 226 in 227 227 let partition_table_len = String.length partition_table_str in 228 228 match Gpt.of_string header_str ~sector_size:512 with 229 - | Error e -> Alcotest.failf "Failed to parse marshalled gpt header: %s" e 229 + | Error e -> 230 + Alcotest.failf "Failed to parse marshalled gpt header: %s" 231 + e 230 232 | Ok (`Read_partition_table (_lba, sectors), k) -> ( 231 233 Fmt.pr "expected %d, got %d\n%!" (partition_table_len / 512) sectors; 232 234 Alcotest.(check int) ··· 235 237 sectors; 236 238 match k (Bytes.of_string partition_table_str) with 237 239 | Error e -> 238 - Alcotest.failf "Failed to parse marshalled partition table: %s" e 240 + Alcotest.failf "Failed to parse marshalled partition table: %s" 241 + e 239 242 | Ok unmarshalled -> 240 243 Alcotest.check gpt "unmarshalled equal to original" morig unmarshalled 241 244 ) ··· 536 539 | Error e -> Alcotest.failf "header parse failed: %s" e 537 540 | Ok (`Read_partition_table (_, _), k) -> ( 538 541 match k (Bytes.of_string pt_str) with 539 - | Error e -> Alcotest.failf "partition table parse failed: %s" e 542 + | Error e -> 543 + Alcotest.failf "partition table parse failed: %s" 544 + e 540 545 | Ok gpt' -> 541 546 Alcotest.(check int32) 542 547 "header_crc32 preserved" gpt.Gpt.header_crc32 gpt'.Gpt.header_crc32; ··· 594 599 Alcotest.(check int64) 595 600 "partition starts at first_usable_lba" fula 596 601 (List.hd gpt.Gpt.partitions).Gpt.Partition.starting_lba 597 - | Error e -> Alcotest.failf "partition at first_usable_lba should work: %s" e 602 + | Error e -> 603 + Alcotest.failf "partition at first_usable_lba should work: %s" 604 + e 598 605 599 606 let first_usable_lba_test_collection = 600 607 [