RTEMS  5.1
Data Structures | Macros | Typedefs | Functions

RTEMS File Systems Bitmap Routines. More...

#include <rtems/rfs/rtems-rfs-buffer.h>
#include <rtems/rfs/rtems-rfs-file-system-fwd.h>
#include <rtems/rfs/rtems-rfs-trace.h>

Go to the source code of this file.

Data Structures

struct  rtems_rfs_bitmap_control_s
 

Macros

#define RTEMS_RFS_BITMAP_CLEAR_ZERO   0
 
#define RTEMS_RFS_BITMAP_BIT_CLEAR   1
 
#define RTEMS_RFS_BITMAP_BIT_SET   0
 
#define RTEMS_RFS_BITMAP_ELEMENT_SET   (0)
 
#define RTEMS_RFS_BITMAP_ELEMENT_CLEAR   (RTEMS_RFS_BITMAP_ELEMENT_FULL_MASK)
 
#define RTEMS_RFS_BITMAP_SET_BITS(_t, _b)   ((_t) & ~(_b))
 
#define RTEMS_RFS_BITMAP_CLEAR_BITS(_t, _b)   ((_t) | (_b))
 
#define RTEMS_RFS_BITMAP_TEST_BIT(_t, _b)   (((_t) & (1 << (_b))) == 0 ? true : false)
 
#define RTEMS_RFS_BITMAP_INVERT_MASK(_mask)   (~(_mask))
 
#define RTEMS_RFS_BITMAP_ELEMENT_FULL_MASK   (0xffffffffUL)
 
#define RTEMS_RFS_BITMAP_SEARCH_WINDOW   (rtems_rfs_bitmap_element_bits () * 64)
 
#define RTEMS_RFS_ELEMENT_BITS_POWER_2   (5)
 
#define rtems_rfs_bitmap_numof_bits(_bytes)   (8 * (_bytes))
 
#define rtems_rfs_bitmap_element_bits()   rtems_rfs_bitmap_numof_bits (sizeof (rtems_rfs_bitmap_element))
 
#define rtems_rfs_bitmap_search_element_bits()   (rtems_rfs_bitmap_element_bits() * rtems_rfs_bitmap_element_bits())
 
#define rtems_rfs_bitmap_elements(_bits)   ((((_bits) - 1) / rtems_rfs_bitmap_element_bits()) + 1)
 
#define rtems_rfs_bitmap_release_buffer(_fs, _bm)   rtems_rfs_buffer_handle_release (_fs, (_bm)->buffer)
 
#define rtems_rfs_bitmap_map_index(_b)   ((_b) >> RTEMS_RFS_ELEMENT_BITS_POWER_2)
 
#define rtems_rfs_bitmap_map_offset(_b)   ((_b) & ((1 << RTEMS_RFS_ELEMENT_BITS_POWER_2) - 1))
 
#define rtems_rfs_bitmap_map_size(_c)   ((_c)->size)
 
#define rtems_rfs_bitmap_map_free(_c)   ((_c)->free)
 
#define rtems_rfs_bitmap_map_handle(_c)   ((_c)->buffer)
 
#define rtems_rfs_bitmap_map_block(_c)   ((_c)->block)
 

Typedefs

typedef int32_t rtems_rfs_bitmap_bit
 
typedef uint32_t rtems_rfs_bitmap_element
 
typedef rtems_rfs_bitmap_elementrtems_rfs_bitmap_map
 
typedef struct rtems_rfs_bitmap_control_s rtems_rfs_bitmap_control
 

Functions

rtems_rfs_bitmap_element rtems_rfs_bitmap_mask (unsigned int size)
 
rtems_rfs_bitmap_element rtems_rfs_bitmap_mask_section (unsigned int start, unsigned int end)
 
int rtems_rfs_bitmap_map_set (rtems_rfs_bitmap_control *control, rtems_rfs_bitmap_bit bit)
 
int rtems_rfs_bitmap_map_clear (rtems_rfs_bitmap_control *control, rtems_rfs_bitmap_bit bit)
 
int rtems_rfs_bitmap_map_test (rtems_rfs_bitmap_control *control, rtems_rfs_bitmap_bit bit, bool *state)
 
int rtems_rfs_bitmap_map_set_all (rtems_rfs_bitmap_control *control)
 
int rtems_rfs_bitmap_map_clear_all (rtems_rfs_bitmap_control *control)
 
int rtems_rfs_bitmap_map_alloc (rtems_rfs_bitmap_control *control, rtems_rfs_bitmap_bit seed, bool *allocate, rtems_rfs_bitmap_bit *bit)
 
int rtems_rfs_bitmap_create_search (rtems_rfs_bitmap_control *control)
 
int rtems_rfs_bitmap_open (rtems_rfs_bitmap_control *control, rtems_rfs_file_system *fs, rtems_rfs_buffer_handle *buffer, size_t size, rtems_rfs_buffer_block block)
 
