source: rtems/c/src/lib/libc/imfs.h @ 562e7ed1

4.104.114.84.95
Last change on this file since 562e7ed1 was 562e7ed1, checked in by Joel Sherrill <joel.sherrill@…>, on 02/11/00 at 15:54:47

Increased block size to 128 and added comments based on feedback from
Java folks including Oscar Martinez de la Torre <omt@…>.

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