// SPDX-License-Identifier: GPL-2.0
#include "bcachefs.h"
#include "checksum.h"
#include "disk_groups.h"
#include "ec.h"
#include "error.h"
#include "journal.h"
#include "journal_sb.h"
#include "journal_seq_blacklist.h"
#include "recovery.h"
#include "replicas.h"
#include "quota.h"
#include "sb-clean.h"
#include "sb-counters.h"
#include "sb-downgrade.h"
#include "sb-errors.h"
#include "sb-members.h"
#include "super-io.h"
#include "super.h"
#include "trace.h"
#include "vstructs.h"
#include <linux/backing-dev.h>
#include <linux/sort.h>
static const struct blk_holder_ops bch2_sb_handle_bdev_ops = {
};
struct bch2_metadata_version {
u16 version;
const char *name;
};
static const struct bch2_metadata_version bch2_metadata_versions[] = {
#define x(n, v) { \
.version = v, \
.name = #n, \
},
BCH_METADATA_VERSIONS()
#undef x
};
void bch2_version_to_text(struct printbuf *out, unsigned v)
{
const char *str = "(unknown version)";
for (unsigned i = 0; i < ARRAY_SIZE(bch2_metadata_versions); i++)
if (bch2_metadata_versions[i].version == v) {
str = bch2_metadata_versions[i].name;
break;
}
prt_printf(out, "%u.%u: %s", BCH_VERSION_MAJOR(v), BCH_VERSION_MINOR(v), str);
}
unsigned bch2_latest_compatible_version(unsigned v)
{
if (!BCH_VERSION_MAJOR(v))
return v;
for (unsigned i = 0; i < ARRAY_SIZE(bch2_metadata_versions); i++)
if (bch2_metadata_versions[i].version > v &&
BCH_VERSION_MAJOR(bch2_metadata_versions[i].version) ==
BCH_VERSION_MAJOR(v))
v = bch2_metadata_versions[i].version;
return v;
}
const char * const bch2_sb_fields[] = {
#define x(name, nr) #name,
BCH_SB_FIELDS()
#undef x
NULL
};
static int bch2_sb_field_valida