source: rtems/cpukit/libfs/src/imfs/imfs.h @ 3b7c123

4.115
Last change on this file since 3b7c123 was 3b7c123, checked in by Sebastian Huber <sebastian.huber@…>, on 03/13/12 at 10:33:51

Filesystem: Reference counting for locations

o A new data structure rtems_filesystem_global_location_t was

introduced to be used for

o the mount point location in the mount table entry,
o the file system root location in the mount table entry,
o the root directory location in the user environment, and
o the current directory location in the user environment.

During the path evaluation global start locations are obtained to
ensure that the current file system instance will be not unmounted in
the meantime.

o The user environment uses now reference counting and is protected

from concurrent access.

o The path evaluation process was completely rewritten and simplified.

The IMFS, RFS, NFS, and DOSFS use now a generic path evaluation
method. Recursive calls in the path evaluation have been replaced
with iteration to avoid stack overflows. Only the evaluation of
symbolic links is recursive. No dynamic memory allocations and
intermediate buffers are used in the high level path evaluation. No
global locks are held during the file system instance specific path
evaluation process.

o Recursive symbolic link evaluation is now limited by

RTEMS_FILESYSTEM_SYMLOOP_MAX. Applications can retrieve this value
via sysconf().

o The device file system (devFS) uses now no global variables and

allocation from the workspace. Node names are allocated from the
heap.

o The upper layer lseek() performs now some parameter checks.
o The upper layer ftruncate() performs now some parameter checks.
o unmask() is now restricted to the RWX flags and protected from

concurrent access.

o The fchmod_h and rmnod_h file system node handlers are now a file

system operation.

o The unlink_h operation has been removed. All nodes are now destroyed

with the rmnod_h operation.

o New lock_h, unlock_h, clonenod_h, and are_nodes_equal_h file system

operations.

o The path evaluation and file system operations are now protected by

per file system instance lock and unlock operations.

o Fix and test file descriptor duplicate in fcntl().
o New test fstests/fsnofs01.

  • Property mode set to 100644
