source: rtems/cpukit/libfs/src/imfs/imfs.h @ ae55da72

4.115
Last change on this file since ae55da72 was 9b4422a2, checked in by Joel Sherrill <joel.sherrill@…>, on 05/03/12 at 15:09:24

Remove All CVS Id Strings Possible Using a Script

Script does what is expected and tries to do it as
smartly as possible.

+ remove occurrences of two blank comment lines

next to each other after Id string line removed.

+ remove entire comment blocks which only exited to

contain CVS Ids

+ If the processing left a blank line at the top of

a file, it was removed.

  • Property mode set to 100644
File size: 15.5 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
16#ifndef _RTEMS_IMFS_H
17#define _RTEMS_IMFS_H
18
19#include <limits.h>
20
21#include <rtems/libio_.h>
22#include <rtems/pipe.h>
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28/*
29 *  Data types
30 */
31
32struct IMFS_jnode_tt;
33typedef struct IMFS_jnode_tt IMFS_jnode_t;
34
35typedef struct {
36  rtems_chain_control                    Entries;
37  rtems_filesystem_mount_table_entry_t  *mt_fs;
38}  IMFS_directory_t;
39
40typedef struct {
41  rtems_device_major_number  major;
42  rtems_device_minor_number  minor;
43}  IMFS_device_t;
44
45typedef struct {
46  IMFS_jnode_t  *link_node;
47} IMFS_link_t;
48
49typedef struct {
50  char *name;
51} IMFS_sym_link_t;
52
53typedef struct {
54  pipe_control_t  *pipe;
55} IMFS_fifo_t;
56
57typedef struct {
58  void *context;
59} IMFS_generic_t;
60
61/*
62 *  IMFS "memfile" information
63 *
64 *  The data structure for the in-memory "memfiles" is based on classic UNIX.
65 *
66 *  block_ptr is a pointer to a block of IMFS_MEMFILE_BYTES_PER_BLOCK in
67 *  length which could be data or a table of pointers to blocks.
68 *
69 *  Setting IMFS_MEMFILE_BYTES_PER_BLOCK to different values has a significant
70 *  impact on the maximum file size supported as well as the amount of
71 *  memory wasted due to internal file fragmentation.  The following
72 *  is a list of maximum file sizes based on various settings
73 *
74 *    max_filesize with blocks of   16 is         1,328
75 *    max_filesize with blocks of   32 is        18,656
76 *    max_filesize with blocks of   64 is       279,488
77 *    max_filesize with blocks of  128 is     4,329,344
78 *    max_filesize with blocks of  256 is    68,173,568
79 *    max_filesize with blocks of  512 is 1,082,195,456
80 */
81
82#define IMFS_MEMFILE_DEFAULT_BYTES_PER_BLOCK     128
83  extern int imfs_rq_memfile_bytes_per_block;
84  extern int imfs_memfile_bytes_per_block;
85
86#define IMFS_MEMFILE_BYTES_PER_BLOCK imfs_memfile_bytes_per_block
87#define IMFS_MEMFILE_BLOCK_SLOTS \
88  (IMFS_MEMFILE_BYTES_PER_BLOCK / sizeof(void *))
89
90typedef uint8_t *block_p;
91typedef block_p *block_ptr;
92
93typedef struct {
94  off_t         size;             /* size of file in bytes */
95  block_ptr     indirect;         /* array of 128 data blocks pointers */
96  block_ptr     doubly_indirect;  /* 128 indirect blocks */
97  block_ptr     triply_indirect;  /* 128 doubly indirect blocks */
98} IMFS_memfile_t;
99
100typedef struct {
101  off_t         size;             /* size of file in bytes */
102  block_p       direct;           /* pointer to file image */
103} IMFS_linearfile_t;
104
105/*
106 *  Important block numbers for "memfiles"
107 */
108
109#define FIRST_INDIRECT           (0)
110#define LAST_INDIRECT            (IMFS_MEMFILE_BLOCK_SLOTS - 1)
111
112#define FIRST_DOUBLY_INDIRECT    (LAST_INDIRECT + 1)
113#define LAST_DOUBLY_INDIRECT     \
114   (LAST_INDIRECT + \
115     (IMFS_MEMFILE_BLOCK_SLOTS * IMFS_MEMFILE_BLOCK_SLOTS))
116
117#define FIRST_TRIPLY_INDIRECT    (LAST_DOUBLY_INDIRECT + 1)
118#define LAST_TRIPLY_INDIRECT \
119   (LAST_DOUBLY_INDIRECT +\
120     (IMFS_MEMFILE_BLOCK_SLOTS * \
121        IMFS_MEMFILE_BLOCK_SLOTS * IMFS_MEMFILE_BLOCK_SLOTS))
122
123#define IMFS_MEMFILE_MAXIMUM_SIZE \
124  (LAST_TRIPLY_INDIRECT * IMFS_MEMFILE_BYTES_PER_BLOCK)
125
126/*
127 *  What types of IMFS file systems entities there can be.
128 */
129
130typedef enum {
131  IMFS_DIRECTORY = RTEMS_FILESYSTEM_DIRECTORY,
132  IMFS_DEVICE = RTEMS_FILESYSTEM_DEVICE,
133  IMFS_HARD_LINK = RTEMS_FILESYSTEM_HARD_LINK,
134  IMFS_SYM_LINK =  RTEMS_FILESYSTEM_SYM_LINK,
135  IMFS_MEMORY_FILE = RTEMS_FILESYSTEM_MEMORY_FILE,
136  IMFS_LINEAR_FILE,
137  IMFS_FIFO,
138  IMFS_GENERIC,
139  IMFS_INVALID_NODE
140} IMFS_jnode_types_t;
141
142/* The IMFS_GENERIC does not count */
143#define IMFS_TYPE_COUNT (IMFS_FIFO + 1)
144
145typedef union {
146  IMFS_directory_t   directory;
147  IMFS_device_t      device;
148  IMFS_link_t        hard_link;
149  IMFS_sym_link_t    sym_link;
150  IMFS_memfile_t     file;
151  IMFS_linearfile_t  linearfile;
152  IMFS_fifo_t        fifo;
153  IMFS_generic_t     generic;
154} IMFS_types_union;
155
156typedef IMFS_jnode_t *(*IMFS_node_control_initialize)(
157  IMFS_jnode_t *node,
158  const IMFS_types_union *info
159);
160
161IMFS_jnode_t *IMFS_node_initialize_default(
162  IMFS_jnode_t *node,
163  const IMFS_types_union *info
164);
165
166IMFS_jnode_t *IMFS_node_initialize_generic(
167  IMFS_jnode_t *node,
168  const IMFS_types_union *info
169);
170
171typedef IMFS_jnode_t *(*IMFS_node_control_remove)(
172  IMFS_jnode_t *node,
173  const IMFS_jnode_t *root_node
174);
175
176IMFS_jnode_t *IMFS_node_remove_default(
177  IMFS_jnode_t *node,
178  const IMFS_jnode_t *root_node
179);
180
181typedef IMFS_jnode_t *(*IMFS_node_control_destroy)( IMFS_jnode_t *node );
182
183IMFS_jnode_t *IMFS_node_destroy_default( IMFS_jnode_t *node );
184
185typedef struct {
186  IMFS_jnode_types_t imfs_type;
187  const rtems_filesystem_file_handlers_r *handlers;
188  IMFS_node_control_initialize node_initialize;
189  IMFS_node_control_remove node_remove;
190  IMFS_node_control_destroy node_destroy;
191} IMFS_node_control;
192
193/*
194 * Major device number for the IMFS. This is not a real device number because
195 * the IMFS is just a file system and does not have a driver.
196 */
197#define IMFS_DEVICE_MAJOR_NUMBER (0xfffe)
198
199#define IMFS_GENERIC_DEVICE_MAJOR_NUMBER (0xfffd)
200
201/*
202 *  Maximum length of a "basename" of an IMFS file/node.
203 */
204
205#define IMFS_NAME_MAX  32
206
207/*
208 *  The control structure for an IMFS jnode.
209 */
210
211struct IMFS_jnode_tt {
212  rtems_chain_node    Node;                  /* for chaining them together */
213  IMFS_jnode_t       *Parent;                /* Parent node */
214  char                name[IMFS_NAME_MAX+1]; /* "basename" */
215  mode_t              st_mode;               /* File mode */
216  unsigned short      reference_count;
217  nlink_t             st_nlink;              /* Link count */
218  ino_t               st_ino;                /* inode */
219
220  uid_t               st_uid;                /* User ID of owner */
221  gid_t               st_gid;                /* Group ID of owner */
222
223  time_t              stat_atime;            /* Time of last access */
224  time_t              stat_mtime;            /* Time of last modification */
225  time_t              stat_ctime;            /* Time of last status change */
226  const IMFS_node_control *control;
227  IMFS_types_union    info;
228};
229
230#define IMFS_update_atime( _jnode )         \
231  do {                                      \
232    struct timeval tv;                      \
233    gettimeofday( &tv, 0 );                 \
234    _jnode->stat_atime  = (time_t) tv.tv_sec; \
235  } while (0)
236
237#define IMFS_update_mtime( _jnode )         \
238  do {                                      \
239    struct timeval tv;                      \
240    gettimeofday( &tv, 0 );                 \
241    _jnode->stat_mtime  = (time_t) tv.tv_sec; \
242  } while (0)
243
244#define IMFS_update_ctime( _jnode )         \
245  do {                                      \
246    struct timeval tv;                      \
247    gettimeofday( &tv, 0 );                 \
248    _jnode->stat_ctime  = (time_t) tv.tv_sec; \
249  } while (0)
250
251#define IMFS_mtime_ctime_update( _jnode )   \
252  do {                                      \
253    struct timeval tv;                      \
254    gettimeofday( &tv, 0 );                 \
255    _jnode->stat_mtime  = (time_t) tv.tv_sec; \
256    _jnode->stat_ctime  = (time_t) tv.tv_sec; \
257  } while (0)
258
259typedef struct {
260  int instance;
261  ino_t ino_count;
262  const IMFS_node_control *node_controls [IMFS_TYPE_COUNT];
263} IMFS_fs_info_t;
264
265/*
266 *  Shared Data
267 */
268
269extern const IMFS_node_control IMFS_node_control_directory;
270extern const IMFS_node_control IMFS_node_control_device;
271extern const IMFS_node_control IMFS_node_control_hard_link;
272extern const IMFS_node_control IMFS_node_control_sym_link;
273extern const IMFS_node_control IMFS_node_control_memfile;
274extern const IMFS_node_control IMFS_node_control_linfile;
275extern const IMFS_node_control IMFS_node_control_fifo;
276extern const IMFS_node_control IMFS_node_control_default;
277
278extern const rtems_filesystem_operations_table miniIMFS_ops;
279extern const rtems_filesystem_operations_table IMFS_ops;
280extern const rtems_filesystem_operations_table fifoIMFS_ops;
281
282extern const rtems_filesystem_limits_and_options_t  IMFS_LIMITS_AND_OPTIONS;
283
284/*
285 *  Routines
286 */
287
288extern int IMFS_initialize(
289   rtems_filesystem_mount_table_entry_t *mt_entry,
290   const void                           *data
291);
292
293extern int fifoIMFS_initialize(
294  rtems_filesystem_mount_table_entry_t  *mt_entry,
295  const void                            *data
296);
297
298extern int miniIMFS_initialize(
299   rtems_filesystem_mount_table_entry_t *mt_entry,
300   const void                           *data
301);
302
303extern int IMFS_initialize_support(
304  rtems_filesystem_mount_table_entry_t *mt_entry,
305  const rtems_filesystem_operations_table *op_table,
306  const IMFS_node_control *const node_controls [IMFS_TYPE_COUNT]
307);
308
309extern void IMFS_fsunmount(
310   rtems_filesystem_mount_table_entry_t *mt_entry
311);
312
313extern int rtems_tarfs_load(
314   const char *mountpoint,
315   uint8_t *tar_image,
316   size_t tar_size
317);
318
319extern void IMFS_dump( void );
320
321/*
322 * Return the size of the largest file which can be created
323 * using the IMFS memory file type.
324 */
325extern int IMFS_memfile_maximum_size( void );
326
327extern void IMFS_node_destroy( IMFS_jnode_t *node );
328
329extern int IMFS_node_clone( rtems_filesystem_location_info_t *loc );
330
331extern void IMFS_node_free( const rtems_filesystem_location_info_t *loc );
332
333extern rtems_filesystem_node_types_t IMFS_node_type(
334  const rtems_filesystem_location_info_t *loc
335);
336
337extern int IMFS_stat(
338  const rtems_filesystem_location_info_t *loc,
339  struct stat *buf
340);
341
342extern void IMFS_eval_path(
343  rtems_filesystem_eval_path_context_t *ctx
344);
345
346extern int IMFS_link(
347  const rtems_filesystem_location_info_t *parentloc,
348  const rtems_filesystem_location_info_t *targetloc,
349  const char *name,
350  size_t namelen
351);
352
353extern int IMFS_chown(
354  const rtems_filesystem_location_info_t *loc,
355  uid_t owner,
356  gid_t group
357);
358
359extern int IMFS_mknod(
360  const rtems_filesystem_location_info_t *parentloc,
361  const char *name,
362  size_t namelen,
363  mode_t mode,
364  dev_t dev
365);
366
367extern IMFS_jnode_t *IMFS_allocate_node(
368  IMFS_fs_info_t *fs_info,
369  const IMFS_node_control *node_control,
370  const char *name,
371  size_t namelen,
372  mode_t mode,
373  const IMFS_types_union *info
374);
375
376extern IMFS_jnode_t *IMFS_create_node_with_control(
377  const rtems_filesystem_location_info_t *parentloc,
378  const IMFS_node_control *node_control,
379  const char *name,
380  size_t namelen,
381  mode_t mode,
382  const IMFS_types_union *info
383);
384
385extern bool IMFS_is_imfs_instance(
386  const rtems_filesystem_location_info_t *loc
387);
388
389extern int IMFS_make_generic_node(
390  const char *path,
391  mode_t mode,
392  const IMFS_node_control *node_control,
393  void *context
394);
395
396extern int IMFS_mount(
397  rtems_filesystem_mount_table_entry_t *mt_entry  /* IN */
398);
399
400extern int IMFS_unmount(
401  rtems_filesystem_mount_table_entry_t *mt_entry  /* IN */
402);
403
404extern IMFS_jnode_t *IMFS_memfile_remove(
405 IMFS_jnode_t  *the_jnode         /* IN/OUT */
406);
407
408extern int memfile_ftruncate(
409  rtems_libio_t *iop,               /* IN  */
410  off_t          length             /* IN  */
411);
412
413extern ssize_t imfs_dir_read(
414  rtems_libio_t *iop,              /* IN  */
415  void          *buffer,           /* IN  */
416  size_t         count             /* IN  */
417);
418
419extern int memfile_open(
420  rtems_libio_t *iop,             /* IN  */
421  const char    *pathname,        /* IN  */
422  int            oflag,           /* IN  */
423  mode_t         mode             /* IN  */
424);
425
426extern ssize_t memfile_read(
427  rtems_libio_t *iop,             /* IN  */
428  void          *buffer,          /* IN  */
429  size_t         count            /* IN  */
430);
431
432extern ssize_t memfile_write(
433  rtems_libio_t *iop,             /* IN  */
434  const void    *buffer,          /* IN  */
435  size_t         count            /* IN  */
436);
437
438extern int memfile_ioctl(
439  rtems_libio_t *iop,             /* IN  */
440  uint32_t       command,         /* IN  */
441  void          *buffer           /* IN  */
442);
443
444extern int device_open(
445  rtems_libio_t *iop,            /* IN  */
446  const char    *pathname,       /* IN  */
447  int            oflag,          /* IN  */
448  mode_t         mode            /* IN  */
449);
450
451extern int device_close(
452  rtems_libio_t *iop             /* IN  */
453);
454
455extern ssize_t device_read(
456  rtems_libio_t *iop,            /* IN  */
457  void          *buffer,         /* IN  */
458  size_t         count           /* IN  */
459);
460
461extern ssize_t device_write(
462  rtems_libio_t *iop,               /* IN  */
463  const void    *buffer,            /* IN  */
464  size_t         count              /* IN  */
465);
466
467extern int device_ioctl(
468  rtems_libio_t *iop,               /* IN  */
469  uint32_t       command,           /* IN  */
470  void          *buffer             /* IN  */
471);
472
473extern int device_ftruncate(
474  rtems_libio_t *iop,               /* IN  */
475  off_t          length             /* IN  */
476);
477
478extern int IMFS_utime(
479  const rtems_filesystem_location_info_t *loc,
480  time_t actime,
481  time_t modtime
482);
483
484extern int IMFS_fchmod(
485  const rtems_filesystem_location_info_t *loc,
486  mode_t mode
487);
488
489extern int IMFS_symlink(
490  const rtems_filesystem_location_info_t *parentloc,
491  const char *name,
492  size_t namelen,
493  const char *target
494);
495
496extern ssize_t IMFS_readlink(
497  const rtems_filesystem_location_info_t *loc,
498  char *buf,
499  size_t bufsize
500);
501
502extern int IMFS_rename(
503  const rtems_filesystem_location_info_t *oldparentloc,
504  const rtems_filesystem_location_info_t *oldloc,
505  const rtems_filesystem_location_info_t *newparentloc,
506  const char *name,
507  size_t namelen
508);
509
510extern int IMFS_rmnod(
511  const rtems_filesystem_location_info_t *parentloc,
512  const rtems_filesystem_location_info_t *loc
513);
514
515/*
516 *  Turn on IMFS assertions when RTEMS_DEBUG is defined.
517 */
518#ifdef RTEMS_DEBUG
519  #include <assert.h>
520
521  #define IMFS_assert(_x) assert(_x)
522#else
523  #define IMFS_assert(_x)
524#endif
525
526static inline void IMFS_Set_handlers( rtems_filesystem_location_info_t *loc )
527{
528  IMFS_jnode_t *node = (IMFS_jnode_t *) loc->node_access;
529
530  loc->handlers = node->control->handlers;
531}
532
533static inline void IMFS_add_to_directory(
534  IMFS_jnode_t *dir,
535  IMFS_jnode_t *node
536)
537{
538  node->Parent = dir;
539  rtems_chain_append_unprotected( &dir->info.directory.Entries, &node->Node );
540}
541
542static inline void IMFS_remove_from_directory( IMFS_jnode_t *node )
543{
544  IMFS_assert( node->Parent != NULL );
545  node->Parent = NULL;
546  rtems_chain_extract_unprotected( &node->Node );
547}
548
549static inline IMFS_jnode_types_t IMFS_type( const IMFS_jnode_t *node )
550{
551  return node->control->imfs_type;
552}
553
554static inline bool IMFS_is_directory( const IMFS_jnode_t *node )
555{
556  return node->control->imfs_type == IMFS_DIRECTORY;
557}
558
559static inline IMFS_jnode_t *IMFS_create_node(
560  const rtems_filesystem_location_info_t *parentloc,
561  IMFS_jnode_types_t type,
562  const char *name,
563  size_t namelen,
564  mode_t mode,
565  const IMFS_types_union *info
566)
567{
568  const IMFS_fs_info_t *fs_info =
569    (const IMFS_fs_info_t *) parentloc->mt_entry->fs_info;
570
571  return IMFS_create_node_with_control(
572    parentloc,
573    fs_info->node_controls [type],
574    name,
575    namelen,
576    mode,
577    info
578  );
579}
580
581static inline void *IMFS_generic_get_context_by_node(
582  const IMFS_jnode_t *node
583)
584{
585  return node->info.generic.context;
586}
587
588static inline void *IMFS_generic_get_context_by_location(
589  const rtems_filesystem_location_info_t *loc
590)
591{
592  const IMFS_jnode_t *node = (const IMFS_jnode_t *) loc->node_access;
593
594  return IMFS_generic_get_context_by_node( node );
595}
596
597static inline void *IMFS_generic_get_context_by_iop(
598  const rtems_libio_t *iop
599)
600{
601  return IMFS_generic_get_context_by_location( &iop->pathinfo );
602}
603
604static inline dev_t IMFS_generic_get_device_identifier_by_node(
605  const IMFS_jnode_t *node
606)
607{
608  return rtems_filesystem_make_dev_t(
609    IMFS_GENERIC_DEVICE_MAJOR_NUMBER,
610    node->st_ino
611  );
612}
613
614#ifdef __cplusplus
615}
616#endif
617
618#endif
619/* end of include file */
Note: See TracBrowser for help on using the repository browser.