xref: /openbmc/linux/fs/xfs/scrub/bitmap.h (revision 178b48d588ea5424a54423dc9c406416de0547c8)
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_BITMAP_H__
7 #define __XFS_SCRUB_BITMAP_H__
8 
9 struct xbitmap_range {
10 	struct list_head	list;
11 	uint64_t		start;
12 	uint64_t		len;
13 };
14 
15 struct xbitmap {
16 	struct list_head	list;
17 };
18 
19 void xbitmap_init(struct xbitmap *bitmap);
20 void xbitmap_destroy(struct xbitmap *bitmap);
21 
22 int xbitmap_set(struct xbitmap *bitmap, uint64_t start, uint64_t len);
23 int xbitmap_disunion(struct xbitmap *bitmap, struct xbitmap *sub);
24 int xbitmap_set_btcur_path(struct xbitmap *bitmap,
25 		struct xfs_btree_cur *cur);
26 int xbitmap_set_btblocks(struct xbitmap *bitmap,
27 		struct xfs_btree_cur *cur);
28 uint64_t xbitmap_hweight(struct xbitmap *bitmap);
29 
30 /*
31  * Return codes for the bitmap iterator functions are 0 to continue iterating,
32  * and non-zero to stop iterating.  Any non-zero value will be passed up to the
33  * iteration caller.  The special value -ECANCELED can be used to stop
34  * iteration, because neither bitmap iterator ever generates that error code on
35  * its own.  Callers must not modify the bitmap while walking it.
36  */
37 typedef int (*xbitmap_walk_fn)(uint64_t start, uint64_t len, void *priv);
38 int xbitmap_walk(struct xbitmap *bitmap, xbitmap_walk_fn fn,
39 		void *priv);
40 
41 typedef int (*xbitmap_walk_bits_fn)(uint64_t bit, void *priv);
42 int xbitmap_walk_bits(struct xbitmap *bitmap, xbitmap_walk_bits_fn fn,
43 		void *priv);
44 
45 #endif	/* __XFS_SCRUB_BITMAP_H__ */
46