From: Julian Stecklina <[email protected]>

Allow erofs to be used as a filesystem for initrds. It offers similar
advantages as squashfs, but with higher performance and arguably nicer
tooling. If we support squashfs, there is no reason not to support
erofs as well.

Suggested-by: Niklas Sturm <[email protected]>
Signed-off-by: Julian Stecklina <[email protected]>
---
 fs/erofs/Makefile |  5 +++++
 fs/erofs/initrd.c | 19 +++++++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/fs/erofs/Makefile b/fs/erofs/Makefile
index 
4331d53c7109550a0518f2ed8df456deecdd2f8c..cea46a51dea2b9e22e4ba1478dd30de3262fe6cb
 100644
--- a/fs/erofs/Makefile
+++ b/fs/erofs/Makefile
@@ -9,3 +9,8 @@ erofs-$(CONFIG_EROFS_FS_ZIP_DEFLATE) += decompressor_deflate.o
 erofs-$(CONFIG_EROFS_FS_ZIP_ZSTD) += decompressor_zstd.o
 erofs-$(CONFIG_EROFS_FS_BACKED_BY_FILE) += fileio.o
 erofs-$(CONFIG_EROFS_FS_ONDEMAND) += fscache.o
+
+# If we are built-in, we provide support for erofs on initrds.
+ifeq ($(CONFIG_EROFS_FS),y)
+erofs-objs += initrd.o
+endif
diff --git a/fs/erofs/initrd.c b/fs/erofs/initrd.c
new file mode 100644
index 
0000000000000000000000000000000000000000..e2bb313f55211a305e201f529d7da810898252ac
--- /dev/null
+++ b/fs/erofs/initrd.c
@@ -0,0 +1,19 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <linux/initrd.h>
+
+#include "internal.h"
+
+static size_t __init detect_erofs(void *block_data)
+{
+       struct erofs_super_block *erofsb = block_data;
+
+       BUILD_BUG_ON(sizeof(*erofsb) > BLOCK_SIZE);
+
+       if (le32_to_cpu(erofsb->magic) != EROFS_SUPER_MAGIC_V1)
+               return 0;
+
+       return le32_to_cpu(erofsb->blocks) << erofsb->blkszbits;
+}
+
+initrd_fs_detect(detect_erofs, EROFS_SUPER_OFFSET);

-- 
2.47.0



Reply via email to