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

Configure Feed

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

Port monorepo to latest ocaml-wire (opam pin)

Migrate all consumers to the new wire API:
- wire.c library → wire.3d (Wire_c → Wire_3d)
- Wire.struct_/module_ → Wire.Everparse.struct_/module_
- Wire.Codec: record/|+/seal → Codec.v with Field.v and $
- Wire.bf_uint* → Wire.U8/U16/U16be/U32/U32be
- Wire.UInt32 → Wire.Private.UInt32
- Wire.cases → Wire.lookup, Wire.map now uses labeled args
- Wire.Codec.decode now returns result
- Add wire pin to root.opam.template

+47 -29
+38 -25
lib/mbr.ml
··· 170 170 171 171 let sizeof = 16 172 172 173 + let decode_chs s = 174 + let heads = Char.code s.[0] in 175 + let y = Char.code s.[1] in 176 + let z = Char.code s.[2] in 177 + { Geometry.cylinders = (y lsl 2) lor z; heads; sectors = y land 0x3F } 178 + 179 + let f_status = Wire.Field.v "status" Wire.uint8 180 + 181 + let f_first_chs = 182 + Wire.Field.v "first_chs" (Wire.byte_array ~size:(Wire.int 3)) 183 + 184 + let f_ty = Wire.Field.v "type" Wire.uint8 185 + let f_last_chs = Wire.Field.v "last_chs" (Wire.byte_array ~size:(Wire.int 3)) 186 + let f_lba_start = Wire.Field.v "lba_start" Wire.uint32 187 + let f_sectors = Wire.Field.v "sectors" Wire.uint32 188 + 173 189 let codec = 174 - let open Wire.Codec in 175 - let decode_chs s = 176 - let heads = Char.code s.[0] in 177 - let y = Char.code s.[1] in 178 - let z = Char.code s.[2] in 179 - { Geometry.cylinders = (y lsl 2) lor z; heads; sectors = y land 0x3F } 180 - in 181 - record "MbrPartition" (fun status first_chs ty last_chs lba sectors -> 190 + Wire.Codec.v "MbrPartition" 191 + (fun status first_chs ty last_chs lba sectors -> 182 192 { 183 193 active = status = 0x80; 184 194 first_absolute_sector_chs = decode_chs first_chs; 185 195 ty; 186 196 last_absolute_sector_chs = decode_chs last_chs; 187 - first_absolute_sector_lba = Int32.of_int (Wire.UInt32.to_int lba); 188 - sectors = Int32.of_int (Wire.UInt32.to_int sectors); 197 + first_absolute_sector_lba = 198 + Int32.of_int (Wire.Private.UInt32.to_int lba); 199 + sectors = Int32.of_int (Wire.Private.UInt32.to_int sectors); 189 200 }) 190 - |+ field "status" Wire.uint8 (fun t -> if t.active then 0x80 else 0) 191 - |+ field "first_chs" 192 - (Wire.byte_array ~size:(Wire.int 3)) 193 - (fun _ -> "\000\000\000") 194 - |+ field "type" Wire.uint8 (fun t -> t.ty) 195 - |+ field "last_chs" 196 - (Wire.byte_array ~size:(Wire.int 3)) 197 - (fun _ -> "\000\000\000") 198 - |+ field "lba_start" Wire.uint32 (fun t -> 199 - Wire.UInt32.of_int (Int32.to_int t.first_absolute_sector_lba)) 200 - |+ field "sectors" Wire.uint32 (fun t -> 201 - Wire.UInt32.of_int (Int32.to_int t.sectors)) 202 - |> seal 201 + Wire.Codec. 202 + [ 203 + (f_status $ fun t -> if t.active then 0x80 else 0); 204 + (f_first_chs $ fun _ -> "\000\000\000"); 205 + (f_ty $ fun t -> t.ty); 206 + (f_last_chs $ fun _ -> "\000\000\000"); 207 + ( f_lba_start $ fun t -> 208 + Wire.Private.UInt32.of_int 209 + (Int32.to_int t.first_absolute_sector_lba) ); 210 + ( f_sectors $ fun t -> 211 + Wire.Private.UInt32.of_int (Int32.to_int t.sectors) ); 212 + ] 203 213 204 - let struct_ = Wire.Codec.to_struct codec 214 + let struct_ = Wire.Everparse.struct_of_codec codec 205 215 206 216 let unmarshal buf off = 207 217 let* () = ··· 212 222 sizeof) 213 223 else Ok () 214 224 in 215 - let p = Wire.Codec.decode codec buf off in 225 + let* p = 226 + Wire.Codec.decode codec buf off 227 + |> Result.map_error (Fmt.str "%a" Wire.pp_parse_error) 228 + in 216 229 if p.ty = 0x00 then 217 230 if bytes_all_zero buf off sizeof then Ok None 218 231 else Error "Non-zero empty partition type"
+1 -1
lib/mbr.mli
··· 72 72 val codec : t Wire.Codec.t 73 73 (** Wire codec for a 16-byte MBR partition entry. *) 74 74 75 - val struct_ : Wire.struct_ 75 + val struct_ : Wire.Everparse.struct_ 76 76 (** Wire struct definition for a partition entry. *) 77 77 end 78 78
+8 -3
test/test_mbr.ml
··· 116 116 ("make sorts partitions", `Quick, test_make_sorted); 117 117 ] 118 118 119 + let decode_exn codec buf off = 120 + match Wire.Codec.decode codec buf off with 121 + | Ok v -> v 122 + | Error e -> Alcotest.failf "decode: %a" Wire.pp_parse_error e 123 + 119 124 let test_partition_wire_size () = 120 125 Alcotest.(check int) 121 126 "partition wire_size" 16 ··· 129 134 in 130 135 let buf = Bytes.create 16 in 131 136 Wire.Codec.encode Mbr.Partition.codec p buf 0; 132 - let p' = Wire.Codec.decode Mbr.Partition.codec buf 0 in 137 + let p' = decode_exn Mbr.Partition.codec buf 0 in 133 138 Alcotest.(check bool) "active" p.active p'.active; 134 139 Alcotest.(check int) "ty" p.ty p'.ty; 135 140 Alcotest.(check int32) ··· 190 195 let p = ok (Mbr.Partition.make ~partition_type:ty 2048l 1024l) in 191 196 let buf = Bytes.create 16 in 192 197 Wire.Codec.encode Mbr.Partition.codec p buf 0; 193 - let p' = Wire.Codec.decode Mbr.Partition.codec buf 0 in 198 + let p' = decode_exn Mbr.Partition.codec buf 0 in 194 199 Alcotest.(check int) 195 200 (Fmt.str "%s (0x%02X) survives roundtrip" label ty) 196 201 ty p'.Mbr.Partition.ty) ··· 229 234 let p = ok (Mbr.Partition.make ~partition_type:0xEE 1l max_lba) in 230 235 let buf = Bytes.create 16 in 231 236 Wire.Codec.encode Mbr.Partition.codec p buf 0; 232 - let p' = Wire.Codec.decode Mbr.Partition.codec buf 0 in 237 + let p' = decode_exn Mbr.Partition.codec buf 0 in 233 238 Alcotest.(check int32) 234 239 "max sectors survives roundtrip" max_lba p'.Mbr.Partition.sectors; 235 240 Alcotest.(check int32)