# bitmap.h

```c
#ifndef __KERN_FS_SFS_BITMAP_H__
#define __KERN_FS_SFS_BITMAP_H__

#include <defs.h>


/*
 * Fixed-size array of bits. (Intended for storage management.)
 *
 * Functions:
 *     bitmap_create  - allocate a new bitmap object.
 *                      Returns NULL on error.
 *     bitmap_getdata - return pointer to raw bit data (for I/O).
 *     bitmap_alloc   - locate a cleared bit, set it, and return its index.
 *     bitmap_mark    - set a clear bit by its index.
 *     bitmap_unmark  - clear a set bit by its index.
 *     bitmap_isset   - return whether a particular bit is set or not.
 *     bitmap_destroy - destroy bitmap.
 */


struct bitmap;

struct bitmap *bitmap_create(uint32_t nbits);                     // allocate a new bitmap object.
int bitmap_alloc(struct bitmap *bitmap, uint32_t *index_store);   // locate a cleared bit, set it, and return its index.
bool bitmap_test(struct bitmap *bitmap, uint32_t index);          // return whether a particular bit is set or not.
void bitmap_free(struct bitmap *bitmap, uint32_t index);          // according index, set related bit to 1
void bitmap_destroy(struct bitmap *bitmap);                       // free memory contains bitmap
void *bitmap_getdata(struct bitmap *bitmap, size_t *len_store);   // return pointer to raw bit data (for I/O)

#endif /* !__KERN_FS_SFS_BITMAP_H__ */
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://oscourse-tsinghua.gitbook.io/ucore-analysis/ucore/kern/fs/sfs/bitmap_h.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
