RTEMS 6.1-rc1
Data Structures | Macros | Typedefs | Functions

RTEMS File Systems Block Position and Size Management. More...

#include <rtems/rfs/rtems-rfs-file-system.h>
#include <rtems/rfs/rtems-rfs-inode.h>

Go to the source code of this file.

Data Structures

struct  rtems_rfs_block_pos_s
 
struct  rtems_rfs_block_size_s
 

Macros

#define rtems_rfs_block_copy_bpos(_lhs, _rhs)
 
#define rtems_rfs_block_copy_size(_lhs, _rhs)
 
#define rtems_rfs_block_pos_last_block(_p, _s)    ((((_p)->bno == 0) && ((_s)->count == 0)) || ((_p)->bno == ((_s)->count - 1)))
 
#define rtems_rfs_block_pos_past_end(_p, _s)
 
#define rtems_rfs_block_pos_block_past_end(_p, _s)    (((_p)->bno && ((_s)->count == 0)) || ((_p)->bno >= (_s)->count))
 
#define rtems_rfs_block_size_get_bpos(_s, _b)
 
#define rtems_rfs_block_size_equal(_lhs, _rhs)    (((_lhs)->count == (_rhs)->count) && ((_lhs)->offset == (_rhs)->offset))
 

Typedefs

typedef rtems_rfs_inode_block rtems_rfs_block_no
 
typedef uint32_t rtems_rfs_block_off
 
typedef struct rtems_rfs_block_pos_s rtems_rfs_block_pos
 
typedef struct rtems_rfs_block_size_s rtems_rfs_block_size
 

Functions

void rtems_rfs_block_get_bpos (rtems_rfs_file_system *fs, rtems_rfs_pos pos, rtems_rfs_block_pos *bpos)
 
rtems_rfs_pos rtems_rfs_block_get_pos (rtems_rfs_file_system *fs, rtems_rfs_block_pos *bpos)
 
void rtems_rfs_block_get_block_size (rtems_rfs_file_system *fs, rtems_rfs_pos pos, rtems_rfs_block_size *size)
 
rtems_rfs_pos rtems_rfs_block_get_size (rtems_rfs_file_system *fs, rtems_rfs_block_size *size)
 

Detailed Description

RTEMS File Systems Block Position and Size Management.

RTEMS File Systems Block Position and Size Management.

These functions manage the position in a block map as well as a size of data held in a block map. The position is the block count plus the offset into the last block where a block position of 0 and an offset of 0 is the start of a map. The size has a block count plus an offset, but the offset into the last block gives the actual size of the data in the map. This means a size will always have a block count greater than 0 when the file is not empty. A size offset of 0 and a non-zero block count means the length if aligned to the end of the block. For this reason there are 2 similar types so we know which set of rules are in use and the reason for this file.

Macro Definition Documentation

◆ rtems_rfs_block_copy_bpos

#define rtems_rfs_block_copy_bpos (   _lhs,
  _rhs 
)
Value:
do { (_lhs)->bno = (_rhs)->bno; \
(_lhs)->boff = (_rhs)->boff; \
(_lhs)->block = (_rhs)->block; } while (0)

Copy a block position.

Parameters
[in]_lhsis the left hand side.
[in]_rhsis the right hand side.

◆ rtems_rfs_block_copy_size

#define rtems_rfs_block_copy_size (   _lhs,
  _rhs 
)
Value:
do { (_lhs)->count = (_rhs)->count; \
(_lhs)->offset = (_rhs)->offset; } while (0)

Copy a block size.

Parameters
[in]_lhsis the left hand side.
[in]_rhsis the right hand side.

◆ rtems_rfs_block_pos_block_past_end

#define rtems_rfs_block_pos_block_past_end (   _p,
  _s 
)     (((_p)->bno && ((_s)->count == 0)) || ((_p)->bno >= (_s)->count))

Is the block position past the end.

◆ rtems_rfs_block_pos_last_block

#define rtems_rfs_block_pos_last_block (   _p,
  _s 
)     ((((_p)->bno == 0) && ((_s)->count == 0)) || ((_p)->bno == ((_s)->count - 1)))

Last block ?

◆ rtems_rfs_block_pos_past_end

#define rtems_rfs_block_pos_past_end (   _p,
  _s 
)
Value:
(((_p)->bno && ((_s)->count == 0)) || \
((_p)->bno >= (_s)->count) || \
(((_p)->bno == ((_s)->count - 1)) && ((_p)->boff > (_s)->offset)))

Last block ?

◆ rtems_rfs_block_size_equal

#define rtems_rfs_block_size_equal (   _lhs,
  _rhs 
)     (((_lhs)->count == (_rhs)->count) && ((_lhs)->offset == (_rhs)->offset))

Do the sizes match ?

◆ rtems_rfs_block_size_get_bpos

#define rtems_rfs_block_size_get_bpos (   _s,
  _b 
)
Value:
do { (_b)->bno = (_s)->count; \
(_b)->boff = (_s)->offset; \
(_b)->block = 0; \
if ((_b)->boff) --(_b)->bno; } while (0)

Copy the size to the block position. Note the block position and the size have different block counts.

Typedef Documentation

◆ rtems_rfs_block_no

The block number is the same type as the inode block number. This makes sure the sizes of the types match.

◆ rtems_rfs_block_off

typedef uint32_t rtems_rfs_block_off

The offset into a block.

◆ rtems_rfs_block_pos

A block position is a block number times the block size plus the offset. The block field can be used hold a block number for the position as a look up cache.

◆ rtems_rfs_block_size

A block size is the number of blocks less one plus the offset where the offset must be less than the block size.

Function Documentation

◆ rtems_rfs_block_get_block_size()

void rtems_rfs_block_get_block_size ( rtems_rfs_file_system fs,
rtems_rfs_pos  pos,
rtems_rfs_block_size size 
)

Set the size given a position.

Parameters
[in]fsis the file system data.
[in]posis the position as an absolute offset from the start.
[out]sizeis a pointer to the block size to fill in.

◆ rtems_rfs_block_get_bpos()

void rtems_rfs_block_get_bpos ( rtems_rfs_file_system fs,
rtems_rfs_pos  pos,
rtems_rfs_block_pos bpos 
)

Given a position compute the block number and block offset.

Parameters
[in]fsis the file system data.
[in]posis the position as an absolute offset from the start.
[out]bposis a pointer to the block position to fill in.

◆ rtems_rfs_block_get_pos()

rtems_rfs_pos rtems_rfs_block_get_pos ( rtems_rfs_file_system fs,
rtems_rfs_block_pos bpos 
)

Given a block position compute the absolute offset.

Parameters
[in]fsis the file system data.
[out]bposis a pointer to the block position to fill in.
Return values
offsetThe absolute offset.

◆ rtems_rfs_block_get_size()

rtems_rfs_pos rtems_rfs_block_get_size ( rtems_rfs_file_system fs,
rtems_rfs_block_size size 
)

Calculate the position given the number of blocks and the offset. If the block count is 0 the size is 0. If the block is greater than 0 and the offset is 0 the size is number of blocks multipled by the block size and if the offset is not 0 it is the offset into the last block. For example if blocks is 1 and offset is 0 the size is the block size. If the block count is 1 and size is 100 the size is 100.

Parameters
[in]fsis the file system data.
[in]sizeThe size in blocks and offset.
Return values
sizeThe size in bytes.