From 0417560649434fc985896c84527fbdadbb06aa42 Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Wed, 21 Dec 2022 21:41:34 -0500 Subject: [PATCH] Get current metadata version from sysfs This changes the default version for the format command to be the currently supported version, via /sys/modules/bcachefs/parameters/version. Signed-off-by: Kent Overstreet --- cmd_format.c | 3 +++ libbcachefs.h | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/cmd_format.c b/cmd_format.c index 9feb3345..26a1cd9f 100644 --- a/cmd_format.c +++ b/cmd_format.c @@ -219,6 +219,9 @@ int cmd_format(int argc, char *argv[]) break; } + if (opts.version != bcachefs_metadata_version_current) + initialize = false; + if (!devices.nr) die("Please supply a device"); diff --git a/libbcachefs.h b/libbcachefs.h index 17e8eef3..4bb51bd8 100644 --- a/libbcachefs.h +++ b/libbcachefs.h @@ -41,8 +41,12 @@ struct format_opts { static inline struct format_opts format_opts_default() { + unsigned version = !access( "/sys/module/bcachefs/parameters/version", R_OK) + ? read_file_u64(AT_FDCWD, "/sys/module/bcachefs/parameters/version") + : bcachefs_metadata_version_current; + return (struct format_opts) { - .version = bcachefs_metadata_version_current, + .version = version, .superblock_size = SUPERBLOCK_SIZE_DEFAULT, }; }