1 /*
2  * Copyright (c) 2023 Antmicro <www.antmicro.com>
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef __EXT2_BITMAP_H__
8 #define __EXT2_BITMAP_H__
9 
10 #include <stdint.h>
11 #include <stdbool.h>
12 
13 /* Functions to make operations on bitmaps.
14  *
15  * NOTICE: Assumed size of the bitmap is 256 B (1024 bits).
16  *         (Hence, the greatest valid index is 1023.)
17  */
18 
19 /**
20  * @brief Set bit at given index to one
21  *
22  * @param bm Pointer to bitmap
23  * @param index Index in bitmap
24  * @param size Size of bitmap in bytes
25  *
26  * @retval 0 on success;
27  * @retval -EINVAL when index is too big;
28  */
29 int ext2_bitmap_set(uint8_t *bm, uint32_t index, uint32_t size);
30 
31 /**
32  * @brief Set bit at given index to zero
33  *
34  * @param bm Pointer to bitmap
35  * @param index Index in bitmap
36  * @param size Size of bitmap in bytes
37  *
38  * @retval 0 on success;
39  * @retval -EINVAL when index is too big;
40  */
41 int ext2_bitmap_unset(uint8_t *bm, uint32_t index, uint32_t size);
42 
43 /**
44  * @brief Find first bit set to zero in bitmap
45  *
46  * @param bm Pointer to bitmap
47  * @param size Size of bitmap in bytes
48  *
49  * @retval >0 found inode number;
50  * @retval -ENOSPC when not found;
51  */
52 int32_t ext2_bitmap_find_free(uint8_t *bm, uint32_t size);
53 
54 /**
55  * @brief Helper function to count bits set in bitmap
56  *
57  * @param bm Pointer to bitmap
58  * @param size Size of bitmap in bits
59  *
60  * @retval Number of set bits in bitmap;
61  */
62 uint32_t ext2_bitmap_count_set(uint8_t *bm, uint32_t size);
63 
64 #endif /* __EXT2_BITMAP_H__ */
65