RTEMS  5.1
Data Structures | Macros | Typedefs | Functions

RTEMS File Systems Block Management. More...

#include <rtems/rfs/rtems-rfs-block-pos.h>
#include <rtems/rfs/rtems-rfs-buffer.h>
#include <rtems/rfs/rtems-rfs-data.h>
#include <rtems/rfs/rtems-rfs-file-system.h>

Go to the source code of this file.

Data Structures

struct  rtems_rfs_block_map_s
 

Macros

#define rtems_rfs_block_get_number(_h, _b)
 
#define rtems_rfs_block_set_number(_h, _b, _n)
 
#define rtems_rfs_block_map_is_dirty(_m)   ((_m)->dirty)
 
#define rtems_rfs_block_map_count(_m)   ((_m)->size.count)
 
#define rtems_rfs_block_map_size(_m)   (&((_m)->size))
 
#define rtems_rfs_block_map_size_offset(_m)   ((_m)->size.offset)
 
#define rtems_rfs_block_map_last(_m)   rtems_rfs_block_pos_last_block (&(_m)->bpos, &(_m)->size)
 
#define rtems_rfs_block_map_past_end(_m, _p)   rtems_rfs_block_pos_past_end (_p, &(_m)->size)
 
#define rtems_rfs_block_map_pos(_f, _m)   rtems_rfs_block_get_pos (_f, &(_m)->bpos)
 
#define rtems_rfs_block_map_block(_m)   ((_m)->bpos.bno)
 
#define rtems_rfs_block_map_block_offset(_m)   ((_m)->bpos.boff)
 

Typedefs

typedef struct rtems_rfs_block_map_s rtems_rfs_block_map
 

Functions

int rtems_rfs_block_map_open (rtems_rfs_file_system *fs, rtems_rfs_inode_handle *inode, rtems_rfs_block_map *map)
 
int rtems_rfs_block_map_close (rtems_rfs_file_system *fs, rtems_rfs_block_map *map)
 
int rtems_rfs_block_map_find (rtems_rfs_file_system *fs, rtems_rfs_block_map *map, rtems_rfs_block_pos *bpos, rtems_rfs_buffer_block *block)
 
int rtems_rfs_block_map_seek (rtems_rfs_file_system *fs, rtems_rfs_block_map *map, rtems_rfs_pos_rel offset, rtems_rfs_buffer_block *block)
 
int rtems_rfs_block_map_next_block (rtems_rfs_file_system *fs, rtems_rfs_block_map *map, rtems_rfs_buffer_block *block)
 
int rtems_rfs_block_map_grow (rtems_rfs_file_system *fs, rtems_rfs_block_map *map, size_t blocks, rtems_rfs_block_no *new_block)
 
int rtems_rfs_block_map_shrink (rtems_rfs_file_system *fs, rtems_rfs_block_map *map, size_t blocks)
 
int rtems_rfs_block_map_free_all (rtems_rfs_file_system *fs, rtems_rfs_block_map *map)
 

Detailed Description

RTEMS File Systems Block Management.

RTEMS File Systems Block Management.

These functions manage the blocks used in the file system.

Macro Definition Documentation

◆ rtems_rfs_block_get_number

#define rtems_rfs_block_get_number (   _h,
  _b 
)
Value:
((_b) * sizeof (rtems_rfs_block_no)))))
rtems_rfs_inode_block rtems_rfs_block_no
Definition: rtems-rfs-block-pos.h:39
#define rtems_rfs_buffer_data(_h)
Definition: rtems-rfs-buffer.h:119
#define rtems_rfs_read_u32(_d)
Definition: rtems-rfs-data.h:57

Get a block number in the media format and return it in the host format.

Parameters
[in]_his the buffer handle of the block.
[in]_bis the block number index.
Return values
blockThe block number.

◆ rtems_rfs_block_map_block

#define rtems_rfs_block_map_block (   _m)    ((_m)->bpos.bno)

Return the map's current block number.

◆ rtems_rfs_block_map_block_offset

#define rtems_rfs_block_map_block_offset (   _m)    ((_m)->bpos.boff)

Return the map's current block offset.

◆ rtems_rfs_block_map_count

#define rtems_rfs_block_map_count (   _m)    ((_m)->size.count)

Return the block count in the map.

◆ rtems_rfs_block_map_is_dirty

#define rtems_rfs_block_map_is_dirty (   _m)    ((_m)->dirty)

Is the map dirty ?

◆ rtems_rfs_block_map_last

#define rtems_rfs_block_map_last (   _m)    rtems_rfs_block_pos_last_block (&(_m)->bpos, &(_m)->size)

Are we at the last block in the map ?

◆ rtems_rfs_block_map_past_end

#define rtems_rfs_block_map_past_end (   _m,
  _p 
)    rtems_rfs_block_pos_past_end (_p, &(_m)->size)

Is the position past the end of the block ?

◆ rtems_rfs_block_map_pos

#define rtems_rfs_block_map_pos (   _f,
  _m 
)    rtems_rfs_block_get_pos (_f, &(_m)->bpos)

Return the current position in the map.

◆ rtems_rfs_block_map_size

#define rtems_rfs_block_map_size (   _m)    (&((_m)->size))

Return the map's size element.

◆ rtems_rfs_block_map_size_offset

#define rtems_rfs_block_map_size_offset (   _m)    ((_m)->size.offset)

Return the size offset for the map.

◆ rtems_rfs_block_set_number

