1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (C) 2018-2023 Oracle. All Rights Reserved.
4 * Author: Darrick J. Wong <djwong@kernel.org>
5 */
6 #ifndef __XFS_SCRUB_AGB_BITMAP_H__
7 #define __XFS_SCRUB_AGB_BITMAP_H__
8
9 /* Bitmaps, but for type-checked for xfs_agblock_t */
10
11 struct xagb_bitmap {
12 struct xbitmap32 agbitmap;
13 };
14
xagb_bitmap_init(struct xagb_bitmap * bitmap)15 static inline void xagb_bitmap_init(struct xagb_bitmap *bitmap)
16 {
17 xbitmap32_init(&bitmap->agbitmap);
18 }
19
xagb_bitmap_destroy(struct xagb_bitmap * bitmap)20 static inline void xagb_bitmap_destroy(struct xagb_bitmap *bitmap)
21 {
22 xbitmap32_destroy(&bitmap->agbitmap);
23 }
24
xagb_bitmap_clear(struct xagb_bitmap * bitmap,xfs_agblock_t start,xfs_extlen_t len)25 static inline int xagb_bitmap_clear(struct xagb_bitmap *bitmap,
26 xfs_agblock_t start, xfs_extlen_t len)
27 {
28 return xbitmap32_clear(&bitmap->agbitmap, start, len);
29 }
xagb_bitmap_set(struct xagb_bitmap * bitmap,xfs_agblock_t start,xfs_extlen_t len)30 static inline int xagb_bitmap_set(struct xagb_bitmap *bitmap,
31 xfs_agblock_t start, xfs_extlen_t len)
32 {
33 return xbitmap32_set(&bitmap->agbitmap, start, len);
34 }
35
xagb_bitmap_test(struct xagb_bitmap * bitmap,xfs_agblock_t start,xfs_extlen_t * len)36 static inline bool xagb_bitmap_test(struct xagb_bitmap *bitmap,
37 xfs_agblock_t start, xfs_extlen_t *len)
38 {
39 return xbitmap32_test(&bitmap->agbitmap, start, len);
40 }
41
xagb_bitmap_disunion(struct xagb_bitmap * bitmap,struct xagb_bitmap * sub)42 static inline int xagb_bitmap_disunion(struct xagb_bitmap *bitmap,
43 struct xagb_bitmap *sub)
44 {
45 return xbitmap32_disunion(&bitmap->agbitmap, &sub->agbitmap);
46 }
47
xagb_bitmap_hweight(struct xagb_bitmap * bitmap)48 static inline uint32_t xagb_bitmap_hweight(struct xagb_bitmap *bitmap)
49 {
50 return xbitmap32_hweight(&bitmap->agbitmap);
51 }
xagb_bitmap_empty(struct xagb_bitmap * bitmap)52 static inline bool xagb_bitmap_empty(struct xagb_bitmap *bitmap)
53 {
54 return xbitmap32_empty(&bitmap->agbitmap);
55 }
56
xagb_bitmap_walk(struct xagb_bitmap * bitmap,xbitmap32_walk_fn fn,void * priv)57 static inline int xagb_bitmap_walk(struct xagb_bitmap *bitmap,
58 xbitmap32_walk_fn fn, void *priv)
59 {
60 return xbitmap32_walk(&bitmap->agbitmap, fn, priv);
61 }
62
63 int xagb_bitmap_set_btblocks(struct xagb_bitmap *bitmap,
64 struct xfs_btree_cur *cur);
65 int xagb_bitmap_set_btcur_path(struct xagb_bitmap *bitmap,
66 struct xfs_btree_cur *cur);
67
xagb_bitmap_count_set_regions(struct xagb_bitmap * b)68 static inline uint32_t xagb_bitmap_count_set_regions(struct xagb_bitmap *b)
69 {
70 return xbitmap32_count_set_regions(&b->agbitmap);
71 }
72
73 #endif /* __XFS_SCRUB_AGB_BITMAP_H__ */
74