OCaml bindings to libpci using Ctypes
OCaml Other
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
bindings
examples
lib
lib_test
stubgen
.coverage.excludes
.docgen.sh
.gitignore
.merlin
.travis.yml
LICENSE
Makefile
README.md
_oasis
_tags
configure
myocamlbuild.ml
opam
pci.odocl
setup.ml

README.md

ocaml-pci

Build Status Coverage Status API reference

An OCaml library exposing an API over bindings to libpci.

This library uses Ctypes to generate type-safe bindings to libpci which is part of "The PCI Utilities" package shipped with most operating systems.

Rather than being a completely transparent set of bindings, this library exposes an API to wrap some of the composite functions to ensure correct memory allocation and cleanup. This should reduce memory leaks and segfaults which are possible with incorrect use of libpci.

Installation

The easiest way to install this library is to use opam:

opam install pci

However, if you don't use opam, you can compile from source by cloning this repo and executing the usual dance:

./configure
make
make install

Documentation

The API documentation for this library is automatically generated from source using ocamldoc and is available online.

Usage

There is an example of a minimal lspci clone in the examples/ directory. The interface is intended to be as simple as possible. Here is an example of listing the devices on your system:

open Pci
let devs = with_access get_devices in
List.iter (fun d ->
  let open Pci_dev in
  Printf.printf "Device: %04x:%02x:%02x.%d\n" d.domain d.bus d.dev d.func
) devs