int rtems_rfs_bitmap_close (rtems_rfs_bitmap_control *control)
 

Detailed Description

RTEMS File Systems Bitmap Routines.

RTEMS File Systems Bitmap Routines.

These functions manage bit maps. A bit map consists of the map of bit allocated in a block and a search map where a bit represents 32 actual bits. The search map allows for a faster search for an available bit as 32 search bits can checked in a test.

Macro Definition Documentation

◆ RTEMS_RFS_BITMAP_CLEAR_ZERO

#define RTEMS_RFS_BITMAP_CLEAR_ZERO   0

Define the way the bits are configured. We can have them configured as clear being 0 or clear being 1. This does not effect how masks are defined. A mask always has a 1 for set and 0 for clear.

◆ rtems_rfs_bitmap_element_bits

#define rtems_rfs_bitmap_element_bits ( )    rtems_rfs_bitmap_numof_bits (sizeof (rtems_rfs_bitmap_element))

Return the number of bits for the number of bytes provided. The search element and the element must have the same number of bits.

◆ RTEMS_RFS_BITMAP_ELEMENT_FULL_MASK

#define RTEMS_RFS_BITMAP_ELEMENT_FULL_MASK   (0xffffffffUL)

This is the full mask of the length of the element. A mask is always a 1 for set and 0 for clear. It is not effected by the state of RTEMS_RFS_BITMAP_CLEAR_ZERO.

◆ rtems_rfs_bitmap_elements

#define rtems_rfs_bitmap_elements (   _bits)    ((((_bits) - 1) / rtems_rfs_bitmap_element_bits()) + 1)

Return the number of elements for a given number of bits.

◆ RTEMS_RFS_BITMAP_INVERT_MASK

#define RTEMS_RFS_BITMAP_INVERT_MASK (   _mask)    (~(_mask))

Invert a mask. Masks are always 1 for set and 0 for clear.

◆ rtems_rfs_bitmap_map_block

#define rtems_rfs_bitmap_map_block (   _c)    ((_c)->block)

Return the bitmap map block.

◆ rtems_rfs_bitmap_map_free

#define rtems_rfs_bitmap_map_free (   _c)    ((_c)->free)

Return the number of free bits in the bitmap.

◆ rtems_rfs_bitmap_map_handle

#define rtems_rfs_bitmap_map_handle (   _c)    ((_c)->buffer)

Return the buffer handle.

◆ rtems_rfs_bitmap_map_index

#define rtems_rfs_bitmap_map_index (   _b)    ((_b) >> RTEMS_RFS_ELEMENT_BITS_POWER_2)

Return the element index for a given bit. We use a macro to hide any implementation assuptions. Typically this would be calculated by dividing the bit index by the number of bits in an element. Given we have a power of 2 as the number of bits we can avoid the division by using a shift. A good compiler should figure this out but I would rather enforce this than rely on the specific backend of a compiler to do the right thing.

◆ rtems_rfs_bitmap_map_offset

#define rtems_rfs_bitmap_map_offset (   _b)    ((_b) & ((1 << RTEMS_RFS_ELEMENT_BITS_POWER_2) - 1))

Return the bit offset for a given bit in an element in a map. See rtems_rfs_bitmap_map_index for a detailed reason why.

◆ rtems_rfs_bitmap_map_size

#define rtems_rfs_bitmap_map_size (   _c)    ((_c)->size)

Return the size of the bitmap.

◆ rtems_rfs_bitmap_numof_bits

#define rtems_rfs_bitmap_numof_bits (   _bytes)    (8 * (_bytes))

Return the number of bits for the number of bytes provided.

◆ rtems_rfs_bitmap_release_buffer

#define rtems_rfs_bitmap_release_buffer (   _fs,
  _bm 
)    rtems_rfs_buffer_handle_release (_fs, (_bm)->buffer)

Release the bitmap buffer back to the buffer pool or cache.

◆ rtems_rfs_bitmap_search_element_bits

#define rtems_rfs_bitmap_search_element_bits ( )    (rtems_rfs_bitmap_element_bits() * rtems_rfs_bitmap_element_bits())

Return the number of bits a search element covers.

◆ RTEMS_RFS_BITMAP_SEARCH_WINDOW

#define RTEMS_RFS_BITMAP_SEARCH_WINDOW   (rtems_rfs_bitmap_element_bits () * 64)

The bitmap search window. Searches occur around a seed in either direction for half the window.

◆ RTEMS_RFS_ELEMENT_BITS_POWER_2

#define RTEMS_RFS_ELEMENT_BITS_POWER_2   (5)

The power of 2 number of bits in the element.

Typedef Documentation

◆ rtems_rfs_bitmap_bit

typedef int32_t rtems_rfs_bitmap_bit

A bit in a map.

◆ rtems_rfs_bitmap_control

