Re: [PATCH v2 3/9] initrd: add a generic mechanism to add fs detectors

From: Julian Stecklina
Date: Mon Mar 24 2025 - 05:35:36 EST


On Sat, 2025-03-22 at 21:34 +0100, Julian Stecklina via B4 Relay wrote:
>
>  #ifdef CONFIG_BLK_DEV_INITRD
>  extern void __init reserve_initrd_mem(void);
>  extern void wait_for_initramfs(void);
> +
> +/*
> + * Detect a filesystem on the initrd. You get 1 KiB (BLOCK_SIZE) of
> + * data to work with. The offset of the block is specified in
> + * initrd_fs_detect().
> + *
> + * @block_data: A pointer to BLOCK_SIZE of data
> + *
> + * Returns the size of the filesystem in bytes or 0, if the filesystem
> + * was not detected.
> + */
> +typedef size_t initrd_fs_detect_fn(void * const block_data);
> +
> +struct initrd_detect_fs {
> + initrd_fs_detect_fn *detect_fn;
> + loff_t detect_byte_offset;
> +};
> +
> +extern struct initrd_detect_fs __start_initrd_fs_detect[];
> +extern struct initrd_detect_fs __stop_initrd_fs_detect[];
> +
> +/*
> + * Add a filesystem detector for initrds. See the documentation of
> + * initrd_fs_detect_fn above.
> + */
> +#define initrd_fs_detect(fn, byte_offset) \
> + static const struct initrd_detect_fs __initrd_fs_detect_ ## fn \
> + __used __section("_initrd_fs_detect") = \
> + { .detect_fn = fn, .detect_byte_offset = byte_offset}
> +
>  #else
>  static inline void __init reserve_initrd_mem(void) {}
>  static inline void wait_for_initramfs(void) {}
> +
> +#define initrd_fs_detect(detectfn)

The !CONFIG_BLK_DEV_INITRD path is broken. Will fix in v3 and add it to my test
plan.

Julian