File size: 13.7 KB
Line 
1/**
2 * @file rtems/imfs.h
3 *
4 * Header file for the In-Memory File System
5 */
6
7/*
8 *  COPYRIGHT (c) 1989-2011.
9 *  On-Line Applications Research Corporation (OAR).
10 *
11 *  The license and distribution terms for this file may be
12 *  found in the file LICENSE in this distribution or at
13 *  http://www.rtems.com/license/LICENSE.
14 *
15 *  $Id$
16 */
17
18#ifndef _RTEMS_IMFS_H
19#define _RTEMS_IMFS_H
20
21#include <limits.h>
22
23#include <rtems/libio_.h>
24#include <rtems/pipe.h>
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30/*
31 *  Data types
32 */
33
34struct IMFS_jnode_tt;
35typedef struct IMFS_jnode_tt IMFS_jnode_t;
36
37typedef struct {
38  rtems_chain_control                    Entries;
39  rtems_filesystem_mount_table_entry_t  *mt_fs;
40}  IMFS_directory_t;
41
42typedef struct {
43  rtems_device_major_number  major;
44  rtems_device_minor_number  minor;
45}  IMFS_device_t;
46
47typedef struct {
48  IMFS_jnode_t  *link_node;
49} IMFS_link_t;
50
51typedef struct {
52  char *name;
53} IMFS_sym_link_t;
54
55typedef struct {
56  pipe_control_t  *pipe;
57} IMFS_fifo_t;
58
59/*
60 *  IMFS "memfile" information
61 *
62 *  The data structure for the in-memory "memfiles" is based on classic UNIX.
63 *
64 *  block_ptr is a pointer to a block of IMFS_MEMFILE_BYTES_PER_BLOCK in
65 *  length which could be data or a table of pointers to blocks.
66 *
67 *  Setting IMFS_MEMFILE_BYTES_PER_BLOCK to different values has a significant
68 *  impact on the maximum file size supported as well as the amount of
69 *  memory wasted due to internal file fragmentation.  The following
70 *  is a list of maximum file sizes based on various settings
71 *
72 *    max_filesize with blocks of   16 is         1,328
73 *    max_filesize with blocks of   32 is        18,656
74 *    max_filesize with blocks of   64 is       279,488
75 *    max_filesize with blocks of  128 is     4,329,344
76 *    max_filesize with blocks of  256 is    68,173,568
77 *    max_filesize with blocks of  512 is 1,082,195,456
78 */
79
80#define IMFS_MEMFILE_DEFAULT_BYTES_PER_BLOCK     128
81  extern int imfs_rq_memfile_bytes_per_block;
82  extern int imfs_memfile_bytes_per_block;
83
84#define IMFS_MEMFILE_BYTES_PER_BLOCK imfs_memfile_bytes_per_block
85#define IMFS_MEMFILE_BLOCK_SLOTS \
86  (IMFS_MEMFILE_BYTES_PER_BLOCK / sizeof(void *))
87
88typedef uint8_t *block_p;
89typedef block_p *block_ptr;
90
91typedef struct {
92  off_t         size;             /* size of file in bytes */
93  block_ptr     indirect;         /* array of 128 data blocks pointers */
94  block_ptr     doubly_indirect;  /* 128 indirect blocks */
95  block_ptr     triply_indirect;  /* 128 doubly indirect blocks */
96} IMFS_memfile_t;
97
98typedef struct {
99  off_t         size;             /* size of file in bytes */
100  block_p       direct;           /* pointer to file image */
101} IMFS_linearfile_t;
102
103/*
104 *  Important block numbers for "memfiles"
105 */
106
107#define FIRST_INDIRECT           (0)
108#define LAST_INDIRECT            (IMFS_MEMFILE_BLOCK_SLOTS - 1)
109
110#define FIRST_DOUBLY_INDIRECT    (LAST_INDIRECT + 1)
111#define LAST_DOUBLY_INDIRECT     \
112   (LAST_INDIRECT + \
113     (IMFS_MEMFILE_BLOCK_SLOTS * IMFS_MEMFILE_BLOCK_SLOTS))
114
115#define FIRST_TRIPLY_INDIRECT    (LAST_DOUBLY_INDIRECT + 1)
116#define LAST_TRIPLY_INDIRECT \
117   (LAST_DOUBLY_INDIRECT +\
118     (IMFS_MEMFILE_BLOCK_SLOTS * \
119        IMFS_MEMFILE_BLOCK_SLOTS * IMFS_MEMFILE_BLOCK_SLOTS))
120
121#define IMFS_MEMFILE_MAXIMUM_SIZE \
122  (LAST_TRIPLY_INDIRECT * IMFS_MEMFILE_BYTES_PER_BLOCK)
123
124/*
125 *  What types of IMFS file systems entities there can be.
126 */
127
128typedef enum {
129  IMFS_DIRECTORY = RTEMS_FILESYSTEM_DIRECTORY,
130  IMFS_DEVICE = RTEMS_FILESYSTEM_DEVICE,
131  IMFS_HARD_LINK = RTEMS_FILESYSTEM_HARD_LINK,
132  IMFS_SYM_LINK =  RTEMS_FILESYSTEM_SYM_LINK,
133  IMFS_MEMORY_FILE = RTEMS_FILESYSTEM_MEMORY_FILE,
134  IMFS_LINEAR_FILE,
135  IMFS_FIFO
136} IMFS_jnode_types_t;
137
138typedef union {
139  IMFS_directory_t   directory;
140  IMFS_device_t      device;
141  IMFS_link_t        hard_link;
142  IMFS_sym_link_t    sym_link;
143  IMFS_memfile_t     file;
144  IMFS_linearfile_t  linearfile;
145  IMFS_fifo_t        fifo;
146} IMFS_types_union;
147
148/*
149 * Major device number for the IMFS. This is not a real device number because
150 * the IMFS is just a file system and does not have a driver.
151 */
152#define IMFS_DEVICE_MAJOR_NUMBER (0xfffe)
153
154/*
155 *  Maximum length of a "basename" of an IMFS file/node.
156 */
157
158#define IMFS_NAME_MAX  32
159
160/*
161 *  The control structure for an IMFS jnode.
162 */
163
164struct IMFS_jnode_tt {
165  rtems_chain_node    Node;                  /* for chaining them together */
166  IMFS_jnode_t       *Parent;                /* Parent node */
167  char                name[IMFS_NAME_MAX+1]; /* "basename" */
168  mode_t              st_mode;               /* File mode */
169  nlink_t             st_nlink;              /* Link count */
170  ino_t               st_ino;                /* inode */
171
172  uid_t               st_uid;                /* User ID of owner */
173  gid_t               st_gid;                /* Group ID of owner */
174
175  time_t              stat_atime;            /* Time of last access */
176  time_t              stat_mtime;            /* Time of last modification */
177  time_t              stat_ctime;            /* Time of last status change */
178  IMFS_jnode_types_t  type;                  /* Type of this entry */
179  IMFS_types_union    info;
180};
181
182#define IMFS_update_atime( _jnode )         \
183  do {                                      \
184    struct timeval tv;                      \
185    gettimeofday( &tv, 0 );                 \
186    _jnode->stat_atime  = (time_t) tv.tv_sec; \
187  } while (0)
188
189#define IMFS_update_mtime( _jnode )         \
190  do {                                      \
191    struct timeval tv;                      \
192    gettimeofday( &tv, 0 );                 \
193    _jnode->stat_mtime  = (time_t) tv.tv_sec; \
194  } while (0)
195
196#define IMFS_update_ctime( _jnode )         \
197  do {                                      \
198    struct timeval tv;                      \
199    gettimeofday( &tv, 0 );                 \
200    _jnode->stat_ctime  = (time_t) tv.tv_sec; \
201  } while (0)
202
203#define IMFS_mtime_ctime_update( _jnode )   \
204  do {                                      \
205    struct timeval tv;                      \
206    gettimeofday( &tv, 0 );                 \
207    _jnode->stat_mtime  = (time_t) tv.tv_sec; \
208    _jnode->stat_ctime  = (time_t) tv.tv_sec; \
209  } while (0)
210
211typedef struct {
212  int                                     instance;
213  ino_t                                   ino_count;
214  const rtems_filesystem_file_handlers_r *memfile_handlers;
215  const rtems_filesystem_file_handlers_r *directory_handlers;
216  const rtems_filesystem_file_handlers_r *link_handlers;
217  const rtems_filesystem_file_handlers_r *fifo_handlers;
218} IMFS_fs_info_t;
219
220/*
221 *  Shared Data
222 */
223
224extern const rtems_filesystem_file_handlers_r       IMFS_directory_handlers;
225extern const rtems_filesystem_file_handlers_r       IMFS_device_handlers;
226extern const rtems_filesystem_file_handlers_r       IMFS_link_handlers;
227extern const rtems_filesystem_file_handlers_r       IMFS_memfile_handlers;
228extern const rtems_filesystem_file_handlers_r       IMFS_fifo_handlers;
229extern const rtems_filesystem_operations_table      IMFS_ops;
230extern const rtems_filesystem_operations_table      fifoIMFS_ops;
231extern const rtems_filesystem_limits_and_options_t  IMFS_LIMITS_AND_OPTIONS;
232
233/*
234 *  Routines
235 */
236
237extern int IMFS_initialize(
238   rtems_filesystem_mount_table_entry_t *mt_entry,
239   const void                           *data
240);
241
242extern int fifoIMFS_initialize(
243  rtems_filesystem_mount_table_entry_t  *mt_entry,
244  const void                            *data
245);
246
247extern int miniIMFS_initialize(
248   rtems_filesystem_mount_table_entry_t *mt_entry,
249   const void                           *data
250);
251
252extern int IMFS_initialize_support(
253   rtems_filesystem_mount_table_entry_t       *mt_entry,
254   const rtems_filesystem_operations_table    *op_table,
255   const rtems_filesystem_file_handlers_r     *link_handlers,
256   const rtems_filesystem_file_handlers_r     *fifo_handlers
257);
258
259extern void IMFS_fsunmount(
260   rtems_filesystem_mount_table_entry_t *mt_entry
261);
262
263extern int rtems_tarfs_load(
264   const char *mountpoint,
265   uint8_t *tar_image,
266   size_t tar_size
267);
268
269extern void IMFS_dump( void );
270
271/*
272 * Return the size of the largest file which can be created
273 * using the IMFS memory file type.
274 */
275extern int IMFS_memfile_maximum_size( void );
276
277
278extern rtems_filesystem_node_types_t IMFS_node_type(
279  const rtems_filesystem_location_info_t *loc
280);
281
282extern int IMFS_stat(
283  const rtems_filesystem_location_info_t *loc,
284  struct stat *buf
285);
286
287extern void IMFS_Set_handlers( rtems_filesystem_location_info_t *loc );
288
289extern void IMFS_eval_path(
290  rtems_filesystem_eval_path_context_t *ctx
291);
292
293extern int IMFS_link(
294  const rtems_filesystem_location_info_t *parentloc,
295  const rtems_filesystem_location_info_t *targetloc,
296  const char *name,
297  size_t namelen
298);
299
300extern int IMFS_chown(
301  const rtems_filesystem_location_info_t *loc,
302  uid_t owner,
303  gid_t group
304);
305
306extern int IMFS_mknod(
307  const rtems_filesystem_location_info_t *parentloc,
308  const char *name,
309  size_t namelen,
310  mode_t mode,
311  dev_t dev
312);
313
314extern IMFS_jnode_t *IMFS_allocate_node(
315  IMFS_jnode_types_t                type,         /* IN  */
316  const char                       *name,         /* IN  */
317  size_t                            namelen,      /* IN  */
318  mode_t                            mode          /* IN  */
319);
320
321extern IMFS_jnode_t *IMFS_create_root_node(void);
322
323extern IMFS_jnode_t *IMFS_create_node(
324  const rtems_filesystem_location_info_t *pathloc, /* IN  */
325  IMFS_jnode_types_t                      type,    /* IN  */
326  const char                             *name,    /* IN  */
327  size_t                                  namelen, /* IN  */
328  mode_t                                  mode,    /* IN  */
329  const IMFS_types_union                 *info     /* IN  */
330);
331
332extern int IMFS_mount(
333  rtems_filesystem_mount_table_entry_t *mt_entry  /* IN */
334);
335
336extern int IMFS_unmount(
337  rtems_filesystem_mount_table_entry_t *mt_entry  /* IN */
338);
339
340extern int IMFS_memfile_remove(
341 IMFS_jnode_t  *the_jnode         /* IN/OUT */
342);
343
344extern int memfile_ftruncate(
345  rtems_libio_t *iop,               /* IN  */
346  off_t          length             /* IN  */
347);
348
349extern int imfs_dir_open(
350  rtems_libio_t *iop,             /* IN  */
351  const char    *pathname,        /* IN  */
352  int            oflag,           /* IN  */
353  mode_t         mode             /* IN  */
354);
355
356extern int imfs_dir_close(
357  rtems_libio_t *iop             /* IN  */
358);
359
360extern ssize_t imfs_dir_read(
361  rtems_libio_t *iop,              /* IN  */
362  void          *buffer,           /* IN  */
363  size_t         count             /* IN  */
364);
365
366extern off_t imfs_dir_lseek(
367  rtems_libio_t        *iop,              /* IN  */
368  off_t                 offset,           /* IN  */
369  int                   whence            /* IN  */
370);
371
372extern int memfile_open(
373  rtems_libio_t *iop,             /* IN  */
374  const char    *pathname,        /* IN  */
375  int            oflag,           /* IN  */
376  mode_t         mode             /* IN  */
377);
378
379extern int memfile_close(
380  rtems_libio_t *iop             /* IN  */
381);
382
383extern ssize_t memfile_read(
384  rtems_libio_t *iop,             /* IN  */
385  void          *buffer,          /* IN  */
386  size_t         count            /* IN  */
387);
388
389extern ssize_t memfile_write(
390  rtems_libio_t *iop,             /* IN  */
391  const void    *buffer,          /* IN  */
392  size_t         count            /* IN  */
393);
394
395extern int memfile_ioctl(
396  rtems_libio_t *iop,             /* IN  */
397  uint32_t       command,         /* IN  */
398  void          *buffer           /* IN  */
399);
400
401extern off_t memfile_lseek(
402  rtems_libio_t        *iop,        /* IN  */
403  off_t                 offset,     /* IN  */
404  int                   whence      /* IN  */
405);
406
407extern int device_open(
408  rtems_libio_t *iop,            /* IN  */
409  const char    *pathname,       /* IN  */
410  int            oflag,          /* IN  */
411  mode_t         mode            /* IN  */
412);
413
414extern int device_close(
415  rtems_libio_t *iop             /* IN  */
416);
417
418extern ssize_t device_read(
419  rtems_libio_t *iop,            /* IN  */
420  void          *buffer,         /* IN  */
421  size_t         count           /* IN  */
422);
423
424extern ssize_t device_write(
425  rtems_libio_t *iop,               /* IN  */
426  const void    *buffer,            /* IN  */
427  size_t         count              /* IN  */
428);
429
430extern int device_ioctl(
431  rtems_libio_t *iop,               /* IN  */
432  uint32_t       command,           /* IN  */
433  void          *buffer             /* IN  */
434);
435
436extern off_t device_lseek(
437  rtems_libio_t *iop,               /* IN  */
438  off_t          offset,            /* IN  */
439  int            whence             /* IN  */
440);
441
442extern int device_ftruncate(
443  rtems_libio_t *iop,               /* IN  */
444  off_t          length             /* IN  */
445);
446
447extern int IMFS_utime(
448  const rtems_filesystem_location_info_t *loc,
449  time_t actime,
450  time_t modtime
451);
452
453extern int IMFS_fchmod(
454  const rtems_filesystem_location_info_t *loc,
455  mode_t mode
456);
457
458extern int IMFS_symlink(
459  const rtems_filesystem_location_info_t *parentloc,
460  const char *name,
461  size_t namelen,
462  const char *target
463);
464
465extern ssize_t IMFS_readlink(
466  const rtems_filesystem_location_info_t *loc,
467  char *buf,
468  size_t bufsize
469);
470
471extern int IMFS_rename(
472  const rtems_filesystem_location_info_t *oldparentloc,
473  const rtems_filesystem_location_info_t *oldloc,
474  const rtems_filesystem_location_info_t *newparentloc,
475  const char *name,
476  size_t namelen
477);
478
479extern int IMFS_fdatasync(
480  rtems_libio_t *iop
481);
482
483extern void IMFS_create_orphan(
484  IMFS_jnode_t *jnode
485);
486
487extern void IMFS_check_node_remove(
488  IMFS_jnode_t *jnode
489);
490
491extern int IMFS_rmnod(
492  const rtems_filesystem_location_info_t *parentloc,
493  const rtems_filesystem_location_info_t *loc
494);
495
496/*
497 *  Turn on IMFS assertions when RTEMS_DEBUG is defined.
498 */
499#ifdef RTEMS_DEBUG
500  #include <assert.h>
501
502  #define IMFS_assert(_x) assert(_x)
503#else
504  #define IMFS_assert(_x)
505#endif
506
507#ifdef __cplusplus
508}
509#endif
510
511#endif
512/* end of include file */
Note: See TracBrowser for help on using the repository browser.