SquashFS compressed filesystem reader in pure OCaml
OCaml 98.1%
Dune 0.6%
Other 1.3%
29 1 0

Clone this repository

https://tangled.org/gazagnaire.org/ocaml-squashfs https://tangled.org/did:plc:jhift2vwcxhou52p3sewcrpx/ocaml-squashfs
git@git.recoil.org:gazagnaire.org/ocaml-squashfs git@git.recoil.org:did:plc:jhift2vwcxhou52p3sewcrpx/ocaml-squashfs

For self-hosted knots, clone URLs may differ based on your setup.

Download tar.gz
README.md

squashfs#

SquashFS compressed filesystem reader in pure OCaml.

Overview#

SquashFS is a compressed read-only filesystem commonly used for:

  • Linux initramfs/initrd images
  • Container images (Docker, Snap packages)
  • Live CD/USB distributions
  • Embedded systems

This library provides read-only access to SquashFS 4.0 images.

Features#

  • Read SquashFS superblock and metadata
  • Navigate directory structure
  • Read file contents
  • Read symbolic link targets
  • Supports gzip compression (zstd planned)
  • Pure OCaml, no external dependencies on squashfs-tools

Installation#

opam install squashfs

Usage#

(* Open a SquashFS image *)
let data = (* read image file *) in
match Squashfs.of_string data with
| Error msg -> Printf.eprintf "Error: %s\n" msg
| Ok fs ->
    (* Print superblock info *)
    Format.printf "%a@." Squashfs.pp_superblock (Squashfs.superblock fs);

    (* List root directory *)
    match Squashfs.readdir fs (Squashfs.root fs) with
    | Error msg -> Printf.eprintf "Error: %s\n" msg
    | Ok entries ->
        List.iter (fun e ->
          Format.printf "%s (%a)@." e.Squashfs.name
            Squashfs.pp_file_type e.Squashfs.file_type
        ) entries

API#

Opening Images#

  • Squashfs.of_string - Open from string data
  • Squashfs.of_reader - Open from bytesrw reader
  • Squashfs.root - Get root directory inode
  • Squashfs.readdir - List directory entries
  • Squashfs.lookup - Look up entry by name
  • Squashfs.resolve - Resolve path to inode

File Operations#

  • Squashfs.read_file - Read file contents
  • Squashfs.read_link - Read symlink target

Inode Properties#

  • Squashfs.inode_type - File type
  • Squashfs.inode_mode - Permission bits
  • Squashfs.inode_size - File size
  • Squashfs.inode_mtime - Modification time

References#

Licence#

MIT License. See LICENSE.md for details.