Skip to content

Commit 560661d

Browse files
author
Kent Overstreet
committed
bcachefs: prt_bitflags_vector()
similar to prt_bitflags(), but for ulong arrays Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
1 parent 6b49b0f commit 560661d

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

fs/bcachefs/printbuf.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// SPDX-License-Identifier: LGPL-2.1+
22
/* Copyright (C) 2022 Kent Overstreet */
33

4+
#include <linux/bitmap.h>
45
#include <linux/err.h>
56
#include <linux/export.h>
67
#include <linux/kernel.h>
@@ -423,3 +424,24 @@ void bch2_prt_bitflags(struct printbuf *out,
423424
flags ^= BIT_ULL(bit);
424425
}
425426
}
427+
428+
void bch2_prt_bitflags_vector(struct printbuf *out,
429+
const char * const list[],
430+
unsigned long *v, unsigned nr)
431+
{
432+
bool first = true;
433+
unsigned i;
434+
435+
for (i = 0; i < nr; i++)
436+
if (!list[i]) {
437+
nr = i - 1;
438+
break;
439+
}
440+
441+
for_each_set_bit(i, v, nr) {
442+
if (!first)
443+
bch2_prt_printf(out, ",");
444+
first = false;
445+
bch2_prt_printf(out, "%s", list[i]);
446+
}
447+
}

fs/bcachefs/printbuf.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ void bch2_prt_units_u64(struct printbuf *, u64);
124124
void bch2_prt_units_s64(struct printbuf *, s64);
125125
void bch2_prt_string_option(struct printbuf *, const char * const[], size_t);
126126
void bch2_prt_bitflags(struct printbuf *, const char * const[], u64);
127+
void bch2_prt_bitflags_vector(struct printbuf *, const char * const[],
128+
unsigned long *, unsigned);
127129

128130
/* Initializer for a heap allocated printbuf: */
129131
#define PRINTBUF ((struct printbuf) { .heap_allocated = true })

fs/bcachefs/util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ do { \
243243
#define prt_units_s64(...) bch2_prt_units_s64(__VA_ARGS__)
244244
#define prt_string_option(...) bch2_prt_string_option(__VA_ARGS__)
245245
#define prt_bitflags(...) bch2_prt_bitflags(__VA_ARGS__)
246+
#define prt_bitflags_vector(...) bch2_prt_bitflags_vector(__VA_ARGS__)
246247

247248
void bch2_pr_time_units(struct printbuf *, u64);
248249
void bch2_prt_datetime(struct printbuf *, time64_t);

0 commit comments

Comments
 (0)