mirage/ocaml-mbr

Name: ocaml-mbr

Owner: MirageOS

Description: A simple library for manipulating Master Boot Records

Created: 2013-11-01 15:19:53.0

Updated: 2017-12-08 00:54:02.0

Pushed: 2015-06-04 16:21:40.0

Homepage: null

Size: 365

Language: OCaml

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

ocaml-mbr

A simple library for manipulating Master Boot Records. The primary purposes of this library are:

  1. to create bootable disk images creating mirage kernels
  2. for mirage kernels to read the partition tables on attached disks
Usage

Define a single partition as follows:

let disk_length_bytes = Int32.(mul (mul 16l 1024l) 1024l) in
let disk_length_sectors = Int32.(div disk_length_bytes 512l) in

let start_sector = 2048l in
let length_sectors = Int32.sub disk_length_sectors start_sector in
let partition = Mbr.Partition.make ~active:true ~ty:6 start_sector length_sectors in
let mbr = Mbr.make [ partition ] in

You can write the MBR to sector zero of a block device `B` as follows:

B.connect id >>|= fun device ->
let sector = Cstruct.create 512 in
Mbr.marshal sector mbr;
B.write device 0L [ sector ] >>|= fun () ->

You can then create a Partition block device as follows:

let module Partition = Mbr_partition.Make(B) in
Partition.connect {
  Partition.b = device;
  start_sector = Int64.of_int32 start_sector;
  length_sectors = Int64.of_int32 length_sectors;
} >>= fun partition_or_error ->
To do items

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.