source: rtems/cpukit/libfs/src/imfs/imfs.h @ 624867b

4.104.114.84.95
Last change on this file since 624867b was 624867b, checked in by Eric Norum <WENorum@…>, on 02/08/05 at 17:12:54

Add copy-on-write semantics to rtems_tarfs_load().

  • Property mode set to 100644
File size: 14.3 KB
RevLine 
[07a3253d]1/*
2 *  Header file for the In-Memory File System
3 *
[08311cc3]4 *  COPYRIGHT (c) 1989-1999.
[07a3253d]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
[cf0539b1]9 *  http://www.rtems.com/license/LICENSE.
[07a3253d]10 *
11 *  $Id$
12 */
13
[a6f5d89]14#ifndef _RTEMS_IMFS_H
15#define _RTEMS_IMFS_H
[07a3253d]16
17#ifdef __cplusplus
18extern "C" {
19#endif
20
21#include <rtems.h>
[ebbe119e]22#include <rtems/chain.h>
[07a3253d]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.
[562e7ed1]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
[07a3253d]81 */
82
[562e7ed1]83#define IMFS_MEMFILE_BYTES_PER_BLOCK     128
[07a3253d]84#define IMFS_MEMFILE_BLOCK_SLOTS \
85  (IMFS_MEMFILE_BYTES_PER_BLOCK / sizeof(void *))
86
[1996aee7]87typedef char * block_p;
[07a3253d]88typedef block_p *block_ptr;
89
90typedef struct {
91  off_t      size;             /* size of file in bytes */
92  block_ptr  indirect;         /* array of 128 data blocks pointers */
93  block_ptr  doubly_indirect;  /* 128 indirect blocks */
94  block_ptr  triply_indirect;  /* 128 doubly indirect blocks */
95} IMFS_memfile_t;
96
[0ef748fb]97typedef struct {
98  off_t      size;             /* size of file in bytes */
99  block_p    direct;           /* pointer to file image */
100} IMFS_linearfile_t;
101
[07a3253d]102/*
103 *  Important block numbers for "memfiles"
104 */
105
106#define FIRST_INDIRECT           (0)
107#define LAST_INDIRECT            (IMFS_MEMFILE_BLOCK_SLOTS - 1)
108
109#define FIRST_DOUBLY_INDIRECT    (LAST_INDIRECT + 1)
110#define LAST_DOUBLY_INDIRECT     \
111   (LAST_INDIRECT + \
112     (IMFS_MEMFILE_BLOCK_SLOTS * IMFS_MEMFILE_BLOCK_SLOTS))
113
114#define FIRST_TRIPLY_INDIRECT    (LAST_DOUBLY_INDIRECT + 1)
115#define LAST_TRIPLY_INDIRECT \
116   (LAST_DOUBLY_INDIRECT +\
117     (IMFS_MEMFILE_BLOCK_SLOTS * \
118        IMFS_MEMFILE_BLOCK_SLOTS * IMFS_MEMFILE_BLOCK_SLOTS))
119
120#define IMFS_MEMFILE_MAXIMUM_SIZE \
121  (LAST_TRIPLY_INDIRECT * IMFS_MEMFILE_BYTES_PER_BLOCK)
122
123/*
124 *  What types of IMFS file systems entities there can be.
125 */
126
127#define IMFS_jnode_types_t rtems_filesystem_node_types_t
128#define IMFS_DIRECTORY     RTEMS_FILESYSTEM_DIRECTORY
129#define IMFS_DEVICE        RTEMS_FILESYSTEM_DEVICE
130#define IMFS_HARD_LINK     RTEMS_FILESYSTEM_HARD_LINK
131#define IMFS_SYM_LINK      RTEMS_FILESYSTEM_SYM_LINK
132#define IMFS_MEMORY_FILE   RTEMS_FILESYSTEM_MEMORY_FILE
[d1941587]133#define IMFS_LINEAR_FILE   (IMFS_MEMORY_FILE + 1)
[07a3253d]134
[0ef748fb]135#define IMFS_NUMBER_OF_TYPES  (IMFS_LINEAR_FILE + 1)
[07a3253d]136
137typedef union {
138  IMFS_directory_t   directory;
139  IMFS_device_t      device;
140  IMFS_link_t        hard_link;
[a5305f6b]141  IMFS_sym_link_t    sym_link;
142  IMFS_memfile_t     file;
143  IMFS_linearfile_t  linearfile;
[07a3253d]144} IMFS_types_union;
145
[3cf8394]146/*
147 *  Maximum length of a "basename" of an IMFS file/node.
148 */
149
150#define IMFS_NAME_MAX  32
151
[07a3253d]152/*
153 *  The control structure for an IMFS jnode.
154 */
155
156struct IMFS_jnode_tt {
[3cf8394]157  Chain_Node          Node;                  /* for chaining them together */
158  IMFS_jnode_t       *Parent;                /* Parent node */
[a5305f6b]159  char                name[IMFS_NAME_MAX+1]; /* "basename" */
[3cf8394]160  mode_t              st_mode;               /* File mode */
161  nlink_t             st_nlink;              /* Link count */
162  ino_t               st_ino;                /* inode */
163
164  uid_t               st_uid;                /* User ID of owner */
165  gid_t               st_gid;                /* Group ID of owner */
166
[df49c60]167  time_t              stat_atime;            /* Time of last access */
168  time_t              stat_mtime;            /* Time of last modification */
169  time_t              stat_ctime;            /* Time of last status change */
[3cf8394]170  IMFS_jnode_types_t  type;                  /* Type of this entry */
171  IMFS_types_union    info;
[07a3253d]172};
173
174#define IMFS_update_atime( _jnode )         \
175  do {                                      \
176    struct timeval tv;                      \
177    gettimeofday( &tv, 0 );                 \
[df49c60]178    _jnode->stat_atime  = (time_t) tv.tv_sec; \
[07a3253d]179  } while (0)
[a5305f6b]180
[07a3253d]181#define IMFS_update_mtime( _jnode )         \
182  do {                                      \
183    struct timeval tv;                      \
184    gettimeofday( &tv, 0 );                 \
[df49c60]185    _jnode->stat_mtime  = (time_t) tv.tv_sec; \
[07a3253d]186  } while (0)
[a5305f6b]187
[07a3253d]188#define IMFS_update_ctime( _jnode )         \
189  do {                                      \
190    struct timeval tv;                      \
191    gettimeofday( &tv, 0 );                 \
[df49c60]192    _jnode->stat_ctime  = (time_t) tv.tv_sec; \
[07a3253d]193  } while (0)
194
195#define IMFS_atime_mtime_update( _jnode )   \
196  do {                                      \
197    struct timeval tv;                      \
198    gettimeofday( &tv, 0 );                 \
[df49c60]199    _jnode->stat_mtime  = (time_t) tv.tv_sec; \
200    _jnode->stat_atime  = (time_t) tv.tv_sec; \
[07a3253d]201  } while (0)
202
203typedef struct {
[657e1bf6]204  ino_t                             ino_count;
205  rtems_filesystem_file_handlers_r *memfile_handlers;
206  rtems_filesystem_file_handlers_r *directory_handlers;
[07a3253d]207} IMFS_fs_info_t;
208
[b2709481]209#if UNUSED
210/* FIXME: Unused, we might want to remove it */
[07a3253d]211#define increment_and_check_linkcounts( _fs_info )                  \
212  ((IMFS_fs_info_t * )_fs_info)->link_counts++;                     \
213  if ( ((IMFS_fs_info_t * )_fs_info)->link_counts  > MAXSYMLINKS )  \
[b2709481]214    rtems_set_errno_and_return_minus_one( ELOOP )
215#endif
[07a3253d]216
217#define decrement_linkcounts(  _fs_info )             \
[a5305f6b]218  ((IMFS_fs_info_t * )_fs_info)->link_counts--;
[07a3253d]219
220/*
221 *  Type defination for tokens returned from IMFS_get_token
222 */
223
224typedef enum {
225  IMFS_NO_MORE_PATH,
226  IMFS_CURRENT_DIR,
227  IMFS_UP_DIR,
228  IMFS_NAME,
229  IMFS_INVALID_TOKEN
230} IMFS_token_types;
231
232/*
233 *  Shared Data
234 */
235
[94b357c2]236extern rtems_filesystem_file_handlers_r       IMFS_directory_handlers;
[51435fc7]237extern rtems_filesystem_file_handlers_r       IMFS_device_handlers;
[94b357c2]238extern rtems_filesystem_file_handlers_r       IMFS_link_handlers;
[51435fc7]239extern rtems_filesystem_file_handlers_r       IMFS_memfile_handlers;
[07a3253d]240extern rtems_filesystem_operations_table      IMFS_ops;
[657e1bf6]241extern rtems_filesystem_operations_table      miniIMFS_ops;
[a5305f6b]242extern rtems_filesystem_limits_and_options_t  IMFS_LIMITS_AND_OPTIONS;
[07a3253d]243
244/*
245 *  Routines
246 */
247
[a5305f6b]248int IMFS_initialize(
[07a3253d]249   rtems_filesystem_mount_table_entry_t *mt_entry
250);
251
[a5305f6b]252int miniIMFS_initialize(
[657e1bf6]253   rtems_filesystem_mount_table_entry_t *mt_entry
254);
255
[a5305f6b]256int IMFS_initialize_support(
[657e1bf6]257   rtems_filesystem_mount_table_entry_t *mt_entry,
258   rtems_filesystem_operations_table    *op_table,
259   rtems_filesystem_file_handlers_r     *memfile_handlers,
260   rtems_filesystem_file_handlers_r     *directory_handlers
261);
262
[07a3253d]263int IMFS_fsunmount(
264   rtems_filesystem_mount_table_entry_t *mt_entry
265);
266
[d1941587]267int rtems_tarfs_load(
[1996aee7]268   char         *mountpoint,
269   char         *tar_image,
270   size_t        tar_size
[0ef748fb]271);
[07a3253d]272
273/*
274 * Returns the number of characters copied from path to token.
275 */
276IMFS_token_types IMFS_get_token(
277  const char       *path,
278  char             *token,
279  int              *token_len
280);
281
282void IMFS_dump( void );
283
284void IMFS_initialize_jnode(
285  IMFS_jnode_t        *the_jnode,
286  IMFS_jnode_types_t   type,
287  IMFS_jnode_t        *the_parent,
288  char                *name,
289  mode_t               mode
290);
291
292IMFS_jnode_t *IMFS_find_match_in_dir(
293  IMFS_jnode_t *directory,                         /* IN */
294  char         *name                               /* IN */
295);
296
297rtems_filesystem_node_types_t IMFS_node_type(
298  rtems_filesystem_location_info_t    *pathloc     /* IN */
299);
300
301int IMFS_stat(
302  rtems_filesystem_location_info_t *loc,           /* IN  */
303  struct stat                      *buf            /* OUT */
304);
305
[a5305f6b]306int IMFS_Set_handlers(
307  rtems_filesystem_location_info_t   *loc
[7f6a0750]308);
309
[07a3253d]310int IMFS_evaluate_link(
311  rtems_filesystem_location_info_t *node,        /* IN/OUT */
312  int                               flags        /* IN     */
313);
314
[a5305f6b]315int IMFS_eval_path(
[07a3253d]316  const char                        *pathname,     /* IN     */
317  int                               flags,         /* IN     */
318  rtems_filesystem_location_info_t  *pathloc       /* IN/OUT */
319);
320
321
322int IMFS_link(
323  rtems_filesystem_location_info_t  *to_loc,      /* IN */
324  rtems_filesystem_location_info_t  *parent_loc,  /* IN */
325  const char                        *token        /* IN */
326);
327
328int IMFS_unlink(
329  rtems_filesystem_location_info_t  *pathloc       /* IN */
330);
331
332int IMFS_chown(
333  rtems_filesystem_location_info_t  *pathloc,      /* IN */
334  uid_t                              owner,        /* IN */
335  gid_t                              group         /* IN */
336);
337
338int IMFS_freenodinfo(
339  rtems_filesystem_location_info_t  *pathloc       /* IN */
340);
341
342int IMFS_mknod(
343  const char                        *path,         /* IN */
344  mode_t                             mode,         /* IN */
345  dev_t                              dev,          /* IN */
346  rtems_filesystem_location_info_t  *pathloc       /* IN/OUT */
347);
348
349IMFS_jnode_t *IMFS_create_node(
350  rtems_filesystem_location_info_t  *parent_loc,   /* IN  */
351  IMFS_jnode_types_t                 type,         /* IN  */
352  char                              *name,         /* IN  */
353  mode_t                             mode,         /* IN  */
354  IMFS_types_union                  *info          /* IN  */
355);
356
357int IMFS_evaluate_for_make(
358  const char                         *path,        /* IN     */
359  rtems_filesystem_location_info_t   *pathloc,     /* IN/OUT */
360  const char                        **name         /* OUT    */
361);
362
363int IMFS_mount(
364  rtems_filesystem_mount_table_entry_t *mt_entry  /* IN */
365);
366
367int IMFS_unmount(
368  rtems_filesystem_mount_table_entry_t *mt_entry  /* IN */
369);
370
371int IMFS_freenod(
372  rtems_filesystem_location_info_t  *node         /* IN/OUT */
373);
374
375int IMFS_memfile_remove(
376 IMFS_jnode_t  *the_jnode         /* IN/OUT */
377);
378
379int memfile_ftruncate(
380  rtems_libio_t *iop,               /* IN  */
381  off_t          length             /* IN  */
382);
[b568ccb]383
[07a3253d]384int imfs_dir_open(
385  rtems_libio_t *iop,             /* IN  */
386  const char    *pathname,        /* IN  */
[f91bbe64]387  uint32_t       flag,            /* IN  */
388  uint32_t       mode             /* IN  */
[07a3253d]389);
[b568ccb]390
[07a3253d]391int imfs_dir_close(
392  rtems_libio_t *iop             /* IN  */
393);
[b568ccb]394
[d32359a7]395ssize_t imfs_dir_read(
[07a3253d]396  rtems_libio_t *iop,              /* IN  */
397  void          *buffer,           /* IN  */
[f91bbe64]398  uint32_t       count             /* IN  */
[07a3253d]399);
[b568ccb]400
[07a3253d]401int imfs_dir_lseek(
402  rtems_libio_t        *iop,              /* IN  */
403  off_t                 offset,           /* IN  */
404  int                   whence            /* IN  */
405);
[b568ccb]406
[07a3253d]407int imfs_dir_fstat(
408  rtems_filesystem_location_info_t *loc,         /* IN  */
409  struct stat                      *buf          /* OUT */
410);
[b568ccb]411
412int imfs_dir_rmnod(
413  rtems_filesystem_location_info_t      *pathloc       /* IN */
414);
415
[07a3253d]416int memfile_open(
417  rtems_libio_t *iop,             /* IN  */
418  const char    *pathname,        /* IN  */
[f91bbe64]419  uint32_t       flag,            /* IN  */
420  uint32_t       mode             /* IN  */
[07a3253d]421);
[b568ccb]422
[07a3253d]423int memfile_close(
424  rtems_libio_t *iop             /* IN  */
425);
[b568ccb]426
[d32359a7]427ssize_t memfile_read(
[07a3253d]428  rtems_libio_t *iop,             /* IN  */
429  void          *buffer,          /* IN  */
[f91bbe64]430  uint32_t       count            /* IN  */
[07a3253d]431);
[b568ccb]432
[d32359a7]433ssize_t memfile_write(
[07a3253d]434  rtems_libio_t *iop,             /* IN  */
435  const void    *buffer,          /* IN  */
[f91bbe64]436  uint32_t       count            /* IN  */
[07a3253d]437);
[b568ccb]438
[07a3253d]439int memfile_ioctl(
440  rtems_libio_t *iop,             /* IN  */
[f91bbe64]441  uint32_t       command,         /* IN  */
[07a3253d]442  void          *buffer           /* IN  */
443);
[b568ccb]444
[07a3253d]445int memfile_lseek(
446  rtems_libio_t        *iop,        /* IN  */
447  off_t                 offset,     /* IN  */
448  int                   whence      /* IN  */
449);
[b568ccb]450
451int memfile_rmnod(
452  rtems_filesystem_location_info_t      *pathloc       /* IN */
453);
454
[07a3253d]455int device_open(
456  rtems_libio_t *iop,            /* IN  */
457  const char    *pathname,       /* IN  */
[f91bbe64]458  uint32_t       flag,           /* IN  */
459  uint32_t       mode            /* IN  */
[07a3253d]460);
[b568ccb]461
[07a3253d]462int device_close(
463  rtems_libio_t *iop             /* IN  */
464);
[b568ccb]465
[d32359a7]466ssize_t device_read(
[07a3253d]467  rtems_libio_t *iop,            /* IN  */
468  void          *buffer,         /* IN  */
[f91bbe64]469  uint32_t       count           /* IN  */
[07a3253d]470);
[b568ccb]471
[d32359a7]472ssize_t device_write(
[07a3253d]473  rtems_libio_t *iop,               /* IN  */
474  const void    *buffer,            /* IN  */
[f91bbe64]475  uint32_t       count              /* IN  */
[07a3253d]476);
[b568ccb]477
[07a3253d]478int device_ioctl(
479  rtems_libio_t *iop,               /* IN  */
[f91bbe64]480  uint32_t       command,           /* IN  */
[07a3253d]481  void          *buffer             /* IN  */
482);
[b568ccb]483
[07a3253d]484int device_lseek(
485  rtems_libio_t *iop,               /* IN  */
486  off_t          offset,            /* IN  */
487  int            whence             /* IN  */
488);
[b568ccb]489
[07a3253d]490int IMFS_utime(
491  rtems_filesystem_location_info_t  *pathloc,       /* IN */
492  time_t                             actime,        /* IN */
493  time_t                             modtime        /* IN */
494);
[b568ccb]495
[07a3253d]496int IMFS_fchmod(
497  rtems_filesystem_location_info_t *loc,
498  mode_t                            mode
499);
500
501int IMFS_symlink(
502  rtems_filesystem_location_info_t  *parent_loc,  /* IN */
503  const char                        *link_name,
504  const char                        *node_name
505);
506
507int IMFS_readlink(
508 rtems_filesystem_location_info_t   *loc,         /* IN */
509 char                               *buf,         /* OUT */
[a5305f6b]510 size_t                             bufsize
[07a3253d]511);
512
[49629bd8]513int IMFS_fdatasync(
514  rtems_libio_t *iop
515);
516
[578a415]517int IMFS_fcntl(
518  int            cmd,
519  rtems_libio_t *iop
520);
521
[94b357c2]522int IMFS_rmnod(
523  rtems_filesystem_location_info_t      *pathloc       /* IN */
524);
525
[07a3253d]526#ifdef __cplusplus
527}
528#endif
529
530#endif
531/* end of include file */
Note: See TracBrowser for help on using the repository browser.