Build Linux initramfs cpio archives from OCaml
at main 28 lines 1.3 kB view raw
1(*--------------------------------------------------------------------------- 2 Copyright (c) 2025 Thomas Gazagnaire. All rights reserved. 3 SPDX-License-Identifier: ISC 4 ---------------------------------------------------------------------------*) 5 6(** Build initramfs cpio archives. 7 8 High-level API for creating Linux initramfs images (cpio newc format) from 9 directories, files, and recursive directory trees. *) 10 11type entry = 12 | Dir of string (** Empty directory. *) 13 | File of { name : string; path : string } 14 (** File from disk, renamed to [name] in the archive. *) 15 | Content of { name : string; data : string; perm : int } 16 (** Inline content, stored as [name] with [perm] permissions. *) 17 | Tree of string (** Recursive directory tree. *) 18 19val build : entry list -> string 20(** [build entries] builds a cpio newc archive from [entries]. 21 22 - [Dir name] creates an empty directory with permissions 0o755. 23 - [File { name; path }] reads a file from [path] and stores it as [name], 24 preserving the original file permissions. 25 - [Content { name; data; perm }] stores inline [data] as [name] with [perm] 26 permissions. 27 - [Tree path] recursively walks [path], adding all files and subdirectories 28 as cpio entries, preserving permissions. *)