source: rtems/c/src/lib/libc/imfs.h @ 4e36a2f

4.104.114.84.95
Last change on this file since 4e36a2f was 08311cc3, checked in by Joel Sherrill <joel.sherrill@…>, on 11/17/99 at 17:51:34

Updated copyright notice.

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