source: rtems/cpukit/libfs/src/imfs/imfs.h @ 21242c2

4.115
Last change on this file since 21242c2 was 21242c2, checked in by Joel Sherrill <joel.sherrill@…>, on 06/24/11 at 17:52:58

2011-06-24 Joel Sherrill <joel.sherrill@…>

  • include/rtems/bspIo.h, include/rtems/concat.h, include/rtems/endian.h, include/rtems/fs.h, include/rtems/irq.h, include/rtems/pci.h, include/rtems/userenv.h, libblock/include/rtems/flashdisk.h, libblock/include/rtems/nvdisk-sram.h, libblock/include/rtems/nvdisk.h, libcsupport/include/clockdrv.h, libcsupport/include/console.h, libcsupport/include/iosupp.h, libcsupport/include/spurious.h, libcsupport/include/motorola/mc68230.h, libcsupport/include/rtems/assoc.h, libcsupport/include/rtems/error.h, libcsupport/include/rtems/framebuffer.h, libcsupport/include/rtems/gxx_wrappers.h, libcsupport/include/rtems/libcsupport.h, libcsupport/include/rtems/libio_.h, libcsupport/include/rtems/malloc.h, libcsupport/include/rtems/termiostypes.h, libcsupport/include/sys/statvfs.h, libcsupport/include/sys/termios.h, libcsupport/include/sys/utsname.h, libcsupport/include/zilog/z8036.h, libcsupport/include/zilog/z8530.h, libcsupport/include/zilog/z8536.h, libfs/src/imfs/imfs.h, libfs/src/pipe/pipe.h, libmisc/capture/capture-cli.h, libmisc/capture/capture.h, libmisc/cpuuse/cpuuse.h, libmisc/devnull/devnull.h, libmisc/devnull/devzero.h, libmisc/dumpbuf/dumpbuf.h, libmisc/fb/fb.h, libmisc/fb/mw_uid.h, libmisc/mouse/mouse_parser.h, libmisc/shell/shellconfig.h, libmisc/stringto/stringto.h, libmisc/untar/untar.h, libnetworking/memory.h, posix/include/aio.h, posix/include/mqueue.h, posix/include/semaphore.h, posix/include/rtems/posix/aio_misc.h, posix/include/rtems/posix/barrier.h, posix/include/rtems/posix/cond.h, posix/include/rtems/posix/config.h, posix/include/rtems/posix/key.h, posix/include/rtems/posix/mqueue.h, posix/include/rtems/posix/mutex.h, posix/include/rtems/posix/posixapi.h, posix/include/rtems/posix/priority.h, posix/include/rtems/posix/psignal.h, posix/include/rtems/posix/pthread.h, posix/include/rtems/posix/ptimer.h, posix/include/rtems/posix/rwlock.h, posix/include/rtems/posix/semaphore.h, posix/include/rtems/posix/sigset.h, posix/include/rtems/posix/spinlock.h, posix/include/rtems/posix/threadsup.h, posix/include/rtems/posix/time.h, posix/include/rtems/posix/timer.h, posix/inline/rtems/posix/barrier.inl, posix/inline/rtems/posix/cond.inl, posix/inline/rtems/posix/mqueue.inl, posix/inline/rtems/posix/mutex.inl, posix/inline/rtems/posix/priority.inl, posix/inline/rtems/posix/pthread.inl, posix/inline/rtems/posix/rwlock.inl, posix/inline/rtems/posix/semaphore.inl, posix/inline/rtems/posix/spinlock.inl, posix/inline/rtems/posix/timer.inl, rtems/mainpage.h, rtems/include/rtems/rtems/barrier.h, rtems/include/rtems/rtems/object.h, rtems/include/rtems/rtems/timer.h, rtems/inline/rtems/rtems/barrier.inl, rtems/inline/rtems/rtems/timer.inl, rtems/src/semtranslatereturncode.c, sapi/include/rtems/config.h, sapi/include/rtems/fatal.h, sapi/include/rtems/mptables.h, score/include/rtems/score/object.h, score/include/rtems/score/priority.h, score/inline/rtems/score/object.inl, score/inline/rtems/score/priority.inl: Add @file Doxygen directives and descriptions to files which originated with RTEMS. This improves the file list page generated by Doxygen.
  • Property mode set to 100644
