source: rtems/cpukit/libfs/src/imfs/imfs.h @ 9807f04

4.104.114.84.95
Last change on this file since 9807f04 was c9b005a9, checked in by Thomas Doerfler <Thomas.Doerfler@…>, on 07/09/06 at 10:05:27

applied patches for PR1117/1118/1119/1120

  • Property mode set to 100644
File size: 14.6 KB
Line 
1/*
2 *  Header file for the In-Memory File System
3 *
4 *  COPYRIGHT (c) 1989-1999.
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#ifdef __cplusplus
18extern "C" {
19#endif
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/*
29 *  File name macros
30 */
31
32#define IMFS_is_valid_name_char( _ch ) ( 1 )
33
34#define IMFS_is_separator( _ch ) \
35   rtems_filesystem_is_separator( _ch )
36
37/*
38 *  Data types
39 */
40
41struct IMFS_jnode_tt;
42typedef struct IMFS_jnode_tt IMFS_jnode_t;
43
44typedef struct {
45  Chain_Control                          Entries;
46  rtems_filesystem_mount_table_entry_t  *mt_fs;
47}  IMFS_directory_t;
48
49typedef struct {
50  rtems_device_major_number  major;
51  rtems_device_minor_number  minor;
52}  IMFS_device_t;
53
54typedef struct {
55  IMFS_jnode_t  *link_node;
56} IMFS_link_t;
57
58typedef struct {
59  const char *name;
60} IMFS_sym_link_t;
61
62/*
63 *  IMFS "memfile" information
64 *
65 *  The data structure for the in-memory "memfiles" is based on classic UNIX.
66 *
67 *  block_ptr is a pointer to a block of IMFS_MEMFILE_BYTES_PER_BLOCK in
68 *  length which could be data or a table of pointers to blocks.
69 *
70 *  Setting IMFS_MEMFILE_BYTES_PER_BLOCK to different values has a significant
71 *  impact on the maximum file size supported as well as the amount of
72 *  memory wasted due to internal file fragmentation.  The following
73 *  is a list of maximum file sizes based on various settings
74 *
75 *    max_filesize with blocks of   16 is         1,328
76 *    max_filesize with blocks of   32 is        18,656
77 *    max_filesize with blocks of   64 is       279,488
78 *    max_filesize with blocks of  128 is     4,329,344
79 *    max_filesize with blocks of  256 is    68,173,568
80 *    max_filesize with blocks of  512 is 1,082,195,456
81 */
82
83#define IMFS_MEMFILE_DEFAULT_BYTES_PER_BLOCK     128
84  extern int imfs_rq_memfile_bytes_per_block;
85  /*
86   * FIXME: make and use derivates from this,
87   * a shift count and a mask
88   */
89  extern int imfs_memfile_bytes_per_block;
90
91#define IMFS_MEMFILE_BYTES_PER_BLOCK imfs_memfile_bytes_per_block 
92#define IMFS_MEMFILE_BLOCK_SLOTS \
93  (IMFS_MEMFILE_BYTES_PER_BLOCK / sizeof(void *))
94
95typedef uint8_t *block_p;
96typedef block_p *block_ptr;
97
98typedef struct {
99  off_t      size;             /* size of file in bytes */
100  block_ptr  indirect;         /* array of 128 data blocks pointers */
101  block_ptr  doubly_indirect;  /* 128 indirect blocks */
102  block_ptr  triply_indirect;  /* 128 doubly indirect blocks */
103} IMFS_memfile_t;
104
105typedef struct {
106  off_t      size;             /* size of file in bytes */
107  block_p    direct;           /* pointer to file image */
108} IMFS_linearfile_t;
109
110/*
111 *  Important block numbers for "memfiles"
112 */
113
114#define FIRST_INDIRECT           (0)
115#define LAST_INDIRECT            (IMFS_MEMFILE_BLOCK_SLOTS - 1)
116
117#define FIRST_DOUBLY_INDIRECT    (LAST_INDIRECT + 1)
118#define LAST_DOUBLY_INDIRECT     \
119   (LAST_INDIRECT + \
120     (IMFS_MEMFILE_BLOCK_SLOTS * IMFS_MEMFILE_BLOCK_SLOTS))
121
122#define FIRST_TRIPLY_INDIRECT    (LAST_DOUBLY_INDIRECT + 1)
123#define LAST_TRIPLY_INDIRECT \
124   (LAST_DOUBLY_INDIRECT +\
125     (IMFS_MEMFILE_BLOCK_SLOTS * \
126        IMFS_MEMFILE_BLOCK_SLOTS * IMFS_MEMFILE_BLOCK_SLOTS))
127
128#define IMFS_MEMFILE_MAXIMUM_SIZE \
129  (LAST_TRIPLY_INDIRECT * IMFS_MEMFILE_BYTES_PER_BLOCK)
130
131/*
132 *  What types of IMFS file systems entities there can be.
133 */
134
135#define IMFS_jnode_types_t rtems_filesystem_node_types_t
136#define IMFS_DIRECTORY     RTEMS_FILESYSTEM_DIRECTORY
137#define IMFS_DEVICE        RTEMS_FILESYSTEM_DEVICE
138#define IMFS_HARD_LINK     RTEMS_FILESYSTEM_HARD_LINK
139#define IMFS_SYM_LINK      RTEMS_FILESYSTEM_SYM_LINK
140#define IMFS_MEMORY_FILE   RTEMS_FILESYSTEM_MEMORY_FILE
141#define IMFS_LINEAR_FILE   (IMFS_MEMORY_FILE + 1)
142
143#define IMFS_NUMBER_OF_TYPES  (IMFS_LINEAR_FILE + 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_types_union;
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  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_atime_mtime_update( _jnode )   \
204  do {                                      \
205    struct timeval tv;                      \
206    gettimeofday( &tv, 0 );                 \
207    _jnode->stat_mtime  = (time_t) tv.tv_sec; \
208    _jnode->stat_atime  = (time_t) tv.tv_sec; \
209  } while (0)
210
211typedef struct {
212  ino_t                             ino_count;
213  rtems_filesystem_file_handlers_r *memfile_handlers;
214  rtems_filesystem_file_handlers_r *directory_handlers;
215} IMFS_fs_info_t;
216
217#if UNUSED
218/* FIXME: Unused, we might want to remove it */
219#define increment_and_check_linkcounts( _fs_info )                  \
220  ((IMFS_fs_info_t * )_fs_info)->link_counts++;                     \
221  if ( ((IMFS_fs_info_t * )_fs_info)->link_counts  > MAXSYMLINKS )  \
222    rtems_set_errno_and_return_minus_one( ELOOP )
223#endif
224
225#define decrement_linkcounts(  _fs_info )             \
226  ((IMFS_fs_info_t * )_fs_info)->link_counts--;
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 rtems_filesystem_file_handlers_r       IMFS_directory_handlers;
245extern rtems_filesystem_file_handlers_r       IMFS_device_handlers;
246extern rtems_filesystem_file_handlers_r       IMFS_link_handlers;
247extern rtems_filesystem_file_handlers_r       IMFS_memfile_handlers;
248extern rtems_filesystem_operations_table      IMFS_ops;
249extern rtems_filesystem_operations_table      miniIMFS_ops;
250extern rtems_filesystem_limits_and_options_t  IMFS_LIMITS_AND_OPTIONS;
251
252/*
253 *  Routines
254 */
255
256int IMFS_initialize(
257   rtems_filesystem_mount_table_entry_t *mt_entry
258);
259
260int miniIMFS_initialize(
261   rtems_filesystem_mount_table_entry_t *mt_entry
262);
263
264int IMFS_initialize_support(
265   rtems_filesystem_mount_table_entry_t *mt_entry,
266   rtems_filesystem_operations_table    *op_table,
267   rtems_filesystem_file_handlers_r     *memfile_handlers,
268   rtems_filesystem_file_handlers_r     *directory_handlers
269);
270
271int IMFS_fsunmount(
272   rtems_filesystem_mount_table_entry_t *mt_entry
273);
274
275int rtems_tarfs_load(
276   char         *mountpoint,
277   uint8_t      *tar_image,
278   size_t        tar_size
279);
280
281/*
282 * Returns the number of characters copied from path to token.
283 */
284IMFS_token_types IMFS_get_token(
285  const char       *path,
286  char             *token,
287  int              *token_len
288);
289
290void IMFS_dump( void );
291
292void IMFS_initialize_jnode(
293  IMFS_jnode_t        *the_jnode,
294  IMFS_jnode_types_t   type,
295  IMFS_jnode_t        *the_parent,
296  char                *name,
297  mode_t               mode
298);
299
300IMFS_jnode_t *IMFS_find_match_in_dir(
301  IMFS_jnode_t *directory,                         /* IN */
302  char         *name                               /* IN */
303);
304
305rtems_filesystem_node_types_t IMFS_node_type(
306  rtems_filesystem_location_info_t    *pathloc     /* IN */
307);
308
309int IMFS_stat(
310  rtems_filesystem_location_info_t *loc,           /* IN  */
311  struct stat                      *buf            /* OUT */
312);
313
314int IMFS_Set_handlers(
315  rtems_filesystem_location_info_t   *loc
316);
317
318int IMFS_evaluate_link(
319  rtems_filesystem_location_info_t *node,        /* IN/OUT */
320  int                               flags        /* IN     */
321);
322
323int IMFS_eval_path(
324  const char                        *pathname,     /* IN     */
325  int                               flags,         /* IN     */
326  rtems_filesystem_location_info_t  *pathloc       /* IN/OUT */
327);
328
329
330int IMFS_link(
331  rtems_filesystem_location_info_t  *to_loc,      /* IN */
332  rtems_filesystem_location_info_t  *parent_loc,  /* IN */
333  const char                        *token        /* IN */
334);
335
336int IMFS_unlink(
337  rtems_filesystem_location_info_t  *pathloc       /* IN */
338);
339
340int IMFS_chown(
341  rtems_filesystem_location_info_t  *pathloc,      /* IN */
342  uid_t                              owner,        /* IN */
343  gid_t                              group         /* IN */
344);
345
346int IMFS_freenodinfo(
347  rtems_filesystem_location_info_t  *pathloc       /* IN */
348);
349
350int IMFS_mknod(
351  const char                        *path,         /* IN */
352  mode_t                             mode,         /* IN */
353  dev_t                              dev,          /* IN */
354  rtems_filesystem_location_info_t  *pathloc       /* IN/OUT */
355);
356
357IMFS_jnode_t *IMFS_create_node(
358  rtems_filesystem_location_info_t  *parent_loc,   /* IN  */
359  IMFS_jnode_types_t                 type,         /* IN  */
360  char                              *name,         /* IN  */
361  mode_t                             mode,         /* IN  */
362  IMFS_types_union                  *info          /* IN  */
363);
364
365int IMFS_evaluate_for_make(
366  const char                         *path,        /* IN     */
367  rtems_filesystem_location_info_t   *pathloc,     /* IN/OUT */
368  const char                        **name         /* OUT    */
369);
370
371int IMFS_mount(
372  rtems_filesystem_mount_table_entry_t *mt_entry  /* IN */
373);
374
375int IMFS_unmount(
376  rtems_filesystem_mount_table_entry_t *mt_entry  /* IN */
377);
378
379int IMFS_freenod(
380  rtems_filesystem_location_info_t  *node         /* IN/OUT */
381);
382
383int IMFS_memfile_remove(
384 IMFS_jnode_t  *the_jnode         /* IN/OUT */
385);
386
387int memfile_ftruncate(
388  rtems_libio_t *iop,               /* IN  */
389  off_t          length             /* IN  */
390);
391
392int imfs_dir_open(
393  rtems_libio_t *iop,             /* IN  */
394  const char    *pathname,        /* IN  */
395  uint32_t       flag,            /* IN  */
396  uint32_t       mode             /* IN  */
397);
398
399int imfs_dir_close(
400  rtems_libio_t *iop             /* IN  */
401);
402
403ssize_t imfs_dir_read(
404  rtems_libio_t *iop,              /* IN  */
405  void          *buffer,           /* IN  */
406  uint32_t       count             /* IN  */
407);
408
409int imfs_dir_lseek(
410  rtems_libio_t        *iop,              /* IN  */
411  off_t                 offset,           /* IN  */
412  int                   whence            /* IN  */
413);
414
415int imfs_dir_fstat(
416  rtems_filesystem_location_info_t *loc,         /* IN  */
417  struct stat                      *buf          /* OUT */
418);
419
420int imfs_dir_rmnod(
421  rtems_filesystem_location_info_t      *pathloc       /* IN */
422);
423
424int memfile_open(
425  rtems_libio_t *iop,             /* IN  */
426  const char    *pathname,        /* IN  */
427  uint32_t       flag,            /* IN  */
428  uint32_t       mode             /* IN  */
429);
430
431int memfile_close(
432  rtems_libio_t *iop             /* IN  */
433);
434
435ssize_t memfile_read(
436  rtems_libio_t *iop,             /* IN  */
437  void          *buffer,          /* IN  */
438  uint32_t       count            /* IN  */
439);
440
441ssize_t memfile_write(
442  rtems_libio_t *iop,             /* IN  */
443  const void    *buffer,          /* IN  */
444  uint32_t       count            /* IN  */
445);
446
447int memfile_ioctl(
448  rtems_libio_t *iop,             /* IN  */
449  uint32_t       command,         /* IN  */
450  void          *buffer           /* IN  */
451);
452
453int memfile_lseek(
454  rtems_libio_t        *iop,        /* IN  */
455  off_t                 offset,     /* IN  */
456  int                   whence      /* IN  */
457);
458
459int memfile_rmnod(
460  rtems_filesystem_location_info_t      *pathloc       /* IN */
461);
462
463int device_open(
464  rtems_libio_t *iop,            /* IN  */
465  const char    *pathname,       /* IN  */
466  uint32_t       flag,           /* IN  */
467  uint32_t       mode            /* IN  */
468);
469
470int device_close(
471  rtems_libio_t *iop             /* IN  */
472);
473
474ssize_t device_read(
475  rtems_libio_t *iop,            /* IN  */
476  void          *buffer,         /* IN  */
477  uint32_t       count           /* IN  */
478);
479
480ssize_t device_write(
481  rtems_libio_t *iop,               /* IN  */
482  const void    *buffer,            /* IN  */
483  uint32_t       count              /* IN  */
484);
485
486int device_ioctl(
487  rtems_libio_t *iop,               /* IN  */
488  uint32_t       command,           /* IN  */
489  void          *buffer             /* IN  */
490);
491
492int device_lseek(
493  rtems_libio_t *iop,               /* IN  */
494  off_t          offset,            /* IN  */
495  int            whence             /* IN  */
496);
497
498int IMFS_utime(
499  rtems_filesystem_location_info_t  *pathloc,       /* IN */
500  time_t                             actime,        /* IN */
501  time_t                             modtime        /* IN */
502);
503
504int IMFS_fchmod(
505  rtems_filesystem_location_info_t *loc,
506  mode_t                            mode
507);
508
509int IMFS_symlink(
510  rtems_filesystem_location_info_t  *parent_loc,  /* IN */
511  const char                        *link_name,
512  const char                        *node_name
513);
514
515int IMFS_readlink(
516 rtems_filesystem_location_info_t   *loc,         /* IN */
517 char                               *buf,         /* OUT */
518 size_t                             bufsize
519);
520
521int IMFS_fdatasync(
522  rtems_libio_t *iop
523);
524
525int IMFS_fcntl(
526  int            cmd,
527  rtems_libio_t *iop
528);
529
530int IMFS_rmnod(
531  rtems_filesystem_location_info_t      *pathloc       /* IN */
532);
533
534#ifdef __cplusplus
535}
536#endif
537
538#endif
539/* end of include file */
Note: See TracBrowser for help on using the repository browser.