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 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.