/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * Copyright (C) 2019 Oracle. All Rights Reserved. * Author: Darrick J. Wong */ #ifndef __XFS_SCRUB_ARRAY_H__ #define __XFS_SCRUB_ARRAY_H__ struct xfbma { struct file *filp; size_t obj_size; uint64_t nr; }; struct xfbma *xfbma_init(size_t obj_size); void xfbma_destroy(struct xfbma *array); int xfbma_get(struct xfbma *array, uint64_t nr, void *ptr); int xfbma_set(struct xfbma *array, uint64_t nr, void *ptr); int xfbma_insert_anywhere(struct xfbma *array, void *ptr); bool xfbma_is_null(struct xfbma *array, void *ptr); int xfbma_nullify(struct xfbma *array, uint64_t nr); int xfbma_append(struct xfbma *array, void *ptr); uint64_t xfbma_length(struct xfbma *array); /* * Return codes for the array iterator function are 0 to continue iterating, * and non-zero to stop iterating. Any non-zero value will be passed up to the * iteration caller. The special value -ECANCELED can be used to stop * iteration, because the iterator never generates that error code on its own. */ typedef int (*xfbma_iter_fn)(const void *item, void *priv); int xfbma_iter_del(struct xfbma *array, xfbma_iter_fn iter_fn, void *priv); typedef int (*xfbma_cmp_fn)(const void *a, const void *b); int xfbma_sort(struct xfbma *array, xfbma_cmp_fn cmp_fn); #define foreach_xfbma_item(array, i, rec) \ for ((i) = 0; (i) < xfbma_length((array)); (i)++) \ if (xfbma_get((array), (i), &(rec)) == 0 && \ !xfbma_is_null((array), &(rec))) #endif /* __XFS_SCRUB_ARRAY_H__ */