Add EROFS library
This adds a library to write EROFS filesystems. It supports most of the non-deprecated features the
filesystem supports other than extended inodes (which have no benefits for most use cases where EROFS would be
appropriate). EROFS's variable-length extent compression is partially implemented but it requires an LZ4
compressor with support for fixed-size output which Go's https://github.com/pierrec/lz4 doesn't have. This means
that VLE compression is currently not wired up.
This will be used later as a replacement for our current initramfs-based root filesystem.
Test Plan: Has both integration and some unit tests. Confirmed working for our whole rootfs.
X-Origin-Diff: phab/D692
GitOrigin-RevId: 8c52b45ea05c617c80047e99c04c2b63e1b60c7c
diff --git a/metropolis/pkg/erofs/BUILD.bazel b/metropolis/pkg/erofs/BUILD.bazel
new file mode 100644
index 0000000..7014e87
--- /dev/null
+++ b/metropolis/pkg/erofs/BUILD.bazel
@@ -0,0 +1,39 @@
+load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
+load("//metropolis/test/ktest:ktest.bzl", "ktest")
+
+go_library(
+ name = "go_default_library",
+ srcs = [
+ "compression.go",
+ "defs.go",
+ "erofs.go",
+ "inode_types.go",
+ "uncompressed_inode_writer.go",
+ ],
+ importpath = "source.monogon.dev/metropolis/pkg/erofs",
+ visibility = ["//visibility:public"],
+ deps = ["@org_golang_x_sys//unix:go_default_library"],
+)
+
+go_test(
+ name = "go_default_test",
+ srcs = [
+ "compression_test.go",
+ "defs_test.go",
+ "erofs_test.go",
+ ],
+ embed = [":go_default_library"],
+ pure = "on", # keep
+ deps = [
+ "@com_github_stretchr_testify//assert:go_default_library",
+ "@com_github_stretchr_testify//require:go_default_library",
+ "@org_golang_x_sys//unix:go_default_library",
+ ],
+)
+
+ktest(
+ cmdline = "ramdisk_size=128",
+ initramfs_extra = "",
+ tester = ":go_default_test",
+ deps = [],
+)