1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _BCACHEFS_BBPOS_H
3#define _BCACHEFS_BBPOS_H
4
5#include "bbpos_types.h"
6#include "bkey_methods.h"
7#include "btree_cache.h"
8
9static inline int bbpos_cmp(struct bbpos l, struct bbpos r)
10{
11 return cmp_int(l.btree, r.btree) ?: bpos_cmp(l: l.pos, r: r.pos);
12}
13
14static inline struct bbpos bbpos_successor(struct bbpos pos)
15{
16 if (bpos_cmp(l: pos.pos, SPOS_MAX)) {
17 pos.pos = bpos_successor(p: pos.pos);
18 return pos;
19 }
20
21 if (pos.btree != BTREE_ID_NR) {
22 pos.btree++;
23 pos.pos = POS_MIN;
24 return pos;
25 }
26
27 BUG();
28}
29
30static inline void bch2_bbpos_to_text(struct printbuf *out, struct bbpos pos)
31{
32 prt_str(out, str: bch2_btree_id_str(pos.btree));
33 prt_char(out, c: ':');
34 bch2_bpos_to_text(out, pos.pos);
35}
36
37#endif /* _BCACHEFS_BBPOS_H */
38

source code of linux/fs/bcachefs/bbpos.h