package gpt

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type
module Partition : sig ... end
type t = private {
  1. revision : int32;
  2. header_size : int32;
  3. header_crc32 : int32;
  4. reserved : int32;
  5. current_lba : int64;
  6. backup_lba : int64;
  7. first_usable_lba : int64;
  8. last_usable_lba : int64;
  9. disk_guid : Uuidm.t;
  10. partition_entry_lba : int64;
  11. num_partition_entries : int32;
  12. partition_size : int32;
  13. partitions_crc32 : int32;
  14. partitions : Partition.t list;
}
val make : ?disk_guid:Uuidm.t -> disk_sectors:int64 -> sector_size:int -> Partition.t list -> (t, string) result

make ?disk_guid ~disk_sectors ~sector_size partitions constructs a GPT given a desired list of partitions. The header is assumed to be written in LBA 1, and the partition table is written from LBA 2 with 128 partition entries allocated. The backup header is assumed written in the last LBA. An Error _ is returned if the number of partitions exceeds 128, or any of the partitions overlap with each other or the first sector,

The optional argument disk_guid specifies the disk guid to be written in the GPT. If disk_guid is not provided, a random value is used.

val unmarshal : Cstruct.t -> sector_size:int -> ([ `Read_partition_table of int64 * int ] * (Cstruct.t -> (t, string) result), string) result

unmarshal ~sector_size buf on success is a pair (`Read_partition (lba, num_sectors), k) where lba is the logical block address (sector) to read num_sectors sectors of the partition table. The bytes read should then be passed to k which then on success returns the GPT header and the partition table. An Error _ is returned when any field has an unexpected value or the checksums are wrong.

val marshal_header : sector_size:int -> primary:bool -> Cstruct.t -> t -> unit

marshal_header ~sector_size ~primary buf t serializes the GPT header to buf. The caller is expected to write the contents of buf to t.current_lba and t.backup_lba. If primary is true (default) t is marshaled as is. Otherwise t.current_lba and t.backup_lba are swapped and t.header_crc32 is recomputedd.

val marshal_partition_table : sector_size:int -> Cstruct.t -> t -> unit

marshal_partition_table ~sector_size buf t serializes the GPT partition table to buf. The caller is expected to write the contents of buf to t.partition_entry_lba.

val protective_mbr : sector_size:int -> t -> Mbr.t

protective_mbr ~sector_size t is the protective MBR written at LBA 0 for GPT header t using sector_size byte sector size.

OCaml

Innovation. Community. Security.