123792a71SKent Overstreet /* SPDX-License-Identifier: GPL-2.0 */
223792a71SKent Overstreet #ifndef _BCACHEFS_BBPOS_H
323792a71SKent Overstreet #define _BCACHEFS_BBPOS_H
423792a71SKent Overstreet
5*d5eade93SKent Overstreet #include "bbpos_types.h"
623792a71SKent Overstreet #include "bkey_methods.h"
788dfe193SKent Overstreet #include "btree_cache.h"
823792a71SKent Overstreet
bbpos_cmp(struct bbpos l,struct bbpos r)923792a71SKent Overstreet static inline int bbpos_cmp(struct bbpos l, struct bbpos r)
1023792a71SKent Overstreet {
1123792a71SKent Overstreet return cmp_int(l.btree, r.btree) ?: bpos_cmp(l.pos, r.pos);
1223792a71SKent Overstreet }
1323792a71SKent Overstreet
bbpos_successor(struct bbpos pos)1423792a71SKent Overstreet static inline struct bbpos bbpos_successor(struct bbpos pos)
1523792a71SKent Overstreet {
1623792a71SKent Overstreet if (bpos_cmp(pos.pos, SPOS_MAX)) {
1723792a71SKent Overstreet pos.pos = bpos_successor(pos.pos);
1823792a71SKent Overstreet return pos;
1923792a71SKent Overstreet }
2023792a71SKent Overstreet
2123792a71SKent Overstreet if (pos.btree != BTREE_ID_NR) {
2223792a71SKent Overstreet pos.btree++;
2323792a71SKent Overstreet pos.pos = POS_MIN;
2423792a71SKent Overstreet return pos;
2523792a71SKent Overstreet }
2623792a71SKent Overstreet
2723792a71SKent Overstreet BUG();
2823792a71SKent Overstreet }
2923792a71SKent Overstreet
bch2_bbpos_to_text(struct printbuf * out,struct bbpos pos)3023792a71SKent Overstreet static inline void bch2_bbpos_to_text(struct printbuf *out, struct bbpos pos)
3123792a71SKent Overstreet {
3288dfe193SKent Overstreet prt_str(out, bch2_btree_id_str(pos.btree));
3323792a71SKent Overstreet prt_char(out, ':');
3423792a71SKent Overstreet bch2_bpos_to_text(out, pos.pos);
3523792a71SKent Overstreet }
3623792a71SKent Overstreet
3723792a71SKent Overstreet #endif /* _BCACHEFS_BBPOS_H */
38