Re: [PATCH] initrd: support erofs as initrd

From: Christian Brauner
Date: Fri Mar 21 2025 - 04:46:45 EST


On Fri, Mar 21, 2025 at 02:08:26AM +0000, Al Viro wrote:
> On Thu, Mar 20, 2025 at 08:28:23PM +0100, Julian Stecklina via B4 Relay wrote:
> > From: Julian Stecklina <julian.stecklina@xxxxxxxxxxxxxxxxxxxxx>
> >
> > Add erofs detection to the initrd mount code. This allows systems to
> > boot from an erofs-based initrd in the same way as they can boot from
> > a squashfs initrd.
> >
> > Just as squashfs initrds, erofs images as initrds are a good option
> > for systems that are memory-constrained.
> >
> > Signed-off-by: Julian Stecklina <julian.stecklina@xxxxxxxxxxxxxxxxxxxxx>
>
> > #include "do_mounts.h"
> > #include "../fs/squashfs/squashfs_fs.h"
> > +#include "../fs/erofs/erofs_fs.h"
>
> This is getting really unpleasant...
>
> Folks, could we do something similar to initcalls - add a section
> (.init.text.rd_detect?) with array of pointers to __init functions
> that would be called by that thing in turn? With filesystems that
> want to add that kind of stuff being about to do something like
>
> static int __init detect_minix(struct file *file, void *buf, loff_t *pos, int start_block)
> {
> struct minix_super_block *minixsb = buf;
> initrd_fill_buffer(file, buf, pos, (start_block + 1) * BLOCK_SIZE);
> if (minixsb->s_magic == MINIX_SUPER_MAGIC ||
> minixsb->s_magic == MINIX_SUPER_MAGIC2) {
> printk(KERN_NOTICE
> "RAMDISK: Minix filesystem found at block %d\n",
> start_block);
> return minixsb->s_nzones << minixsb->s_log_zone_size;
> }
> return -1;
> }
>
> initrd_detect(detect_minix);
>
> with the latter emitting a pointer to detect_minix into that new
> section?
>
> initrd_fill_buffer() would be something along the lines of
>
> if (*pos != wanted) {
> *pos = wanted;
> kernel_read(file, buf, 512, pos);
> }
>
> I mean, we can keep adding those pieces there, but...

Very much agreed.