source: rtems/cpukit/libfs/src/rfs/rtems-rfs-file-system.h @ ca8c50de

4.115
Last change on this file since ca8c50de was ca8c50de, checked in by Chris Johns <chrisj@…>, on 06/17/10 at 22:00:47

2010-06-18 Chris Johns <chrisj@…>

  • libfs/src/rfs/rtems-rfs-file-system.h, libfs/src/rfs/rtems-rfs-file-system.c: Move questionable macros to C functions.
  • Property mode set to 100644
File size: 10.2 KB
RevLine 
[a9fa9b7]1/*
2 *  COPYRIGHT (c) 2010 Chris Johns <chrisj@rtems.org>
3 *
4 *  The license and distribution terms for this file may be
5 *  found in the file LICENSE in this distribution or at
6 *  http://www.rtems.com/license/LICENSE.
7 *
8 *  $Id$
9 */
10/**
11 * @file
12 *
13 * @ingroup rtems-rfs
14 *
15 * RTEMS File System Data
16 *
17 * This file defines the file system data.
18 */
19
20#if !defined (_RTEMS_RFS_FILE_SYSTEM_H_)
21#define _RTEMS_RFS_FILE_SYSTEM_H_
22
23#include <rtems/rfs/rtems-rfs-group.h>
24
25/**
26 * Superblock offsets and values.
27 */
28#define RTEMS_RFS_SB_OFFSET_MAGIC           (0)
29#define RTEMS_RFS_SB_MAGIC                  (0x28092001)
[3cfa636]30#define RTEMS_RFS_SB_OFFSET_VERSION         (RTEMS_RFS_SB_OFFSET_MAGIC           + 4)
31#define RTEMS_RFS_SB_OFFSET_BLOCK_SIZE      (RTEMS_RFS_SB_OFFSET_VERSION         + 4)
32#define RTEMS_RFS_SB_OFFSET_BLOCKS          (RTEMS_RFS_SB_OFFSET_BLOCK_SIZE      + 4)
33#define RTEMS_RFS_SB_OFFSET_BAD_BLOCKS      (RTEMS_RFS_SB_OFFSET_BLOCKS          + 4)
34#define RTEMS_RFS_SB_OFFSET_MAX_NAME_LENGTH (RTEMS_RFS_SB_OFFSET_BAD_BLOCKS      + 4)
35#define RTEMS_RFS_SB_OFFSET_GROUPS          (RTEMS_RFS_SB_OFFSET_MAX_NAME_LENGTH + 4)
36#define RTEMS_RFS_SB_OFFSET_GROUP_BLOCKS    (RTEMS_RFS_SB_OFFSET_GROUPS          + 4)
37#define RTEMS_RFS_SB_OFFSET_GROUP_INODES    (RTEMS_RFS_SB_OFFSET_GROUP_BLOCKS    + 4)
38#define RTEMS_RFS_SB_OFFSET_INODE_SIZE      (RTEMS_RFS_SB_OFFSET_GROUP_INODES    + 4)
39
40/**
41 * RFS Version Number.
42 */
43#define RTEMS_RFS_VERSION (0x00000000)
44
45/**
46 * RFS Version Number Mask. The mask determines which bits of the version
47 * number indicate compatility issues.
48 */
[ff0d62ca]49#define RTEMS_RFS_VERSION_MASK INT32_C(0x00000000)
[a9fa9b7]50
51/**
52 * The root inode number. Do not use 0 as this has special meaning in some Unix
53 * operating systems.
54 */
55#define RTEMS_RFS_ROOT_INO (1)
56
57/**
58 * Empty inode number.
59 */
60#define RTEMS_RFS_EMPTY_INO (0)
61
62/**
63 * The number of blocks in the inode. This number effects the size of the inode
64 * and that effects the overhead of the inode tables in a group.
65 */
66#define RTEMS_RFS_INODE_BLOCKS (5)
67
68/**
69 * The inode overhead is the percentage of space reserved for inodes. It is
70 * calculated as the percentage number of blocks in a group. The number of
71 * blocks in a group is the number of bits a block can hold.
72 */
73#define RTEMS_RFS_INODE_OVERHEAD_PERCENTAGE (1)
74
75/**
76 * Number of blocks in the superblock. Yes I know it is a superblock and not
77 * superblocks but if for any reason this needs to change it is handled.
78 */
79#define RTEMS_RFS_SUPERBLOCK_SIZE (1)
80
81/**
82 * The maximum number of buffers held by the file system at any one time.
83 */
84#define RTEMS_RFS_FS_MAX_HELD_BUFFERS (5)
85
86/**
87 * Absolute position. Make a 64bit value.
88 */
89typedef uint64_t rtems_rfs_pos;
90
91/**
92 * Relative position. Make a 64bit value.
93 */
94typedef int64_t rtems_rfs_pos_rel;
95
96/**
97 * Flags to control the file system.
98 */
99#define RTEMS_RFS_FS_BITMAPS_HOLD      (1 << 0) /**< Do not release bitmaps
100                                                 * when finished. Default is
101                                                 * off so they are released. */
102#define RTEMS_RFS_FS_NO_LOCAL_CACHE    (1 << 1) /**< Do not cache the buffers
103                                                 * and release directly to the
104                                                 * buffer support layer. The
105                                                 * default is to hold buffers. */
106#define RTEMS_RFS_FS_FORCE_OPEN        (1 << 2) /**< Force open and ignore any
107                                                 * errors. */
108#define RTEMS_RFS_FS_READ_ONLY         (1 << 3) /**< Make the mount
109                                                 * read-only. Currently not
110                                                 * supported. */
111/**
112 * RFS File System data.
113 */
[9bc752b]114struct _rtems_rfs_file_system
[a9fa9b7]115{
116  /**
117   * Flags to control the file system. Some can be controlled via the ioctl.
118   */
119  uint32_t flags;
120
121  /**
122   * The number of blocks in the disk. The size of the disk is the number of
123   * blocks by the block size. This should be within a block size of the size
124   * returned by the media driver.
125   */
126  size_t blocks;
127
128  /**
129   * The size of a block. This must be a multiple of the disk's media block
130   * size.
131   */
132  size_t block_size;
133
134#if RTEMS_RFS_USE_LIBBLOCK
135  /**
136   * The disk device. This is the data about the block device this file system
137   * is mounted on. We access the data held in this structure rather than
138   * making an extra copy in this structure.
139   */
140  rtems_disk_device* disk;
141#else
142  /**
143   * The device number which is a the file handle for device I/O.
144   */
145  dev_t device;
146
147  /**
148   * The number of blocks in the file system.
149   */
150  size_t size;
151#endif
152
153  /**
154   * Inode count.
155   */
156  uint32_t inodes;
157
158  /**
159   * Bad block blocks. This is a table of blocks that have been found to be
160   * bad.
161   */
162  uint32_t bad_blocks;
163
164  /**
165   * Maximum length of names supported by this file system.
166   */
167  uint32_t max_name_length;
168
169  /**
170   * A disk is broken down into a series of groups.
171   */
172  rtems_rfs_group* groups;
173
174  /**
175   * Number of groups.
176   */
177  int group_count;
178
179  /**
180   * Number of blocks in a group.
181   */
182  size_t group_blocks;
183
184  /**
185   * Number of inodes in a group.
186   */
187  size_t group_inodes;
188
189  /**
190   * Number of inodes in each block.
191   */
192  size_t inodes_per_block;
193
194  /**
195   * Number of block numbers in a block.
196   */
197  size_t blocks_per_block;
198
199  /**
200   * Block map single indirect count. This is the block number per block
201   * multiplied but the slots in the inode.
202   */
203  size_t block_map_singly_blocks;
204
205  /**
206   * Block map double indirect count. This is the block number per block
207   * squared and multiplied by the slots in the inode. It is the maximum
208   * number of blocks a map (file/directory) can have.
209   */
210  size_t block_map_doubly_blocks;
211
212  /**
213   * Number of buffers held before releasing back to the cache.
214   */
215  uint32_t max_held_buffers;
216
217  /**
218   * List of buffers attached to buffer handles. Allows sharing.
219   */
220  rtems_chain_control buffers;
221
222  /**
223   * Number of buffers held on the buffers list.
224   */
225  uint32_t buffers_count;
226
227  /**
228   * List of buffers that need to be released when the processing of a file
229   * system request has completed.
230   */
231  rtems_chain_control release;
232
233  /**
234   * Number of buffers held on the release list.
235   */
236  uint32_t release_count;
237
238  /**
239   * List of buffers that need to be released modified when the processing of a
240   * file system request has completed.
241   */
242  rtems_chain_control release_modified;
243
244  /**
245   * Number of buffers held on the release modified list.
246   */
247  uint32_t release_modified_count;
248
249  /**
250   * List of open shared file node data. The shared node data such as the inode
251   * and block map allows a single file to be open more than once.
252   */
253  rtems_chain_control file_shares;
254
255  /**
256   * Pointer to user data supplied when opening.
257   */
258  void* user;
259};
260
[59762963]261/**
262 * Return the flags.
263 *
264 * @param _fs Pointer to the file system.
265 */
266#define rtems_rfs_fs_flags(_f) ((_f)->flags)
[a9fa9b7]267/**
268 * Should bitmap buffers be released when finished ?
269 *
270 * @param _fs Pointer to the file system.
271 */
272#define rtems_rfs_fs_release_bitmaps(_f) (!((_f)->flags & RTEMS_RFS_FS_BITMAPS_HOLD))
273
274/**
275 * Are the buffers locally cache or released back to the buffering layer ?
276 *
277 * @param _fs Pointer to the file system.
278 */
279#define rtems_rfs_fs_no_local_cache(_f) ((_f)->flags & RTEMS_RFS_FS_NO_LOCAL_CACHE)
280
281/**
282 * The disk device number.
283 *
284 * @param _fs Pointer to the file system.
285 */
286#if RTEMS_RFS_USE_LIBBLOCK
287#define rtems_rfs_fs_device(_fs) ((_fs)->disk->dev)
288#else
289#define rtems_rfs_fs_device(_fs) ((_fs)->device)
290#endif
291
292/**
293 * The size of the disk in blocks.
294 *
295 * @param _fs Pointer to the file system.
296 */
297#define rtems_rfs_fs_blocks(_fs) ((_fs)->blocks)
298
299/**
300 * The block size.
301 *
302 * @param _fs Pointer to the file system.
303 */
304#define rtems_rfs_fs_block_size(_fs) ((_fs)->block_size)
305
306/**
307 * The number of inodes.
308 *
309 * @param _fs Pointer to the file system.
310 */
311#define rtems_rfs_fs_inodes(_fs) ((_fs)->inodes)
312
313/**
314 * Calculate a block in the file system given the group and the block within
315 * the group.
316 *
317 * @param _fs Pointer to the file system.
318 * @param _grp The group.
319 * @param _blk The block within the group.
320 * @return The absolute block number.
321 */
322#define rtems_rfs_fs_block(_fs, _grp, _blk) \
323  ((((_fs)->group_blocks) * (_grp)) + (_blk) + 1)
324
325/**
326 * The media size of the disk in media size blocks.
327 *
328 * @param _fs Pointer to the file system.
329 */
330#if RTEMS_RFS_USE_LIBBLOCK
331#define rtems_rfs_fs_media_blocks(_fs) ((_fs)->disk->size)
332#else
333#define rtems_rfs_fs_media_blocks(_fs) ((_fs)->media_size)
334#endif
335
336/**
337 * The media block size. This is the size of a block on disk. For a device I/O
338 * this value is 1.
339 *
340 * @param _fs Pointer to the file system.
341 */
342#if RTEMS_RFS_USE_LIBBLOCK
343#define rtems_rfs_fs_media_block_size(_fs) ((_fs)->disk->media_block_size)
344#else
345#define rtems_rfs_fs_media_block_size(_fs) (1)
346#endif
347
348/**
349 * The maximum length of a name supported by the file system.
350 */
351#define rtems_rfs_fs_max_name(_fs) ((_fs)->max_name_length)
352
353/**
354 * Return the maximum number of blocks in a block map.
355 *
356 * @return uint32_t The maximum number of blocks possible.
357 */
358#define rtems_rfs_fs_max_block_map_blocks(_fs) ((_fs)->block_map_doubly_blocks)
359
360/**
361 * Return the user pointer.
362 */
363#define rtems_rfs_fs_user(_fs) ((_fs)->user)
364
[ca8c50de]365/**
366 * Return the size of the disk in bytes.
367 *
368 * @param fs Pointer to the file system.
369 * @return uint64_t The size of the disk in bytes.
370 */
371uint64_t rtems_rfs_fs_size(rtems_rfs_file_system* fs);
372
373/**
374 * The size of the disk in bytes calculated from the media parameters..
375 *
376 * @param fs Pointer to the file system.
377 * @return uint64_t The size of the disk in bytes.
378 */
379uint64_t rtems_rfs_fs_media_size (rtems_rfs_file_system* fs);
380
[a9fa9b7]381/**
382 * Open the file system given a file path.
383 *
384 * @param name The device to open.
385 * @param fs The file system data filled in by this call.
386 * @param user A pointer to user data.
387 * @return int The error number (errno). No error if 0.
388 */
389int rtems_rfs_fs_open (const char*             name,
390                       void*                   user,
391                       uint32_t                flags,
392                       rtems_rfs_file_system** fs);
393
394/**
395 * Close the file system.
396 *
397 * @param fs The file system data.
398 * @return int The error number (errno). No error if 0.
399 */
400int rtems_rfs_fs_close (rtems_rfs_file_system* fs);
401
402#endif
Note: See TracBrowser for help on using the repository browser.