package gpt

  1. Overview
  2. Docs
A library to manipulate GUID Partition tables

Install

Dune Dependency

Authors

Maintainers

Sources

gpt-1.0.0.tbz
sha256=e2d78b11f8c3f168c9f84c7da4139a24ef472ef2dc6ad5a988e833fd589849d4
sha512=968e822c96220008143a8c0476343aaeaa9ff22034d6004554c2d978d9b753a272d17b15ea1229a5d4c12ebb880be5b46ce9048dbba72b0217f588ceb3d97830

Description

A longer description

Tags

mirage ocaml storage gpt

Published: 20 Feb 2024

README

ocaml-gpt

Introduction

This library provides functionality for working with the GUID Partition Table (GPT). It allows you to create, manipulate, and marshal/unmarshal GPT headers and partitions.

Dependencies

  • OCaml (version 4.02 or later)

  • dune (build system)

  • uuidm (library for UUID manipulation)

  • checkseum (library for checksum calculations)

  • ocaml-cstruct (library for working with C-like structures)

Installation

  1. Install OCaml and dune by following the instructions for your platform. Up and Running with Ocaml

  2. Install the required dependencies using OPAM (OCaml package manager)

opam install .
  1. Build the project using dune

dune build
  1. Run Test

dune build @runtest

Usage

Module: Partition

This module provides functions for working with GPT partitions.

Partition.make
val make :
  ?name:string ->
  type_guid:Uuidm.t ->
  attributes:int64 ->
  starting_lba:int64 ->
  ending_lba:int64 ->
  (Partition.t, string) result

This function creates a new GPT partition with the specified parameters. It returns a Partition.t value wrapped in the Result type, indicating success or failure. name should be a utf-16-le encoded string of length 72 bytes.

Partition.unmarshal
val unmarshal : Cstruct.t -> (Partition.t, string) result

This function takes a Cstruct.t buffer and unmarshals the data into a Partition.t value. It returns the unmarshalled partition wrapped in the Result type, indicating success or failure.

Partition.marshal
val marshal : Cstruct.t -> Partition.t -> unit

This function marshals a Partition.t value into a Cstruct.t buffer.

Module: Gpt

This module provides functions for working with GPT headers.

Gpt.make
val make :  ?disk_guid:Uuidm.t -> disk_size:int64 
            -> sector_size:int ->  Partition.t list -> (t, string) result

This function creates a new GPT header with the specified list of partitions. It returns a Gpt.t value wrapped in the Result type, indicating success or failure.

Gpt.unmarshal
val unmarshal : Cstruct.t -> sector_size:int -> (t, string) result

This function takes a Cstruct.t buffer and unmarshals the data into a Gpt.t value. It returns the unmarshalled GPT header wrapped in the Result type, indicating success or failure.

Gpt.marshal
val marshal : Cstruct.t -> t -> unit

This function marshals a Gpt.t value into a Cstruct.t buffer.

Example Usage

Here's an example of how you can use this library to create and manipulate GPT headers and partitions:

let create_gpt_header () =
  let partition1 = Match Partition.make ~name:"Partition 1" ~type_guid:"12345678-1234-1234-1234-123456789abc" ~attributes:0L 1L 100L
  with 
  | Ok p -> p
  | Error error -> Printf.eprintf "Error %s" error
  in
  match make [partition1] ~disk_size:1024L ~sector_size:512 with
  | Ok gpt -> gpt
  | Error error -> Printf.eprintf "Error %s" error

Tools

Inspect the GPT Header:

  • gpt_inspect.exe: This script prints the GPT header and it's corresponding partitions. It enables you inspect your GPT disks.

Usage
  dune exec -- bin/gpt_inspect.exe disk.img
  • disk.img corresponds to the disk or disk file image you wish to inspect

License

This libray is licensed with the Ocaml standard ISC license. See here License

Contributions

Please report bugs using the issue tracker at https://github.com/PizieDust/ocaml-gpt/issues

Dependencies (7)

  1. ocplib-endian >= "1.2"
  2. mbr-format >= "2.0.0"
  3. checkseum >= "0.4.0"
  4. uuidm >= "0.9.7"
  5. cstruct
  6. dune >= "3.7"
  7. ocaml >= "4.13.0"

Dev Dependencies (3)

  1. odoc with-doc
  2. fmt with-test
  3. alcotest with-test

Used by (1)

  1. gptar

Conflicts

None

OCaml

Innovation. Community. Security.