#define x(t, n) [n] = #t,
-const char * const bch2_metadata_versions[] = {
- BCH_METADATA_VERSIONS()
- NULL
-};
-
const char * const bch2_error_actions[] = {
BCH_ERROR_ACTIONS()
NULL
#include <linux/sysfs.h>
#include "bcachefs_format.h"
-extern const char * const bch2_metadata_versions[];
extern const char * const bch2_error_actions[];
extern const char * const bch2_sb_features[];
extern const char * const bch2_sb_compat[];
goto err;
}
- if (!c->opts.nochanges) {
- if (c->sb.version < bcachefs_metadata_required_upgrade_below) {
- bch_info(c, "version %s (%u) prior to %s (%u), upgrade and fsck required",
- bch2_metadata_versions[c->sb.version],
- c->sb.version,
- bch2_metadata_versions[bcachefs_metadata_required_upgrade_below],
- bcachefs_metadata_required_upgrade_below);
- c->opts.version_upgrade = true;
- c->opts.fsck = true;
- c->opts.fix_errors = FSCK_OPT_YES;
- }
+ if (!c->opts.nochanges &&
+ c->sb.version < bcachefs_metadata_required_upgrade_below) {
+ struct printbuf buf = PRINTBUF;
+
+ prt_str(&buf, "version ");
+ bch2_version_to_text(&buf, c->sb.version);
+ prt_str(&buf, " prior to ");
+ bch2_version_to_text(&buf, bcachefs_metadata_required_upgrade_below);
+ prt_str(&buf, ", upgrade and fsck required");
+
+ bch_info(c, "%s", buf.buf);
+ printbuf_exit(&buf);
+
+ c->opts.version_upgrade = true;
+ c->opts.fsck = true;
+ c->opts.fix_errors = FSCK_OPT_YES;
}
if (c->opts.fsck && c->opts.norecovery) {
static const struct blk_holder_ops bch2_sb_handle_bdev_ops = {
};
+static const char * const bch2_metadata_versions[] = {
+#define x(t, n) [n] = #t,
+ BCH_METADATA_VERSIONS()
+#undef x
+};
+
+void bch2_version_to_text(struct printbuf *out, unsigned v)
+{
+ const char *str = v < ARRAY_SIZE(bch2_metadata_versions)
+ ? bch2_metadata_versions[v]
+ : "(unknown version)";
+
+ prt_printf(out, "%u: %s", v, str);
+}
+
const char * const bch2_sb_fields[] = {
#define x(name, nr) #name,
BCH_SB_FIELDS()
prt_str(out, "Version:");
prt_tab(out);
- prt_printf(out, "%s", bch2_metadata_versions[le16_to_cpu(sb->version)]);
+ bch2_version_to_text(out, le16_to_cpu(sb->version));
prt_newline(out);
prt_printf(out, "Oldest version on disk:");
prt_tab(out);
- prt_printf(out, "%s", bch2_metadata_versions[le16_to_cpu(sb->version_min)]);
+ bch2_version_to_text(out, le16_to_cpu(sb->version_min));
prt_newline(out);
prt_printf(out, "Created:");
#include <asm/byteorder.h>
+void bch2_version_to_text(struct printbuf *, unsigned);
+
struct bch_sb_field *bch2_sb_field_get(struct bch_sb *, enum bch_sb_field_type);
struct bch_sb_field *bch2_sb_field_resize(struct bch_sb_handle *,
enum bch_sb_field_type, unsigned);
struct printbuf p = PRINTBUF;
bool first = true;
- prt_printf(&p, "mounted version=%s", bch2_metadata_versions[c->sb.version]);
+ prt_str(&p, "mounted version ");
+ bch2_version_to_text(&p, c->sb.version);
if (c->opts.read_only) {
prt_str(&p, " opts=");