source: rtems/c/src/exec/libfs/src/imfs/imfs.h @ 32f415d

4.104.114.84.95
Last change on this file since 32f415d was 0ef748fb, checked in by Joel Sherrill <joel.sherrill@…>, on 12/13/00 at 17:53:55

2000-12-12 Jake Janovetz <janovetz@…>

  • src/imfs/linearfile.c, src/imfs/imfs_load_tar.c: New files.
  • src/imfs/Makefile.am, src/imfs/imfs.h, src/imfs/imfs_creat.c, src/imfs/imfs_debug.c, src/imfs/imfs_eval.c, src/imfs/imfs_handlers_memfile.c, src/imfs/imfs_init.c, src/imfs/imfs_initsupp.c, src/imfs/imfs_stat.c, src/imfs/miniimfs_init.c: Added "tarfs". This is not really a tar filesystem. It is a way to load a tar image into the IMFS but actually leave bulky file contents in the original tar image. It essentially adds the linear file type and associated support and a loader routine.
  • Property mode set to 100644
File size: 14.8 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.OARcorp.com/rtems/license.html.
10 *
11 *  $Id$
12 */
13
14#ifndef __IMFS_h
15#define __IMFS_h
16
17#ifdef __cplusplus
18extern "C" {
19#endif
20
21#include <rtems.h>
22#include <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_BYTES_PER_BLOCK     128
84#define IMFS_MEMFILE_BLOCK_SLOTS \
85  (IMFS_MEMFILE_BYTES_PER_BLOCK / sizeof(void *))
86
87typedef unsigned char * block_p;
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
97typedef struct {
98  off_t      size;             /* size of file in bytes */
99  block_p    direct;           /* pointer to file image */
100} IMFS_linearfile_t;
101
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
133#define IMFS_LINEAR_FILE   (RTEMS_FILESYSTEM_MEMORY_FILE + 1)
134
135#define IMFS_NUMBER_OF_TYPES  (IMFS_LINEAR_FILE + 1)
136
137typedef union {
138  IMFS_directory_t   directory;
139  IMFS_device_t      device;
140  IMFS_link_t        hard_link;
141  IMFS_sym_link_t    sym_link;   
142  IMFS_memfile_t     file;   
143  IMFS_linearfile_t  linearfile;   
144} IMFS_types_union;
145
146/*
147 *  Maximum length of a "basename" of an IMFS file/node.
148 */
149
150#define IMFS_NAME_MAX  32
151
152/*
153 *  The control structure for an IMFS jnode.
154 */
155
156struct IMFS_jnode_tt {
157  Chain_Node          Node;                  /* for chaining them together */
158  IMFS_jnode_t       *Parent;                /* Parent node */
159  char                name[IMFS_NAME_MAX+1]; /* "basename" */
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
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 */
170  IMFS_jnode_types_t  type;                  /* Type of this entry */
171  IMFS_types_union    info;
172};
173
174#define IMFS_update_atime( _jnode )         \
175  do {                                      \
176    struct timeval tv;                      \
177    gettimeofday( &tv, 0 );                 \
178    _jnode->stat_atime  = (time_t) tv.tv_sec; \
179  } while (0)
180               
181#define IMFS_update_mtime( _jnode )         \
182  do {                                      \
183    struct timeval tv;                      \
184    gettimeofday( &tv, 0 );                 \
185    _jnode->stat_mtime  = (time_t) tv.tv_sec; \
186  } while (0)
187               
188#define IMFS_update_ctime( _jnode )         \
189  do {                                      \
190    struct timeval tv;                      \
191    gettimeofday( &tv, 0 );                 \
192    _jnode->stat_ctime  = (time_t) tv.tv_sec; \
193  } while (0)
194
195#define IMFS_atime_mtime_update( _jnode )   \
196  do {                                      \
197    struct timeval tv;                      \
198    gettimeofday( &tv, 0 );                 \
199    _jnode->stat_mtime  = (time_t) tv.tv_sec; \
200    _jnode->stat_atime  = (time_t) tv.tv_sec; \
201  } while (0)
202
203typedef struct {
204  ino_t                             ino_count;
205  rtems_filesystem_file_handlers_r *linearfile_handlers;
206  rtems_filesystem_file_handlers_r *memfile_handlers;
207  rtems_filesystem_file_handlers_r *directory_handlers;
208} IMFS_fs_info_t;
209
210#define increment_and_check_linkcounts( _fs_info )                  \
211  ((IMFS_fs_info_t * )_fs_info)->link_counts++;                     \
212  if ( ((IMFS_fs_info_t * )_fs_info)->link_counts  > MAXSYMLINKS )  \
213    set_errno_and_return_minus_one( ELOOP )
214
215#define decrement_linkcounts(  _fs_info )             \
216  ((IMFS_fs_info_t * )_fs_info)->link_counts--;       
217
218/*
219 *  Type defination for tokens returned from IMFS_get_token
220 */
221
222typedef enum {
223  IMFS_NO_MORE_PATH,
224  IMFS_CURRENT_DIR,
225  IMFS_UP_DIR,
226  IMFS_NAME,
227  IMFS_INVALID_TOKEN
228} IMFS_token_types;
229
230/*
231 *  Shared Data
232 */
233
234extern rtems_filesystem_file_handlers_r       IMFS_directory_handlers;
235extern rtems_filesystem_file_handlers_r       IMFS_device_handlers;
236extern rtems_filesystem_file_handlers_r       IMFS_link_handlers;
237extern rtems_filesystem_file_handlers_r       IMFS_linearfile_handlers;
238extern rtems_filesystem_file_handlers_r       IMFS_memfile_handlers;
239extern rtems_filesystem_operations_table      IMFS_ops;
240extern rtems_filesystem_operations_table      miniIMFS_ops;
241extern rtems_filesystem_limits_and_options_t  IMFS_LIMITS_AND_OPTIONS;
242
243/*
244 *  Routines
245 */
246
247int IMFS_initialize(
248   rtems_filesystem_mount_table_entry_t *mt_entry
249);
250
251int miniIMFS_initialize(
252   rtems_filesystem_mount_table_entry_t *mt_entry
253);
254
255int IMFS_initialize_support(
256   rtems_filesystem_mount_table_entry_t *mt_entry,
257   rtems_filesystem_operations_table    *op_table,
258   rtems_filesystem_file_handlers_r     *linearfile_handlers,
259   rtems_filesystem_file_handlers_r     *memfile_handlers,
260   rtems_filesystem_file_handlers_r     *directory_handlers
261);
262
263int IMFS_fsunmount(
264   rtems_filesystem_mount_table_entry_t *mt_entry
265);
266
267int rtems_tarfs_mount(
268   char          *mountpoint,
269   unsigned char *addr,
270   unsigned long length
271);
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
306int IMFS_Set_handlers( 
307  rtems_filesystem_location_info_t   *loc
308);
309
310int IMFS_evaluate_link(
311  rtems_filesystem_location_info_t *node,        /* IN/OUT */
312  int                               flags        /* IN     */
313);
314
315int IMFS_eval_path( 
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);
383
384int imfs_dir_open(
385  rtems_libio_t *iop,             /* IN  */
386  const char    *pathname,        /* IN  */
387  unsigned32     flag,            /* IN  */
388  unsigned32     mode             /* IN  */
389);
390
391int imfs_dir_close(
392  rtems_libio_t *iop             /* IN  */
393);
394
395int imfs_dir_read(
396  rtems_libio_t *iop,              /* IN  */
397  void          *buffer,           /* IN  */
398  unsigned32     count             /* IN  */
399);
400
401int imfs_dir_lseek(
402  rtems_libio_t        *iop,              /* IN  */
403  off_t                 offset,           /* IN  */
404  int                   whence            /* IN  */
405);
406
407int imfs_dir_fstat(
408  rtems_filesystem_location_info_t *loc,         /* IN  */
409  struct stat                      *buf          /* OUT */
410);
411
412int imfs_dir_rmnod(
413  rtems_filesystem_location_info_t      *pathloc       /* IN */
414);
415
416int linearfile_read(
417  rtems_libio_t *iop,             /* IN  */
418  void          *buffer,          /* IN  */
419  unsigned32     count            /* IN  */
420);
421
422int linearfile_lseek(
423  rtems_libio_t        *iop,        /* IN  */
424  off_t                 offset,     /* IN  */
425  int                   whence      /* IN  */
426);
427
428int memfile_open(
429  rtems_libio_t *iop,             /* IN  */
430  const char    *pathname,        /* IN  */
431  unsigned32     flag,            /* IN  */
432  unsigned32     mode             /* IN  */
433);
434
435int memfile_close(
436  rtems_libio_t *iop             /* IN  */
437);
438
439int memfile_read(
440  rtems_libio_t *iop,             /* IN  */
441  void          *buffer,          /* IN  */
442  unsigned32     count            /* IN  */
443);
444
445int memfile_write(
446  rtems_libio_t *iop,             /* IN  */
447  const void    *buffer,          /* IN  */
448  unsigned32     count            /* IN  */
449);
450
451int memfile_ioctl(
452  rtems_libio_t *iop,             /* IN  */
453  unsigned32     command,         /* IN  */
454  void          *buffer           /* IN  */
455);
456
457int memfile_lseek(
458  rtems_libio_t        *iop,        /* IN  */
459  off_t                 offset,     /* IN  */
460  int                   whence      /* IN  */
461);
462
463int memfile_rmnod(
464  rtems_filesystem_location_info_t      *pathloc       /* IN */
465);
466
467int device_open(
468  rtems_libio_t *iop,            /* IN  */
469  const char    *pathname,       /* IN  */
470  unsigned32     flag,           /* IN  */
471  unsigned32     mode            /* IN  */
472);
473
474int device_close(
475  rtems_libio_t *iop             /* IN  */
476);
477
478int device_read(
479  rtems_libio_t *iop,            /* IN  */
480  void          *buffer,         /* IN  */
481  unsigned32     count           /* IN  */
482);
483
484int device_write(
485  rtems_libio_t *iop,               /* IN  */
486  const void    *buffer,            /* IN  */
487  unsigned32     count              /* IN  */
488);
489
490int device_ioctl(
491  rtems_libio_t *iop,               /* IN  */
492  unsigned32     command,           /* IN  */
493  void          *buffer             /* IN  */
494);
495
496int device_lseek(
497  rtems_libio_t *iop,               /* IN  */
498  off_t          offset,            /* IN  */
499  int            whence             /* IN  */
500);
501
502int IMFS_utime(
503  rtems_filesystem_location_info_t  *pathloc,       /* IN */
504  time_t                             actime,        /* IN */
505  time_t                             modtime        /* IN */
506);
507
508int IMFS_fchmod(
509  rtems_filesystem_location_info_t *loc,
510  mode_t                            mode
511);
512
513int IMFS_symlink(
514  rtems_filesystem_location_info_t  *parent_loc,  /* IN */
515  const char                        *link_name,
516  const char                        *node_name
517);
518
519int IMFS_readlink(
520 rtems_filesystem_location_info_t   *loc,         /* IN */
521 char                               *buf,         /* OUT */
522 size_t                             bufsize   
523);
524
525int IMFS_fdatasync(
526  rtems_libio_t *iop
527);
528
529int IMFS_fcntl(
530  int            cmd,
531  rtems_libio_t *iop
532);
533
534int IMFS_rmnod(
535  rtems_filesystem_location_info_t      *pathloc       /* IN */
536);
537
538#ifdef __cplusplus
539}
540#endif
541
542#endif
543/* end of include file */
Note: See TracBrowser for help on using the repository browser.