#define BB_OFFSET(x)   (((x) & BB_OFFSET_MASK) >> 9)
 #define BB_LEN(x)      (((x) & BB_LEN_MASK) + 1)
 #define BB_ACK(x)      (!!((x) & BB_ACK_MASK))
+#define BB_END(x)      (BB_OFFSET(x) + BB_LEN(x))
 #define BB_MAKE(a, l, ack) (((a)<<9) | ((l)-1) | ((u64)(!!(ack)) << 63))
 
 /* Bad block numbers are stored sorted in a single page.
        sector_t size;          /* in sectors */
 };
 
+struct badblocks_context {
+       sector_t        start;
+       sector_t        len;
+       int             ack;
+};
+
 int badblocks_check(struct badblocks *bb, sector_t s, int sectors,
                   sector_t *first_bad, int *bad_sectors);
 int badblocks_set(struct badblocks *bb, sector_t s, int sectors,
        }
        badblocks_exit(bb);
 }
+
+static inline int badblocks_full(struct badblocks *bb)
+{
+       return (bb->count >= MAX_BADBLOCKS);
+}
+
+static inline int badblocks_empty(struct badblocks *bb)
+{
+       return (bb->count == 0);
+}
+
+static inline void set_changed(struct badblocks *bb)
+{
+       if (bb->changed != 1)
+               bb->changed = 1;
+}
+
+static inline void clear_changed(struct badblocks *bb)
+{
+       if (bb->changed != 0)
+               bb->changed = 0;
+}
+
 #endif