1 // SPDX-License-Identifier: GPL-2.0
3 * Feature set bits and string conversion.
4 * Inspired by ext4's features compat/incompat/ro_compat related code.
9 #include "bcache_ondisk.h"
19 static struct feature feature_list[] = {
20 {BCH_FEATURE_INCOMPAT, BCH_FEATURE_INCOMPAT_LOG_LARGE_BUCKET_SIZE,
25 #define compose_feature_string(type) \
30 for (f = &feature_list[0]; f->compat != 0; f++) { \
31 if (f->compat != BCH_FEATURE_ ## type) \
33 if (BCH_HAS_ ## type ## _FEATURE(&c->cache->sb, f->mask)) { \
35 out += snprintf(out, buf + size - out, \
38 out += snprintf(out, buf + size - out, \
41 } else if (!first) { \
42 out += snprintf(out, buf + size - out, " "); \
45 out += snprintf(out, buf + size - out, "%s", f->string);\
47 if (BCH_HAS_ ## type ## _FEATURE(&c->cache->sb, f->mask)) \
48 out += snprintf(out, buf + size - out, "]"); \
53 out += snprintf(out, buf + size - out, "\n"); \
56 int bch_print_cache_set_feature_compat(struct cache_set *c, char *buf, int size)
59 compose_feature_string(COMPAT);
63 int bch_print_cache_set_feature_ro_compat(struct cache_set *c, char *buf, int size)
66 compose_feature_string(RO_COMPAT);
70 int bch_print_cache_set_feature_incompat(struct cache_set *c, char *buf, int size)
73 compose_feature_string(INCOMPAT);