#define rtems_rfs_block_set_number (   _h,
  _b,
  _n 
)
Value:
do { \
rtems_rfs_write_u32 (rtems_rfs_buffer_data (_h) + \
((_b) * sizeof (rtems_rfs_block_no)), (_n)); \
rtems_rfs_buffer_mark_dirty (_h); \
} while (0)
rtems_rfs_inode_block rtems_rfs_block_no
Definition: rtems-rfs-block-pos.h:39
#define rtems_rfs_buffer_data(_h)
Definition: rtems-rfs-buffer.h:119

Set a block number in the media format given a number in the host format.

Parameters
[in]_his the buffer handle of the block.
[in]_bis the block number index, ie the number of block number not the buffer offset.
[in]_nis the block number.

Typedef Documentation

◆ rtems_rfs_block_map

A block map manges the block lists that originate from an inode. The inode contains a number of block numbers. A block map takes those block numbers and manages them.

The blocks cannot have all ones as a block number nor block 0. The block map is series of block numbers in a blocks. The size of the map determines the way the block numbers are stored. The map uses the following:

  • Direct Access,
  • Single Indirect Access, and
  • Double Indirect Access.

Direct access has the blocks numbers in the inode slots. The Single Indirect Access has block numbers in the inode slots that pointer to a table of block numbers that point to data blocks. The Double Indirect Access has block numbers in the inode that point to Single Indirect block tables.

The inode can hold a number of Direct, Single Indirect, and Double Indirect block tables. The move from Direct to Single occurs then the block count in the map is above the number of slots in the inode. The move from Single to Double occurs when the map block count is greated than the block numbers per block multipled by the slots in the inode. The move from Single to Double occurs when the map block count is over the block numbers per block squared multipled by the number of slots in the inode.

The block map can managed files of the follow size verses block size with 5 inode slots:

  • 41,943,040 bytes for a 512 byte block size,
  • 335,544,320 bytes for a 1024 byte block size,
  • 2,684,354,560 bytes for a 2048 byte block size, and
  • 21,474,836,480 bytes for a 4096 byte block size.

Function Documentation

◆ rtems_rfs_block_map_close()

int rtems_rfs_block_map_close ( rtems_rfs_file_system fs,
rtems_rfs_block_map map 
)

Close the map. The buffer handles are closed and any help buffers are released.

Parameters
[in]fsis the file system data.
[in]mapis a pointer to the map that is opened.
Return values
0Successful operation.
error_codeAn error occurred.

◆ rtems_rfs_block_map_find()

int rtems_rfs_block_map_find ( rtems_rfs_file_system fs,
rtems_rfs_block_map map,
rtems_rfs_block_pos bpos,
rtems_rfs_buffer_block block 
)

Find a block number in the map from the position provided.

Parameters
[in]fsis the file system data.
[in]mapis a pointer to the map to search.
[in]bposis a pointer to the block position to find.
[out]blockwill contain the block in when found.
Return values
0Successful operation.
error_codeAn error occurred.

◆ rtems_rfs_block_map_free_all()

int rtems_rfs_block_map_free_all ( rtems_rfs_file_system fs,
rtems_rfs_block_map map 
)

Free all blocks in the map.

Parameters
[in]fsis the file system data.
[in]mapis a pointer to the open map to free all blocks from.
Return values
0Successful operation.
error_codeAn error occurred.

◆ rtems_rfs_block_map_grow()

int rtems_rfs_block_map_grow ( rtems_rfs_file_system fs,
rtems_rfs_block_map map,
size_t  blocks,
rtems_rfs_block_no new_block 
)

Grow the block map by the specified number of blocks.

Parameters
[in]fsis the file system data.
[in]mapis a pointer to the open map to grow.
[in]blocksis the number of blocks to grow the map by.
[out]new_blockwill contain first of the blocks allocated to the map.
Return values
0Successful operation.
error_codeAn error occurred.

◆ rtems_rfs_block_map_next_block()

int rtems_rfs_block_map_next_block ( rtems_rfs_file_system fs,
rtems_rfs_block_map map,
rtems_rfs_buffer_block block 
)

Seek to the next block.

Parameters
[in]fsis the file system data.
[in]mapis a pointer to the map to search.
[out]blockwill contain the block in when found.
Return values
0Successful operation.
ENXIOFailed to seek because it is outside the block map.
error_codeAn error occurred.

◆ rtems_rfs_block_map_open()

int rtems_rfs_block_map_open ( rtems_rfs_file_system fs,
rtems_rfs_inode_handle inode,
rtems_rfs_block_map map 
)

Open a block map. The block map data in the inode is copied into the map. The buffer handles are opened. The block position is set to the start so a seek of offset 0 will return the first block.

Parameters
[in]fsis the file system data.
[in]inodeis a pointer to the inode the map belongs to.
[in]mapis a pointer to the map that is opened.
Return values
0Successful operation.
error_codeAn error occurred.

◆ rtems_rfs_block_map_seek()

int rtems_rfs_block_map_seek ( rtems_rfs_file_system fs,
rtems_rfs_block_map map,
rtems_rfs_pos_rel  offset,
rtems_rfs_buffer_block block 
)

Seek around the map.

Parameters
[in]fsis the file system data.
[in]mapis a pointer to the map to search.
[in]offsetis the distance to seek. It is signed.
[out]blockwill contain the block in when found.
Return values
0Successful operation.
ENXIOFailed to seek because it is outside the block map.
error_codeAn error occurred.

◆ rtems_rfs_block_map_shrink()

int rtems_rfs_block_map_shrink ( rtems_rfs_file_system fs,
rtems_rfs_block_map map,
size_t  blocks 
)

Grow the block map by the specified number of blocks.

Parameters
[in]fsis the file system data.
[in]mapis a pointer to the open map to shrink.
[in]blocksis the number of blocks to shrink the map by. If more than the number of blocks the map is emptied.
Return values
0Successful operation.
error_codeAn error occurred.