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

4.104.11
Last change on this file since 3cfa636 was 3cfa636, checked in by Chris Johns <chrisj@…>, on Feb 26, 2010 at 5:54:59 AM

010-02-26 Chris Johns <chrisj@…>

  • libfs/src/rfs/rtems-rfs-block.c: Reset a buffer handle after moving down an indirection level.
  • libfs/src/rfs/rtems-rfs-dir.c: Move directory entry validation into a macro and use the macro. Fix the range check on the ino so all inodes can be used.
  • libfs/src/rfs/rtems-rfs-file-system.c,
libfs/src/rfs/rtems-rfs-file-system.h
Add a version number to the superblock. Use RTEMS_RFS_INODE_SIZE.
  • libfs/src/rfs/rtems-rfs-file.c: Fix the size offset on partial block lengths. Set the size in the file handle on a truncate to 0.
  • libfs/src/rfs/rtems-rfs-format.c: Add a version number to the superblock. Use RTEMS_RFS_INODE_SIZE. A better set of defaults for small disks.
  • libfs/src/rfs/rtems-rfs-inode.c: Use RTEMS_RFS_INODE_SIZE. Free the allocated inode if it cannot be opened.
  • libfs/src/rfs/rtems-rfs-inode.h: Add RTEMS_RFS_INODE_SIZE.
  • libfs/src/rfs/rtems-rfs-rtems-file.c: Move some of the iop acceses inside the fs lock.
  • libfs/src/rfs/rtems-rfs-shell.c: Use RTEMS_RFS_INODE_SIZE.
  • Property mode set to 100644
File size: 10.3 KB
Line 
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)
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 */
49#define RTEMS_RFS_VERSION_MASK (0x00000000)
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 */
114struct rtems_rfs_file_system_t
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
261/**
262 * Return the flags.
263 *
264 * @param _fs Pointer to the file system.
265 */
266#define rtems_rfs_fs_flags(_f) ((_f)->flags)
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 size of the disk in bytes.
308 *
309 * @param _fs Pointer to the file system.
310 */
311#define rtems_rfs_fs_size(_fs) (((uint64_t) rtems_rfs_fs_blocks (_fs)) * \
312                                rtems_rfs_fs_block_size (_fs))
313
314/**
315 * The number of inodes.
316 *
317 * @param _fs Pointer to the file system.
318 */
319#define rtems_rfs_fs_inodes(_fs) ((_fs)->inodes)
320
321/**
322 * Calculate a block in the file system given the group and the block within
323 * the group.
324 *
325 * @param _fs Pointer to the file system.
326 * @param _grp The group.
327 * @param _blk The block within the group.
328 * @return The absolute block number.
329 */
330#define rtems_rfs_fs_block(_fs, _grp, _blk) \
331  ((((_fs)->group_blocks) * (_grp)) + (_blk) + 1)
332
333/**
334 * The media size of the disk in media size blocks.
335 *
336 * @param _fs Pointer to the file system.
337 */
338#if RTEMS_RFS_USE_LIBBLOCK
339#define rtems_rfs_fs_media_blocks(_fs) ((_fs)->disk->size)
340#else
341#define rtems_rfs_fs_media_blocks(_fs) ((_fs)->media_size)
342#endif
343
344/**
345 * The media block size. This is the size of a block on disk. For a device I/O
346 * this value is 1.
347 *
348 * @param _fs Pointer to the file system.
349 */
350#if RTEMS_RFS_USE_LIBBLOCK
351#define rtems_rfs_fs_media_block_size(_fs) ((_fs)->disk->media_block_size)
352#else
353#define rtems_rfs_fs_media_block_size(_fs) (1)
354#endif
355
356/**
357 * The size of the disk in bytes.
358 *
359 * @param _fs Pointer to the file system.
360 */
361#define rtems_rfs_fs_media_size(_fs) (((uint64_t) rtems_rfs_fs_media_blocks (_fs)) * \
362                                      rtems_rfs_fs_media_block_size (_fs))
363
364/**
365 * The maximum length of a name supported by the file system.
366 */
367#define rtems_rfs_fs_max_name(_fs) ((_fs)->max_name_length)
368
369/**
370 * Return the maximum number of blocks in a block map.
371 *
372 * @return uint32_t The maximum number of blocks possible.
373 */
374#define rtems_rfs_fs_max_block_map_blocks(_fs) ((_fs)->block_map_doubly_blocks)
375
376/**
377 * Return the user pointer.
378 */
379#define rtems_rfs_fs_user(_fs) ((_fs)->user)
380
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.