File size: 16.1 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 <rtems.h>
22#include <rtems/chain.h>
23
24#include <sys/types.h>
25#include <limits.h>
26#include <rtems/libio.h>
27
28#include <rtems/pipe.h>
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34/*
35 *  File name macros
36 */
37
38#define IMFS_is_valid_name_char( _ch ) ( 1 )
39
40#define IMFS_is_separator( _ch ) \
41   rtems_filesystem_is_separator( _ch )
42
43/*
44 *  Data types
45 */
46
47struct IMFS_jnode_tt;
48typedef struct IMFS_jnode_tt IMFS_jnode_t;
49
50typedef struct {
51  rtems_chain_control                    Entries;
52  rtems_filesystem_mount_table_entry_t  *mt_fs;
53}  IMFS_directory_t;
54
55typedef struct {
56  rtems_device_major_number  major;
57  rtems_device_minor_number  minor;
58}  IMFS_device_t;
59
60typedef struct {
61  IMFS_jnode_t  *link_node;
62} IMFS_link_t;
63
64typedef struct {
65  char *name;
66} IMFS_sym_link_t;
67
68typedef struct {
69  pipe_control_t  *pipe;
70} IMFS_fifo_t;
71
72/*
73 *  IMFS "memfile" information
74 *
75 *  The data structure for the in-memory "memfiles" is based on classic UNIX.
76 *
77 *  block_ptr is a pointer to a block of IMFS_MEMFILE_BYTES_PER_BLOCK in
78 *  length which could be data or a table of pointers to blocks.
79 *
80 *  Setting IMFS_MEMFILE_BYTES_PER_BLOCK to different values has a significant
81 *  impact on the maximum file size supported as well as the amount of
82 *  memory wasted due to internal file fragmentation.  The following
83 *  is a list of maximum file sizes based on various settings
84 *
85 *    max_filesize with blocks of   16 is         1,328
86 *    max_filesize with blocks of   32 is        18,656
87 *    max_filesize with blocks of   64 is       279,488
88 *    max_filesize with blocks of  128 is     4,329,344
89 *    max_filesize with blocks of  256 is    68,173,568
90 *    max_filesize with blocks of  512 is 1,082,195,456
91 */
92
93#define IMFS_MEMFILE_DEFAULT_BYTES_PER_BLOCK     128
94  extern int imfs_rq_memfile_bytes_per_block;
95  extern int imfs_memfile_bytes_per_block;
96
97#define IMFS_MEMFILE_BYTES_PER_BLOCK imfs_memfile_bytes_per_block
98#define IMFS_MEMFILE_BLOCK_SLOTS \
99  (IMFS_MEMFILE_BYTES_PER_BLOCK / sizeof(void *))
100
101typedef uint8_t *block_p;
102typedef block_p *block_ptr;
103
104typedef struct {
105  rtems_off64_t size;             /* size of file in bytes */
106  block_ptr     indirect;         /* array of 128 data blocks pointers */
107  block_ptr     doubly_indirect;  /* 128 indirect blocks */
108  block_ptr     triply_indirect;  /* 128 doubly indirect blocks */
109} IMFS_memfile_t;
110
111typedef struct {
112  rtems_off64_t size;             /* size of file in bytes */
113  block_p       direct;           /* pointer to file image */
114} IMFS_linearfile_t;
115
116/*
117 *  Important block numbers for "memfiles"
118 */
119
120#define FIRST_INDIRECT           (0)
121#define LAST_INDIRECT            (IMFS_MEMFILE_BLOCK_SLOTS - 1)
122
123#define FIRST_DOUBLY_INDIRECT    (LAST_INDIRECT + 1)
124#define LAST_DOUBLY_INDIRECT     \
125   (LAST_INDIRECT + \
126     (IMFS_MEMFILE_BLOCK_SLOTS * IMFS_MEMFILE_BLOCK_SLOTS))
127
128#define FIRST_TRIPLY_INDIRECT    (LAST_DOUBLY_INDIRECT + 1)
129#define LAST_TRIPLY_INDIRECT \
130   (LAST_DOUBLY_INDIRECT +\
131     (IMFS_MEMFILE_BLOCK_SLOTS * \
132        IMFS_MEMFILE_BLOCK_SLOTS * IMFS_MEMFILE_BLOCK_SLOTS))
133
134#define IMFS_MEMFILE_MAXIMUM_SIZE \
135  (LAST_TRIPLY_INDIRECT * IMFS_MEMFILE_BYTES_PER_BLOCK)
136
137/*
138 *  What types of IMFS file systems entities there can be.
139 */
140
141typedef enum {
142  IMFS_DIRECTORY = RTEMS_FILESYSTEM_DIRECTORY,
143  IMFS_DEVICE = RTEMS_FILESYSTEM_DEVICE,
144  IMFS_HARD_LINK = RTEMS_FILESYSTEM_HARD_LINK,
145  IMFS_SYM_LINK =  RTEMS_FILESYSTEM_SYM_LINK,
146  IMFS_MEMORY_FILE = RTEMS_FILESYSTEM_MEMORY_FILE,
147  IMFS_LINEAR_FILE,
148  IMFS_FIFO
149} IMFS_jnode_types_t;
150
151typedef union {
152  IMFS_directory_t   directory;
153  IMFS_device_t      device;
154  IMFS_link_t        hard_link;
155  IMFS_sym_link_t    sym_link;
156  IMFS_memfile_t     file;
157  IMFS_linearfile_t  linearfile;
158  IMFS_fifo_t        fifo;
159} IMFS_types_union;
160
161/*
162 * Major device number for the IMFS. This is not a real device number because
163 * the IMFS is just a file system and does not have a driver.
164 */
165#define IMFS_DEVICE_MAJOR_NUMBER (0xfffe)
166
167/*
168 *  Maximum length of a "basename" of an IMFS file/node.
169 */
170
171#define IMFS_NAME_MAX  32
172
173/*
174 *  The control structure for an IMFS jnode.
175 */
176
177struct IMFS_jnode_tt {
178  rtems_chain_node    Node;                  /* for chaining them together */
179  IMFS_jnode_t       *Parent;                /* Parent node */
180  char                name[IMFS_NAME_MAX+1]; /* "basename" */
181  mode_t              st_mode;               /* File mode */
182  nlink_t             st_nlink;              /* Link count */
183  ino_t               st_ino;                /* inode */
184
185  uid_t               st_uid;                /* User ID of owner */
186  gid_t               st_gid;                /* Group ID of owner */
187
188  time_t              stat_atime;            /* Time of last access */
189  time_t              stat_mtime;            /* Time of last modification */
190  time_t              stat_ctime;            /* Time of last status change */
191  IMFS_jnode_types_t  type;                  /* Type of this entry */
192  IMFS_types_union    info;
193};
194
195#define IMFS_update_atime( _jnode )         \
196  do {                                      \
197    struct timeval tv;                      \
198    gettimeofday( &tv, 0 );                 \
199    _jnode->stat_atime  = (time_t) tv.tv_sec; \
200  } while (0)
201
202#define IMFS_update_mtime( _jnode )         \
203  do {                                      \
204    struct timeval tv;                      \
205    gettimeofday( &tv, 0 );                 \
206    _jnode->stat_mtime  = (time_t) tv.tv_sec; \
207  } while (0)
208
209#define IMFS_update_ctime( _jnode )         \
210  do {                                      \
211    struct timeval tv;                      \
212    gettimeofday( &tv, 0 );                 \
213    _jnode->stat_ctime  = (time_t) tv.tv_sec; \
214  } while (0)
215
216#define IMFS_mtime_ctime_update( _jnode )   \
217  do {                                      \
218    struct timeval tv;                      \
219    gettimeofday( &tv, 0 );                 \
220    _jnode->stat_mtime  = (time_t) tv.tv_sec; \
221    _jnode->stat_ctime  = (time_t) tv.tv_sec; \
222  } while (0)
223
224typedef struct {
225  int                                     instance;
226  ino_t                                   ino_count;
227  const rtems_filesystem_file_handlers_r *memfile_handlers;
228  const rtems_filesystem_file_handlers_r *directory_handlers;
229  const rtems_filesystem_file_handlers_r *fifo_handlers;
230} IMFS_fs_info_t;
231
232/*
233 *  Type defination for tokens returned from IMFS_get_token
234 */
235
236typedef enum {
237  IMFS_NO_MORE_PATH,
238  IMFS_CURRENT_DIR,
239  IMFS_UP_DIR,
240  IMFS_NAME,
241  IMFS_INVALID_TOKEN
242} IMFS_token_types;
243
244/*
245 *  Shared Data
246 */
247
248extern const rtems_filesystem_file_handlers_r       IMFS_directory_handlers;
249extern const rtems_filesystem_file_handlers_r       IMFS_device_handlers;
250extern const rtems_filesystem_file_handlers_r       IMFS_link_handlers;
251extern const rtems_filesystem_file_handlers_r       IMFS_memfile_handlers;
252extern const rtems_filesystem_file_handlers_r       IMFS_fifo_handlers;
253extern const rtems_filesystem_operations_table      IMFS_ops;
254extern const rtems_filesystem_operations_table      fifoIMFS_ops;
255extern const rtems_filesystem_limits_and_options_t  IMFS_LIMITS_AND_OPTIONS;
256
257/*
258 *  Routines
259 */
260
261extern int IMFS_initialize(
262   rtems_filesystem_mount_table_entry_t *mt_entry,
263   const void                           *data
264);
265
266extern int fifoIMFS_initialize(
267  rtems_filesystem_mount_table_entry_t  *mt_entry,
268  const void                            *data
269);
270
271extern int miniIMFS_initialize(
272   rtems_filesystem_mount_table_entry_t *mt_entry,
273   const void                           *data
274);
275
276extern int IMFS_initialize_support(
277   rtems_filesystem_mount_table_entry_t       *mt_entry,
278   const rtems_filesystem_operations_table    *op_table,
279   const rtems_filesystem_file_handlers_r     *memfile_handlers,
280   const rtems_filesystem_file_handlers_r     *directory_handlers,
281   const rtems_filesystem_file_handlers_r     *fifo_handlers
282);
283
284extern int IMFS_fsunmount(
285   rtems_filesystem_mount_table_entry_t *mt_entry
286);
287
288extern int rtems_tarfs_load(
289   char         *mountpoint,
290   uint8_t      *tar_image,
291   size_t        tar_size
292);
293
294/*
295 * Returns the number of characters copied from path to token.
296 */
297extern IMFS_token_types IMFS_get_token(
298  const char       *path,
299  int               pathlen,
300  char             *token,
301  int              *token_len
302);
303
304extern void IMFS_dump( void );
305
306extern void IMFS_initialize_jnode(
307  IMFS_jnode_t        *the_jnode,
308  IMFS_jnode_types_t   type,
309  IMFS_jnode_t        *the_parent,
310  char                *name,
311  mode_t               mode
312);
313
314extern IMFS_jnode_t *IMFS_find_match_in_dir(
315  IMFS_jnode_t *directory,                         /* IN */
316  char         *name                               /* IN */
317);
318
319extern rtems_filesystem_node_types_t IMFS_node_type(
320  rtems_filesystem_location_info_t    *pathloc     /* IN */
321);
322
323extern int IMFS_stat(
324  rtems_filesystem_location_info_t *loc,           /* IN  */
325  struct stat                      *buf            /* OUT */
326);
327
328extern int IMFS_Set_handlers(
329  rtems_filesystem_location_info_t   *loc
330);
331
332extern int IMFS_evaluate_link(
333  rtems_filesystem_location_info_t *node,        /* IN/OUT */
334  int                               flags        /* IN     */
335);
336
337extern int IMFS_eval_path(
338  const char                        *pathname,     /* IN     */
339  size_t                            pathnamelen,   /* IN     */
340  int                               flags,         /* IN     */
341  rtems_filesystem_location_info_t  *pathloc       /* IN/OUT */
342);
343
344extern int IMFS_link(
345  rtems_filesystem_location_info_t  *to_loc,      /* IN */
346  rtems_filesystem_location_info_t  *parent_loc,  /* IN */
347  const char                        *token        /* IN */
348);
349
350extern int IMFS_unlink(
351  rtems_filesystem_location_info_t  *parent_pathloc, /* IN */
352  rtems_filesystem_location_info_t  *pathloc         /* IN */
353);
354
355extern int IMFS_chown(
356  rtems_filesystem_location_info_t  *pathloc,      /* IN */
357  uid_t                              owner,        /* IN */
358  gid_t                              group         /* IN */
359);
360
361extern int IMFS_mknod(
362  const char                        *path,         /* IN */
363  mode_t                             mode,         /* IN */
364  dev_t                              dev,          /* IN */
365  rtems_filesystem_location_info_t  *pathloc       /* IN/OUT */
366);
367
368extern IMFS_jnode_t *IMFS_allocate_node(
369  IMFS_jnode_types_t                type,         /* IN  */
370  const char                       *name,         /* IN  */
371  mode_t                            mode          /* IN  */
372);
373
374extern IMFS_jnode_t *IMFS_create_root_node(void);
375
376extern IMFS_jnode_t *IMFS_create_node(
377  rtems_filesystem_location_info_t *parent_loc,   /* IN  */
378  IMFS_jnode_types_t                type,         /* IN  */
379  const char                       *name,         /* IN  */
380  mode_t                            mode,         /* IN  */
381  const IMFS_types_union           *info          /* IN  */
382);
383
384extern int IMFS_evaluate_for_make(
385  const char                         *path,       /* IN     */
386  rtems_filesystem_location_info_t   *pathloc,    /* IN/OUT */
387  const char                        **name        /* OUT    */
388);
389
390extern int IMFS_mount(
391  rtems_filesystem_mount_table_entry_t *mt_entry  /* IN */
392);
393
394extern int IMFS_unmount(
395  rtems_filesystem_mount_table_entry_t *mt_entry  /* IN */
396);
397
398extern int IMFS_memfile_remove(
399 IMFS_jnode_t  *the_jnode         /* IN/OUT */
400);
401
402extern int memfile_ftruncate(
403  rtems_libio_t *iop,               /* IN  */
404  rtems_off64_t  length             /* IN  */
405);
406
407extern int imfs_dir_open(
408  rtems_libio_t *iop,             /* IN  */
409  const char    *pathname,        /* IN  */
410  uint32_t       flag,            /* IN  */
411  uint32_t       mode             /* IN  */
412);
413
414extern int imfs_dir_close(
415  rtems_libio_t *iop             /* IN  */
416);
417
418extern ssize_t imfs_dir_read(
419  rtems_libio_t *iop,              /* IN  */
420  void          *buffer,           /* IN  */
421  size_t         count             /* IN  */
422);
423
424extern rtems_off64_t imfs_dir_lseek(
425  rtems_libio_t        *iop,              /* IN  */
426  rtems_off64_t         offset,           /* IN  */
427  int                   whence            /* IN  */
428);
429
430extern int imfs_dir_fstat(
431  rtems_filesystem_location_info_t *loc,         /* IN  */
432  struct stat                      *buf          /* OUT */
433);
434
435extern int imfs_dir_rmnod(
436  rtems_filesystem_location_info_t *parent_pathloc, /* IN */
437  rtems_filesystem_location_info_t *pathloc         /* IN */
438);
439
440extern int memfile_open(
441  rtems_libio_t *iop,             /* IN  */
442  const char    *pathname,        /* IN  */
443  uint32_t       flag,            /* IN  */
444  uint32_t       mode             /* IN  */
445);
446
447extern int memfile_close(
448  rtems_libio_t *iop             /* IN  */
449);
450
451extern ssize_t memfile_read(
452  rtems_libio_t *iop,             /* IN  */
453  void          *buffer,          /* IN  */
454  size_t         count            /* IN  */
455);
456
457extern ssize_t memfile_write(
458  rtems_libio_t *iop,             /* IN  */
459  const void    *buffer,          /* IN  */
460  size_t         count            /* IN  */
461);
462
463extern int memfile_ioctl(
464  rtems_libio_t *iop,             /* IN  */
465  uint32_t       command,         /* IN  */
466  void          *buffer           /* IN  */
467);
468
469extern rtems_off64_t memfile_lseek(
470  rtems_libio_t        *iop,        /* IN  */
471  rtems_off64_t         offset,     /* IN  */
472  int                   whence      /* IN  */
473);
474
475extern int device_open(
476  rtems_libio_t *iop,            /* IN  */
477  const char    *pathname,       /* IN  */
478  uint32_t       flag,           /* IN  */
479  uint32_t       mode            /* IN  */
480);
481
482extern int device_close(
483  rtems_libio_t *iop             /* IN  */
484);
485
486extern ssize_t device_read(
487  rtems_libio_t *iop,            /* IN  */
488  void          *buffer,         /* IN  */
489  size_t         count           /* IN  */
490);
491
492extern ssize_t device_write(
493  rtems_libio_t *iop,               /* IN  */
494  const void    *buffer,            /* IN  */
495  size_t         count              /* IN  */
496);
497
498extern int device_ioctl(
499  rtems_libio_t *iop,               /* IN  */
500  uint32_t       command,           /* IN  */
501  void          *buffer             /* IN  */
502);
503
504extern rtems_off64_t device_lseek(
505  rtems_libio_t *iop,               /* IN  */
506  rtems_off64_t  offset,            /* IN  */
507  int            whence             /* IN  */
508);
509
510extern int device_ftruncate(
511  rtems_libio_t *iop,               /* IN  */
512  rtems_off64_t  length             /* IN  */
513);
514
515extern int IMFS_utime(
516  rtems_filesystem_location_info_t  *pathloc,       /* IN */
517  time_t                             actime,        /* IN */
518  time_t                             modtime        /* IN */
519);
520
521extern int IMFS_fchmod(
522  rtems_filesystem_location_info_t *loc,
523  mode_t                            mode
524);
525
526extern int IMFS_symlink(
527  rtems_filesystem_location_info_t  *parent_loc,  /* IN */
528  const char                        *link_name,
529  const char                        *node_name
530);
531
532extern ssize_t IMFS_readlink(
533 rtems_filesystem_location_info_t   *loc,         /* IN */
534 char                               *buf,         /* OUT */
535 size_t                             bufsize
536);
537
538extern int IMFS_rename(
539  rtems_filesystem_location_info_t  *old_loc,         /* IN */
540  rtems_filesystem_location_info_t  *old_parent_loc,  /* IN */
541  rtems_filesystem_location_info_t  *new_parent_loc,  /* IN */
542  const char                        *new_name         /* IN */
543);
544
545extern int IMFS_fdatasync(
546  rtems_libio_t *iop
547);
548
549extern void IMFS_create_orphan(
550  IMFS_jnode_t *jnode
551);
552
553extern void IMFS_check_node_remove(
554  IMFS_jnode_t *jnode
555);
556
557extern int IMFS_rmnod(
558  rtems_filesystem_location_info_t  *parent_pathloc, /* IN */
559  rtems_filesystem_location_info_t  *pathloc         /* IN */
560);
561
562/*
563 *  Turn on IMFS assertions when RTEMS_DEBUG is defined.
564 */
565#ifdef RTEMS_DEBUG
566  #include <assert.h>
567
568  #define IMFS_assert(_x) assert(_x)
569#else
570  #define IMFS_assert(_x)
571#endif
572
573#ifdef __cplusplus
574}
575#endif
576
577#endif
578/* end of include file */
Note: See TracBrowser for help on using the repository browser.