The bitmap control is a simple way to manage the various parts of a bitmap.

◆ rtems_rfs_bitmap_element

typedef uint32_t rtems_rfs_bitmap_element

The basic element of a bitmap. A bitmap is manipulated by elements.

◆ rtems_rfs_bitmap_map

A bitmap or map is an array of bitmap elements.

Function Documentation

◆ rtems_rfs_bitmap_close()

int rtems_rfs_bitmap_close ( rtems_rfs_bitmap_control control)

Close a bitmap.

Parameters
[in]controlis the bit map control.
Return values
0Successful operation.
error_codeAn error occurred.

◆ rtems_rfs_bitmap_create_search()

int rtems_rfs_bitmap_create_search ( rtems_rfs_bitmap_control control)

Create a search bit map from the actual bit map.

Parameters
[in]controlis the map control.
Return values
0Successful operation.
error_codeAn error occurred.

◆ rtems_rfs_bitmap_map_alloc()

int rtems_rfs_bitmap_map_alloc ( rtems_rfs_bitmap_control control,
rtems_rfs_bitmap_bit  seed,
bool *  allocate,
rtems_rfs_bitmap_bit bit 
)

Find a free bit searching from the seed up and down until found. The search is performing by moving up from the seed for the window distance then to search down from the seed for the window distance. This is repeated out from the seed for each window until a free bit is found. The search is performed by checking the search map to see if the map has a free bit.

Parameters
[in]controlis the map control.
[in]seedis the bit to search out from.
[out]allocateA bit was allocated.
[out]bitwill contain the bit found free if true is returned.
Return values
0Successful operation.
error_codeAn error occurred.

◆ rtems_rfs_bitmap_map_clear()

int rtems_rfs_bitmap_map_clear ( rtems_rfs_bitmap_control control,
rtems_rfs_bitmap_bit  bit 
)

Clear a bit in a map and make sure the search map bit is clear so a search will find this bit available.

Parameters
[in]controlis the control for the map.
[in]bitis the bit in the map to clear.
Return values
0Successful operation.
error_codeAn error occurred.

◆ rtems_rfs_bitmap_map_clear_all()

int rtems_rfs_bitmap_map_clear_all ( rtems_rfs_bitmap_control control)

Clear all bits in the bitmap and set the dirty bit.

Parameters
[in]controlis the bitmap control.
Return values
0Successful operation.
error_codeAn error occurred.

◆ rtems_rfs_bitmap_map_set()

int rtems_rfs_bitmap_map_set ( rtems_rfs_bitmap_control control,
rtems_rfs_bitmap_bit  bit 
)

Set a bit in a map and if all the bits are set, set the search map bit as well.

Parameters
[in]controlis the control for the map.
[in]bitis the bit in the map to set.
Return values
0Successful operation.
error_codeAn error occurred.

◆ rtems_rfs_bitmap_map_set_all()

int rtems_rfs_bitmap_map_set_all ( rtems_rfs_bitmap_control control)

Set all bits in the bitmap and set the dirty bit.

Parameters
[in]controlis the bitmap control.
Return values
0Successful operation.
error_codeAn error occurred.

◆ rtems_rfs_bitmap_map_test()

int rtems_rfs_bitmap_map_test ( rtems_rfs_bitmap_control control,
rtems_rfs_bitmap_bit  bit,
bool *  state 
)

Test a bit in the map.

Parameters
[in]controlis the bitmap control.
[in]bitis the bit to test.
[in]stateis the state of the bit if no error is returned.
Return values
0Successful operation.
error_codeAn error occurred.

◆ rtems_rfs_bitmap_mask()

rtems_rfs_bitmap_element rtems_rfs_bitmap_mask ( unsigned int  size)

Create a bit mask with the specified number of bits up to an element's size. The mask is aligned to bit 0 of the element.

Parameters
[in]sizeis the number of bits in the mask.
Returns
The mask of the argument size number of bits.

◆ rtems_rfs_bitmap_mask_section()

rtems_rfs_bitmap_element rtems_rfs_bitmap_mask_section ( unsigned int  start,
unsigned int  end 
)

Create a bit mask section. A mask section is a mask that is not aligned to an end of the element.

Parameters
[in]startis the first bit of the mask numbered from 0.
[in]endis the end bit of the mask numbered from 0.
Returns
Mask section as defined by the start and end arguments.

◆ rtems_rfs_bitmap_open()

int rtems_rfs_bitmap_open ( rtems_rfs_bitmap_control control,
rtems_rfs_file_system fs,
rtems_rfs_buffer_handle buffer,
size_t  size,
rtems_rfs_buffer_block  block 
)

Open a bitmap control with a map and search map.

Parameters
[in]controlis the map control.
[in]fsis the file system data.
[in]bufferis a pointer to the buffer handle the map is stored in.
[in]sizeis the number of bits in the map.
Return values
0Successful operation.
error_codeAn error occurred.