source: rtems/cpukit/libfs/src/rfs/rtems-rfs-block.h @ c2ae79e

4.115
Last change on this file since c2ae79e was c2ae79e, checked in by Mathew Kallada <matkallada@…>, on 12/12/12 at 20:57:49

misc: Header File Doxygen Enhancement Task #3

http://www.google-melange.com/gci/task/view/google/gci2012/8006220

  • Property mode set to 100644
File size: 10.0 KB
Line 
1/**
2 * @file
3 *
4 * @brief RTEMS File Systems Block Management
5 *
6 * @ingroup rtems-rfs
7 *
8 * RTEMS File Systems Block Management.
9 *
10 * These functions manage the blocks used in the file system.
11 */
12
13/*
14 *  COPYRIGHT (c) 2010 Chris Johns <chrisj@rtems.org>
15 *
16 *  The license and distribution terms for this file may be
17 *  found in the file LICENSE in this distribution or at
18 *  http://www.rtems.com/license/LICENSE.
19 */
20
21
22#if !defined (_RTEMS_RFS_BLOCK_H_)
23#define _RTEMS_RFS_BLOCK_H_
24
25#include <rtems/rfs/rtems-rfs-block-pos.h>
26#include <rtems/rfs/rtems-rfs-buffer.h>
27#include <rtems/rfs/rtems-rfs-data.h>
28#include <rtems/rfs/rtems-rfs-file-system.h>
29
30/**
31 * Get a block number in the media format and return it in the host format.
32 *
33 * @param _h The buffer handle of the block.
34 * @param _b The block number index.
35 * @return uint32_t The block number.
36 */
37#define rtems_rfs_block_get_number(_h, _b) \
38  ((rtems_rfs_block_no) \
39   (rtems_rfs_read_u32 (rtems_rfs_buffer_data (_h) + \
40                        ((_b) * sizeof (rtems_rfs_block_no)))))
41
42/**
43 * Set a block number in the media format given a number in the host format.
44 *
45 * @param _h The buffer handle of the block.
46 * @param _b The block number index, ie the number of block number not the
47 *           buffer offset.
48 * @param _n The block number.
49 */
50#define rtems_rfs_block_set_number(_h, _b, _n) \
51  do { \
52    rtems_rfs_write_u32 (rtems_rfs_buffer_data (_h) + \
53                         ((_b) * sizeof (rtems_rfs_block_no)), (_n)); \
54    rtems_rfs_buffer_mark_dirty (_h); \
55  } while (0)
56
57/**
58 * A block map manges the block lists that originate from an inode. The inode
59 * contains a number of block numbers. A block map takes those block numbers
60 * and manages them.
61 *
62 * The blocks cannot have all ones as a block number nor block 0. The block map
63 * is series of block numbers in a blocks. The size of the map determines the
64 * way the block numbers are stored. The map uses the following:
65 *
66 * @li @e Direct Access,
67 * @li @e Single Indirect Access, and
68 * @li @e Double Indirect Access.
69 *
70 * Direct access has the blocks numbers in the inode slots. The Single Indirect
71 * Access has block numbers in the inode slots that pointer to a table of block
72 * numbers that point to data blocks. The Double Indirect Access has block
73 * numbers in the inode that point to Single Indirect block tables.
74 *
75 * The inode can hold a number of Direct, Single Indirect, and Double Indirect
76 * block tables. The move from Direct to Single occurs then the block count in
77 * the map is above the number of slots in the inode. The move from Single to
78 * Double occurs when the map block count is greated than the block numbers per
79 * block multipled by the slots in the inode. The move from Single to Double
80 * occurs when the map block count is over the block numbers per block squared
81 * multipled by the number of slots in the inode.
82 *
83 * The block map can managed files of the follow size verses block size with 5
84 * inode slots:
85 *
86 *  @li 41,943,040 bytes for a 512 byte block size,
87 *  @li 335,544,320 bytes for a 1024 byte block size,
88 *  @li 2,684,354,560 bytes for a 2048 byte block size, and
89 *  @li 21,474,836,480 bytes for a 4096 byte block size.
90 */
91typedef struct rtems_rfs_block_map_s
92{
93  /**
94   * Is the map dirty ?
95   */
96  bool dirty;
97
98  /**
99   * The inode this map is attached to.
100   */
101  rtems_rfs_inode_handle* inode;
102
103  /**
104   * The size of the map.
105   */
106  rtems_rfs_block_size size;
107
108  /**
109   * The block map position. Used to navigate the map when seeking. The find
110   * call is to a position in the file/directory and is a block number plus
111   * offset. The block find only needs to locate a block and not worry about
112   * the offset while a seek can be less than a block size yet move across a
113   * block boundary. Therefore the position a block map has to maintain must
114   * include the offset so seeks work.
115   */
116  rtems_rfs_block_pos bpos;
117
118  /**
119   * The last map block allocated. This is used as the goal when allocating a
120   * new map block.
121   */
122  rtems_rfs_block_no last_map_block;
123
124  /**
125   * The last data block allocated. This is used as the goal when allocating a
126   * new data block.
127   */
128  rtems_rfs_block_no last_data_block;
129
130  /**
131   * The block map.
132   */
133  uint32_t blocks[RTEMS_RFS_INODE_BLOCKS];
134
135  /**
136   * Singly Buffer handle.
137   */
138  rtems_rfs_buffer_handle singly_buffer;
139
140  /**
141   * Doubly Buffer handle.
142   */
143  rtems_rfs_buffer_handle doubly_buffer;
144
145} rtems_rfs_block_map;
146
147/**
148 * Is the map dirty ?
149 */
150#define rtems_rfs_block_map_is_dirty(_m) ((_m)->dirty)
151
152/**
153 * Return the block count in the map.
154 */
155#define rtems_rfs_block_map_count(_m) ((_m)->size.count)
156
157/**
158 * Return the map's size element.
159 */
160#define rtems_rfs_block_map_size(_m) (&((_m)->size))
161
162/**
163 * Return the size offset for the map.
164 */
165#define rtems_rfs_block_map_size_offset(_m) ((_m)->size.offset)
166
167/**
168 * Are we at the last block in the map ?
169 */
170#define rtems_rfs_block_map_last(_m) \
171  rtems_rfs_block_pos_last_block (&(_m)->bpos, &(_m)->size)
172
173/**
174 * Is the position past the end of the block ?
175 */
176#define rtems_rfs_block_map_past_end(_m, _p) \
177  rtems_rfs_block_pos_past_end (_p, &(_m)->size)
178
179/**
180 * Return the current position in the map.
181 */
182#define rtems_rfs_block_map_pos(_f, _m) \
183  rtems_rfs_block_get_pos (_f, &(_m)->bpos)
184
185/**
186 * Return the map's current block number.
187 */
188#define rtems_rfs_block_map_block(_m) ((_m)->bpos.bno)
189
190/**
191 * Return the map's current block offset.
192 */
193#define rtems_rfs_block_map_block_offset(_m) ((_m)->bpos.boff)
194
195/**
196 * Set the size offset for the map. The map is tagged as dirty.
197 *
198 * @param map Pointer to the open map to set the offset in.
199 * @param offset The offset to set in the map's size.
200 */
201static inline void
202rtems_rfs_block_map_set_size_offset (rtems_rfs_block_map* map,
203                                     rtems_rfs_block_off  offset)
204{
205  map->size.offset = offset;
206  map->dirty = true;
207}
208
209/**
210 * Set the map's size. The map is tagged as dirty.
211 *
212 * @param map Pointer to the open map to set the offset in.
213 * @param size The size to set in the map's size.
214 */
215static inline void
216rtems_rfs_block_map_set_size (rtems_rfs_block_map*  map,
217                              rtems_rfs_block_size* size)
218{
219  rtems_rfs_block_copy_size (&map->size, size);
220  map->dirty = true;
221}
222/**
223 * Open a block map. The block map data in the inode is copied into the
224 * map. The buffer handles are opened. The block position is set to the start
225 * so a seek of offset 0 will return the first block.
226 *
227 * @param fs The file system data.
228 * @param inode The inode the map belongs to.
229 * @param map The map that is opened.
230 * @return int The error number (errno). No error if 0.
231 */
232int rtems_rfs_block_map_open (rtems_rfs_file_system*  fs,
233                              rtems_rfs_inode_handle* inode,
234                              rtems_rfs_block_map*    map);
235
236/**
237 * Close the map. The buffer handles are closed and any help buffers are
238 * released.
239 *
240 * @param fs The file system data.
241 * @param map The map that is opened.
242 * @return int The error number (errno). No error if 0.
243 */
244int rtems_rfs_block_map_close (rtems_rfs_file_system* fs,
245                               rtems_rfs_block_map*   map);
246
247/**
248 * Find a block number in the map from the position provided.
249 *
250 * @param fs The file system data.
251 * @param map The map to search.
252 * @param bpos The block position to find.
253 * @param block Pointer to place the block in when found.
254 * @return int The error number (errno). No error if 0.
255 */
256int rtems_rfs_block_map_find (rtems_rfs_file_system*  fs,
257                              rtems_rfs_block_map*    map,
258                              rtems_rfs_block_pos*    bpos,
259                              rtems_rfs_buffer_block* block);
260
261/**
262 * Seek around the map.
263 *
264 * @param fs The file system data.
265 * @param map The map to search.
266 * @param offset The distance to seek. It is signed.
267 * @param block Pointer to place the block in when found.
268 * @retval ENXIO Failed to seek because it is outside the block map.
269 * @return int The error number (errno). No error if 0.
270 */
271int rtems_rfs_block_map_seek (rtems_rfs_file_system*  fs,
272                              rtems_rfs_block_map*    map,
273                              rtems_rfs_pos_rel       offset,
274                              rtems_rfs_buffer_block* block);
275
276/**
277 * Seek to the next block.
278 *
279 * @param fs The file system data.
280 * @param map The map to search.
281 * @param block Pointer to place the block in when found.
282 * @retval ENXIO Failed to seek because it is outside the block map.
283 * @return int The error number (errno). No error if 0.
284 */
285int rtems_rfs_block_map_next_block (rtems_rfs_file_system*  fs,
286                                    rtems_rfs_block_map*    map,
287                                    rtems_rfs_buffer_block* block);
288
289/**
290 * Grow the block map by the specified number of blocks.
291 *
292 * @param fs The file system data.
293 * @param map Pointer to the open map to grow.
294 * @param blocks The number of blocks to grow the map by.
295 * @param new_block The first of the blocks allocated to the map.
296 * @return int The error number (errno). No error if 0.
297 */
298int rtems_rfs_block_map_grow (rtems_rfs_file_system* fs,
299                              rtems_rfs_block_map*   map,
300                              size_t                 blocks,
301                              rtems_rfs_block_no*    new_block);
302
303/**
304 * Grow the block map by the specified number of blocks.
305 *
306 * @param fs The file system data.
307 * @param map Pointer to the open map to shrink.
308 * @param blocks The number of blocks to shrink the map by. If more than the
309 *               number of blocks the map is emptied.
310 * @return int The error number (errno). No error if 0.
311 */
312int rtems_rfs_block_map_shrink (rtems_rfs_file_system* fs,
313                                rtems_rfs_block_map*   map,
314                                size_t                 blocks);
315
316/**
317 * Free all blocks in the map.
318 *
319 * @param fs The file system data.
320 * @param map Pointer to the open map to free all blocks from.
321 * @return int The error number (errno). No error if 0.
322 */
323int rtems_rfs_block_map_free_all (rtems_rfs_file_system* fs,
324                                  rtems_rfs_block_map*   map);
325
326#endif
Note: See TracBrowser for help on using the repository browser.