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, lzma, lzo, xz, lz4, and zstd compression
- Filesystem writer module for creating SquashFS images
- Pure OCaml, no external dependencies on squashfs-tools
Installation#
Install with opam:
$ opam install squashfs
If opam cannot find the package, it may not yet be released in the public
opam-repository. Add the overlay repository, then install it:
$ opam repo add samoht https://tangled.org/gazagnaire.org/opam-overlay.git
$ opam update
$ opam install squashfs
Usage#
let read_image data =
match Squashfs.of_string data with
| Error msg -> Fmt.epr "Error: %s@." msg
| Ok fs -> (
Fmt.pr "%a@." Squashfs.pp_superblock (Squashfs.superblock fs);
match Squashfs.readdir fs (Squashfs.root fs) with
| Error msg -> Fmt.epr "Error: %s@." msg
| Ok entries ->
List.iter
(fun e ->
Fmt.pr "%s (%a)@." e.Squashfs.name Squashfs.pp_file_type
e.Squashfs.file_type)
entries)
API#
Opening Images#
Squashfs.of_string- Open from string dataSquashfs.of_reader- Open from bytesrw reader
Navigation#
Squashfs.root- Get root directory inodeSquashfs.readdir- List directory entriesSquashfs.lookup- Look up entry by nameSquashfs.resolve- Resolve path to inode
File Operations#
Squashfs.read_file- Read file contentsSquashfs.read_link- Read symlink target
Inode Properties#
Squashfs.inode_type- File typeSquashfs.inode_mode- Permission bitsSquashfs.inode_size- File sizeSquashfs.inode_mtime- Modification time
Related Work#
- squashfs-tools - Reference C implementation
- go-squashfs - Go implementation
- rust-squashfs - Rust implementation
References#
Licence#
MIT License. See LICENSE.md for details.