bbpos.h 761 B

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