RTEMS
5.1
|
RTEMS File Systems Block Routines. More...
#include <inttypes.h>
#include <string.h>
#include <rtems/rfs/rtems-rfs-block.h>
#include <rtems/rfs/rtems-rfs-data.h>
#include <rtems/rfs/rtems-rfs-group.h>
#include <rtems/rfs/rtems-rfs-inode.h>
RTEMS File Systems Block Routines.
These functions manage blocks in the RFS file system. A block is an area of the media and its size is set for a each specific media. The block size is set when the file system is set up and needs to be matched for it to be read correctly.
Blocks are managed as groups. A block group or "group" is part of the total number of blocks being managed by the file system and exist to allow resources to localised. A file in a directory will be allocated blocks in the same group as the directory, and the blocks for the file will also be allocated in the same group.
A group consist of a block bitmap, inodes and data blocks. The first block of the file system will hold the superblock. The block bitmap is a collection of blocks that hold a map of bits, one bit per block for each block in the group. When a file system is mounted the block bitmaps are read and a summary bit map is made. The summary bitmap has a single bit for 32 bits in the bitmap and is set when all 32 bits it maps to are set. This speeds up the search for a free block by a factor of 32.
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.
[in] | fs | is the file system data. |
[in] | pos | is the position as an absolute offset from the start. |
[out] | size | is a pointer to the block size to fill in. |
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.
[in] | fs | is the file system data. |
[in] | pos | is the position as an absolute offset from the start. |
[out] | bpos | is a pointer to the block position to fill in. |
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.
[in] | fs | is the file system data. |
[out] | bpos | is a pointer to the block position to fill in. |
offset | The absolute offset. |
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.
[in] | fs | is the file system data. |
[in] | size | The size in blocks and offset. |
size | The size in bytes. |
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.
[in] | fs | is the file system data. |
[in] | map | is a pointer to the map that is opened. |
0 | Successful operation. |
error_code | An error occurred. |
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.
[in] | fs | is the file system data. |
[in] | map | is a pointer to the map to search. |
[in] | bpos | is a pointer to the block position to find. |
[out] | block | will contain the block in when found. |
0 | Successful operation. |
error_code | An error occurred. |
int rtems_rfs_block_map_free_all | ( | rtems_rfs_file_system * | fs, |
rtems_rfs_block_map * | map | ||
) |
Free all blocks in the map.
[in] | fs | is the file system data. |
[in] | map | is a pointer to the open map to free all blocks from. |
0 | Successful operation. |
error_code | An error occurred. |
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.
[in] | fs | is the file system data. |
[in] | map | is a pointer to the open map to grow. |
[in] | blocks | is the number of blocks to grow the map by. |
[out] | new_block | will contain first of the blocks allocated to the map. |
0 | Successful operation. |
error_code | An error occurred. |
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.
[in] | fs | is the file system data. |
[in] | map | is a pointer to the map to search. |
[out] | block | will contain the block in when found. |
0 | Successful operation. |
ENXIO | Failed to seek because it is outside the block map. |
error_code | An error occurred. |
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.
[in] | fs | is the file system data. |
[in] | inode | is a pointer to the inode the map belongs to. |
[in] | map | is a pointer to the map that is opened. |
0 | Successful operation. |
error_code | An error occurred. |
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.
[in] | fs | is the file system data. |
[in] | map | is a pointer to the map to search. |
[in] | offset | is the distance to seek. It is signed. |
[out] | block | will contain the block in when found. |
0 | Successful operation. |
ENXIO | Failed to seek because it is outside the block map. |
error_code | An error occurred. |
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.
[in] | fs | is the file system data. |
[in] | map | is a pointer to the open map to shrink. |
[in] | blocks | is the number of blocks to shrink the map by. If more than the number of blocks the map is emptied. |
0 | Successful operation. |
error_code | An error occurred. |