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

Configure Feed

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

fix(mbr): replace Printf with Fmt in CLI tools (E205)

+24 -27
+16 -18
bin/mbr_inspect.ml
··· 1 1 open Cmdliner 2 2 3 3 let print_mbr_fields print_bootstrap_code mbr = 4 - Printf.printf "MBR fields:\n"; 4 + Fmt.pr "MBR fields:\n"; 5 5 if print_bootstrap_code then 6 - Printf.printf " bootstrap_code: %s\n" 6 + Fmt.pr " bootstrap_code: %s\n" 7 7 (String.concat "" 8 8 (List.init (String.length mbr.Mbr.bootstrap_code) (fun i -> 9 9 Fmt.str "%02x" (Char.code mbr.Mbr.bootstrap_code.[i])))); 10 - Printf.printf " original_physical_drive: %d\n" 11 - mbr.Mbr.original_physical_drive; 12 - Printf.printf " seconds: %d\n" mbr.Mbr.seconds; 13 - Printf.printf " minutes: %d\n" mbr.Mbr.minutes; 14 - Printf.printf " hours: %d\n" mbr.Mbr.hours; 15 - Printf.printf " disk_signature: %lx\n" mbr.Mbr.disk_signature; 10 + Fmt.pr " original_physical_drive: %d\n" mbr.Mbr.original_physical_drive; 11 + Fmt.pr " seconds: %d\n" mbr.Mbr.seconds; 12 + Fmt.pr " minutes: %d\n" mbr.Mbr.minutes; 13 + Fmt.pr " hours: %d\n" mbr.Mbr.hours; 14 + Fmt.pr " disk_signature: %lx\n" mbr.Mbr.disk_signature; 16 15 List.iteri 17 16 (fun i part -> 18 17 let chs_begin = part.Mbr.Partition.first_absolute_sector_chs in 19 18 let chs_end = part.Mbr.Partition.last_absolute_sector_chs in 20 - Printf.printf " Partition %d:\n" (i + 1); 21 - Printf.printf " bootable: %b\n" part.Mbr.Partition.active; 19 + Fmt.pr " Partition %d:\n" (i + 1); 20 + Fmt.pr " bootable: %b\n" part.Mbr.Partition.active; 22 21 let { Mbr.Geometry.cylinders; Mbr.Geometry.heads; Mbr.Geometry.sectors } = 23 22 chs_begin 24 23 in 25 - Printf.printf " chs_begin: (cylinders: %d, heads: %d, sectors: %d)\n" 24 + Fmt.pr " chs_begin: (cylinders: %d, heads: %d, sectors: %d)\n" 26 25 cylinders heads sectors; 27 - Printf.printf " ty: %02x\n" part.Mbr.Partition.ty; 26 + Fmt.pr " ty: %02x\n" part.Mbr.Partition.ty; 28 27 let { Mbr.Geometry.cylinders; Mbr.Geometry.heads; Mbr.Geometry.sectors } = 29 28 chs_end 30 29 in 31 - Printf.printf " chs_end: (cylinders: %d, heads: %d, sectors: %d)\n" 32 - cylinders heads sectors; 33 - Printf.printf " lba_begin: %ld\n" 34 - part.Mbr.Partition.first_absolute_sector_lba; 35 - Printf.printf " size_sectors: %ld\n" part.Mbr.Partition.sectors) 30 + Fmt.pr " chs_end: (cylinders: %d, heads: %d, sectors: %d)\n" cylinders 31 + heads sectors; 32 + Fmt.pr " lba_begin: %ld\n" part.Mbr.Partition.first_absolute_sector_lba; 33 + Fmt.pr " size_sectors: %ld\n" part.Mbr.Partition.sectors) 36 34 mbr.partitions 37 35 38 36 let read_mbrs print_bootstrap_code mbrs = ··· 45 43 match Mbr.of_string (Bytes.to_string buf) with 46 44 | Ok mbr -> print_mbr_fields print_bootstrap_code mbr 47 45 | Error msg -> 48 - Printf.printf "Failed to read MBR from %s: %s\n" mbr msg; 46 + Fmt.pr "Failed to read MBR from %s: %s\n" mbr msg; 49 47 exit 1) 50 48 mbrs 51 49
+1 -1
bin/read_partition.ml
··· 8 8 match Mbr.of_string (Bytes.to_string buf) with 9 9 | Ok mbr -> mbr 10 10 | Error msg -> 11 - Printf.printf "Failed to read MBR from %s: %s\n" mbr msg; 11 + Fmt.pr "Failed to read MBR from %s: %s\n" mbr msg; 12 12 exit 1 13 13 14 14 let partition_info mbr partition_num =
+3 -4
bin/resize_partition.ml
··· 8 8 match Mbr.of_string (Bytes.to_string buf) with 9 9 | Ok mbr -> (mbr, Mbr.sizeof) 10 10 | Error msg -> 11 - Printf.printf "Failed to read MBR from %s: %s\n" mbr msg; 11 + Fmt.pr "Failed to read MBR from %s: %s\n" mbr msg; 12 12 exit 1 13 13 14 14 let partition_info mbr partition_number = ··· 21 21 in 22 22 let num_sectors = Int32.to_int partition.Mbr.Partition.sectors in 23 23 let sector_size = 512 in 24 - Printf.printf "Current partition size: %d bytes\n" (num_sectors * sector_size); 24 + Fmt.pr "Current partition size: %d bytes\n" (num_sectors * sector_size); 25 25 (start_sector, sector_size) 26 26 27 27 let new_partition partition start_sector sector_size new_size = ··· 33 33 else 34 34 let new_num_sectors = new_size / sector_size in 35 35 let new_end_sector = start_sector + new_num_sectors in 36 - Printf.printf "New partition size: %d bytes\n" 37 - (new_num_sectors * sector_size); 36 + Fmt.pr "New partition size: %d bytes\n" (new_num_sectors * sector_size); 38 37 match 39 38 Mbr.Partition.make ~active:partition.Mbr.Partition.active 40 39 ~partition_type:partition.Mbr.Partition.ty
+4 -4
bin/write_partition.ml
··· 8 8 match Mbr.of_string (Bytes.to_string buf) with 9 9 | Ok mbr -> (mbr, Mbr.sizeof) 10 10 | Error msg -> 11 - Printf.printf "Failed to read MBR from %s: %s\n" mbr msg; 11 + Fmt.pr "Failed to read MBR from %s: %s\n" mbr msg; 12 12 exit 1 13 13 14 14 let partition_info mbr partition_num = ··· 58 58 in 59 59 let partition_size = num_sectors * sector_size in 60 60 Option.iter 61 - (fun data_size -> Printf.printf "Total input size: %d\n" data_size) 61 + (fun data_size -> Fmt.pr "Total input size: %d\n" data_size) 62 62 data_size; 63 - Printf.printf "Total Partition size: %d\n" partition_size; 63 + Fmt.pr "Total Partition size: %d\n" partition_size; 64 64 Option.iter 65 65 (fun data_size -> 66 66 if data_size > partition_size then 67 67 failwith "Input is too large for partition") 68 68 data_size; 69 - Printf.printf "\nBegin writing to partition:- \n"; 69 + Fmt.pr "\nBegin writing to partition:- \n"; 70 70 let oc = open_out_gen [ Open_wronly; Open_binary ] 0o644 mbr in 71 71 seek_out oc (start_sector * sector_size); 72 72 copy ic oc partition_size;