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

4.115
Last change on this file since 9788279 was 9788279, checked in by Sebastian Huber <sebastian.huber@…>, on 08/25/10 at 09:37:49

2010-08-25 Sebastian Huber <sebastian.huber@…>

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