1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef _BCACHEFS_BBPOS_H 3 #define _BCACHEFS_BBPOS_H 4 5 #include "bkey_methods.h" 6 7 struct bbpos { 8 enum btree_id btree; 9 struct bpos pos; 10 }; 11 12 static inline struct bbpos BBPOS(enum btree_id btree, struct bpos pos) 13 { 14 return (struct bbpos) { btree, pos }; 15 } 16 17 #define BBPOS_MIN BBPOS(0, POS_MIN) 18 #define BBPOS_MAX BBPOS(BTREE_ID_NR - 1, POS_MAX) 19 20 static inline int bbpos_cmp(struct bbpos l, struct bbpos r) 21 { 22 return cmp_int(l.btree, r.btree) ?: bpos_cmp(l.pos, r.pos); 23 } 24 25 static inline struct bbpos bbpos_successor(struct bbpos pos) 26 { 27 if (bpos_cmp(pos.pos, SPOS_MAX)) { 28 pos.pos = bpos_successor(pos.pos); 29 return pos; 30 } 31 32 if (pos.btree != BTREE_ID_NR) { 33 pos.btree++; 34 pos.pos = POS_MIN; 35 return pos; 36 } 37 38 BUG(); 39 } 40 41 static inline void bch2_bbpos_to_text(struct printbuf *out, struct bbpos pos) 42 { 43 prt_str(out, bch2_btree_ids[pos.btree]); 44 prt_char(out, ':'); 45 bch2_bpos_to_text(out, pos.pos); 46 } 47 48 #endif /* _BCACHEFS_BBPOS_H */ 49