format: Ensure bcachefs module is loaded before checking version

this prevents accidentally formatting with a version unsupported by the
running kernel

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
Kent Overstreet 2025-03-31 17:23:46 -04:00
parent 33483738c6
commit 3aa2a4c47c

View File

@ -54,6 +54,12 @@ static inline unsigned bcachefs_kernel_version(void)
static inline struct format_opts format_opts_default()
{
/*
* Ensure bcachefs module is loaded so we know the supported on disk
* format version:
*/
system("modprobe bcachefs > /dev/null 2>&1");
return (struct format_opts) {
.version = bcachefs_kernel_version() ?:
bcachefs_metadata_version_current,