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

4.104.114.84.95
Last change on this file since a6f5d89 was a6f5d89, checked in by Ralf Corsepius <ralf.corsepius@…>, on 01/28/05 at 08:44:51

New header guard.

  • 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.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_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   (IMFS_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#if UNUSED
211/* FIXME: Unused, we might want to remove it */
212#define increment_and_check_linkcounts( _fs_info )                  \
213  ((IMFS_fs_info_t * )_fs_info)->link_counts++;                     \
214  if ( ((IMFS_fs_info_t * )_fs_info)->link_counts  > MAXSYMLINKS )  \
215    rtems_set_errno_and_return_minus_one( ELOOP )
216#endif
217
218#define decrement_linkcounts(  _fs_info )             \
219  ((IMFS_fs_info_t * )_fs_info)->link_counts--;
220
221/*
222 *  Type defination for tokens returned from IMFS_get_token
223 */
224
225typedef enum {
226  IMFS_NO_MORE_PATH,
227  IMFS_CURRENT_DIR,
228  IMFS_UP_DIR,
229  IMFS_NAME,
230  IMFS_INVALID_TOKEN
231} IMFS_token_types;
232
233/*
234 *  Shared Data
235 */
236
237extern rtems_filesystem_file_handlers_r       IMFS_directory_handlers;
238extern rtems_filesystem_file_handlers_r       IMFS_device_handlers;
239extern rtems_filesystem_file_handlers_r       IMFS_link_handlers;
240extern rtems_filesystem_file_handlers_r       IMFS_linearfile_handlers;
241extern rtems_filesystem_file_handlers_r       IMFS_memfile_handlers;
242extern rtems_filesystem_operations_table      IMFS_ops;
243extern rtems_filesystem_operations_table      miniIMFS_ops;
244extern rtems_filesystem_limits_and_options_t  IMFS_LIMITS_AND_OPTIONS;
245
246/*
247 *  Routines
248 */
249
250int IMFS_initialize(
251   rtems_filesystem_mount_table_entry_t *mt_entry
252);
253
254int miniIMFS_initialize(
255   rtems_filesystem_mount_table_entry_t *mt_entry
256);
257
258int IMFS_initialize_support(
259   rtems_filesystem_mount_table_entry_t *mt_entry,
260   rtems_filesystem_operations_table    *op_table,
261   rtems_filesystem_file_handlers_r     *linearfile_handlers,
262   rtems_filesystem_file_handlers_r     *memfile_handlers,
263   rtems_filesystem_file_handlers_r     *directory_handlers
264);
265
266int IMFS_fsunmount(
267   rtems_filesystem_mount_table_entry_t *mt_entry
268);
269
270int rtems_tarfs_load(
271   char          *mountpoint,
272   unsigned char *addr,
273   unsigned long length
274);
275
276/*
277 * Returns the number of characters copied from path to token.
278 */
279IMFS_token_types IMFS_get_token(
280  const char       *path,
281  char             *token,
282  int              *token_len
283);
284
285void IMFS_dump( void );
286
287void IMFS_initialize_jnode(
288  IMFS_jnode_t        *the_jnode,
289  IMFS_jnode_types_t   type,
290  IMFS_jnode_t        *the_parent,
291  char                *name,
292  mode_t               mode
293);
294
295IMFS_jnode_t *IMFS_find_match_in_dir(
296  IMFS_jnode_t *directory,                         /* IN */
297  char         *name                               /* IN */
298);
299
300rtems_filesystem_node_types_t IMFS_node_type(
301  rtems_filesystem_location_info_t    *pathloc     /* IN */
302);
303
304int IMFS_stat(
305  rtems_filesystem_location_info_t *loc,           /* IN  */
306  struct stat                      *buf            /* OUT */
307);
308
309int IMFS_Set_handlers(
310  rtems_filesystem_location_info_t   *loc
311);
312
313int IMFS_evaluate_link(
314  rtems_filesystem_location_info_t *node,        /* IN/OUT */
315  int                               flags        /* IN     */
316);
317
318int IMFS_eval_path(
319  const char                        *pathname,     /* IN     */
320  int                               flags,         /* IN     */
321  rtems_filesystem_location_info_t  *pathloc       /* IN/OUT */
322);
323
324
325int IMFS_link(
326  rtems_filesystem_location_info_t  *to_loc,      /* IN */
327  rtems_filesystem_location_info_t  *parent_loc,  /* IN */
328  const char                        *token        /* IN */
329);
330
331int IMFS_unlink(
332  rtems_filesystem_location_info_t  *pathloc       /* IN */
333);
334
335int IMFS_chown(
336  rtems_filesystem_location_info_t  *pathloc,      /* IN */
337  uid_t                              owner,        /* IN */
338  gid_t                              group         /* IN */
339);
340
341int IMFS_freenodinfo(
342  rtems_filesystem_location_info_t  *pathloc       /* IN */
343);
344
345int IMFS_mknod(
346  const char                        *path,         /* IN */
347  mode_t                             mode,         /* IN */
348  dev_t                              dev,          /* IN */
349  rtems_filesystem_location_info_t  *pathloc       /* IN/OUT */
350);
351
352IMFS_jnode_t *IMFS_create_node(
353  rtems_filesystem_location_info_t  *parent_loc,   /* IN  */
354  IMFS_jnode_types_t                 type,         /* IN  */
355  char                              *name,         /* IN  */
356  mode_t                             mode,         /* IN  */
357  IMFS_types_union                  *info          /* IN  */
358);
359
360int IMFS_evaluate_for_make(
361  const char                         *path,        /* IN     */
362  rtems_filesystem_location_info_t   *pathloc,     /* IN/OUT */
363  const char                        **name         /* OUT    */
364);
365
366int IMFS_mount(
367  rtems_filesystem_mount_table_entry_t *mt_entry  /* IN */
368);
369
370int IMFS_unmount(
371  rtems_filesystem_mount_table_entry_t *mt_entry  /* IN */
372);
373
374int IMFS_freenod(
375  rtems_filesystem_location_info_t  *node         /* IN/OUT */
376);
377
378int IMFS_memfile_remove(
379 IMFS_jnode_t  *the_jnode         /* IN/OUT */
380);
381
382int memfile_ftruncate(
383  rtems_libio_t *iop,               /* IN  */
384  off_t          length             /* IN  */
385);
386
387int imfs_dir_open(
388  rtems_libio_t *iop,             /* IN  */
389  const char    *pathname,        /* IN  */
390  uint32_t       flag,            /* IN  */
391  uint32_t       mode             /* IN  */
392);
393
394int imfs_dir_close(
395  rtems_libio_t *iop             /* IN  */
396);
397
398ssize_t imfs_dir_read(
399  rtems_libio_t *iop,              /* IN  */
400  void          *buffer,           /* IN  */
401  uint32_t       count             /* IN  */
402);
403
404int imfs_dir_lseek(
405  rtems_libio_t        *iop,              /* IN  */
406  off_t                 offset,           /* IN  */
407  int                   whence            /* IN  */
408);
409
410int imfs_dir_fstat(
411  rtems_filesystem_location_info_t *loc,         /* IN  */
412  struct stat                      *buf          /* OUT */
413);
414
415int imfs_dir_rmnod(
416  rtems_filesystem_location_info_t      *pathloc       /* IN */
417);
418
419int linearfile_read(
420  rtems_libio_t *iop,             /* IN  */
421  void          *buffer,          /* IN  */
422  uint32_t       count            /* IN  */
423);
424
425int linearfile_lseek(
426  rtems_libio_t        *iop,        /* IN  */
427  off_t                 offset,     /* IN  */
428  int                   whence      /* IN  */
429);
430
431int memfile_open(
432  rtems_libio_t *iop,             /* IN  */
433  const char    *pathname,        /* IN  */
434  uint32_t       flag,            /* IN  */
435  uint32_t       mode             /* IN  */
436);
437
438int memfile_close(
439  rtems_libio_t *iop             /* IN  */
440);
441
442ssize_t memfile_read(
443  rtems_libio_t *iop,             /* IN  */
444  void          *buffer,          /* IN  */
445  uint32_t       count            /* IN  */
446);
447
448ssize_t memfile_write(
449  rtems_libio_t *iop,             /* IN  */
450  const void    *buffer,          /* IN  */
451  uint32_t       count            /* IN  */
452);
453
454int memfile_ioctl(
455  rtems_libio_t *iop,             /* IN  */
456  uint32_t       command,         /* IN  */
457  void          *buffer           /* IN  */
458);
459
460int memfile_lseek(
461  rtems_libio_t        *iop,        /* IN  */
462  off_t                 offset,     /* IN  */
463  int                   whence      /* IN  */
464);
465
466int memfile_rmnod(
467  rtems_filesystem_location_info_t      *pathloc       /* IN */
468);
469
470int device_open(
471  rtems_libio_t *iop,            /* IN  */
472  const char    *pathname,       /* IN  */
473  uint32_t       flag,           /* IN  */
474  uint32_t       mode            /* IN  */
475);
476
477int device_close(
478  rtems_libio_t *iop             /* IN  */
479);
480
481ssize_t device_read(
482  rtems_libio_t *iop,            /* IN  */
483  void          *buffer,         /* IN  */
484  uint32_t       count           /* IN  */
485);
486
487ssize_t device_write(
488  rtems_libio_t *iop,               /* IN  */
489  const void    *buffer,            /* IN  */
490  uint32_t       count              /* IN  */
491);
492
493int device_ioctl(
494  rtems_libio_t *iop,               /* IN  */
495  uint32_t       command,           /* IN  */
496  void          *buffer             /* IN  */
497);
498
499int device_lseek(
500  rtems_libio_t *iop,               /* IN  */
501  off_t          offset,            /* IN  */
502  int            whence             /* IN  */
503);
504
505int IMFS_utime(
506  rtems_filesystem_location_info_t  *pathloc,       /* IN */
507  time_t                             actime,        /* IN */
508  time_t                             modtime        /* IN */
509);
510
511int IMFS_fchmod(
512  rtems_filesystem_location_info_t *loc,
513  mode_t                            mode
514);
515
516int IMFS_symlink(
517  rtems_filesystem_location_info_t  *parent_loc,  /* IN */
518  const char                        *link_name,
519  const char                        *node_name
520);
521
522int IMFS_readlink(
523 rtems_filesystem_location_info_t   *loc,         /* IN */
524 char                               *buf,         /* OUT */
525 size_t                             bufsize
526);
527
528int IMFS_fdatasync(
529  rtems_libio_t *iop
530);
531
532int IMFS_fcntl(
533  int            cmd,
534  rtems_libio_t *iop
535);
536
537int IMFS_rmnod(
538  rtems_filesystem_location_info_t      *pathloc       /* IN */
539);
540
541#ifdef __cplusplus
542}
543#endif
544
545#endif
546/* end of include file */
Note: See TracBrowser for help on using the repository browser.