source: rtems/cpukit/libfs/src/imfs/imfs.h @ 49629bd8

4.104.114.84.95
Last change on this file since 49629bd8 was 49629bd8, checked in by Jennifer Averett <Jennifer.Averett@…>, on 12/03/98 at 22:17:46

Added a imfs fdatasync routine that gets called for fdatasync and datasync.

  • Property mode set to 100644
File size: 12.4 KB
Line 
1/*
2 *  Header file for the In-Memory File System
3 *
4 *  COPYRIGHT (c) 1989-1998.
5 *  On-Line Applications Research Corporation (OAR).
6 *  Copyright assigned to U.S. Government, 1994.
7 *
8 *  The license and distribution terms for this file may be
9 *  found in the file LICENSE in this distribution or at
10 *  http://www.OARcorp.com/rtems/license.html.
11 *
12 *  $Id$
13 */
14
15#ifndef __IMFS_h
16#define __IMFS_h
17
18#ifdef __cplusplus
19extern "C" {
20#endif
21
22#include <rtems.h>
23#include <chain.h>
24
25#include <sys/types.h>
26#include <limits.h>
27#include <rtems/libio.h>
28
29/*
30 *  File name macros
31 */
32
33#define IMFS_is_valid_name_char( _ch ) ( 1 )
34
35#define IMFS_is_separator( _ch ) \
36   rtems_filesystem_is_separator( _ch )
37
38/*
39 *  Data types
40 */
41
42struct IMFS_jnode_tt;
43typedef struct IMFS_jnode_tt IMFS_jnode_t;
44
45typedef struct {
46  Chain_Control                          Entries;
47  rtems_filesystem_mount_table_entry_t  *mt_fs;
48}  IMFS_directory_t;
49
50typedef struct {
51  rtems_device_major_number  major;
52  rtems_device_minor_number  minor;
53}  IMFS_device_t;
54
55typedef struct {
56  IMFS_jnode_t  *link_node;
57} IMFS_link_t;
58
59typedef struct {
60  const char *name;
61} IMFS_sym_link_t;
62
63/*
64 *  IMFS "memfile" information
65 *
66 *  The data structure for the in-memory "memfiles" is based on classic UNIX.
67 *
68 *  block_ptr is a pointer to a block of IMFS_MEMFILE_BYTES_PER_BLOCK in
69 *  length which could be data or a table of pointers to blocks.
70 */
71
72#define IMFS_MEMFILE_BYTES_PER_BLOCK     64 /* 512 */
73#define IMFS_MEMFILE_BLOCK_SLOTS \
74  (IMFS_MEMFILE_BYTES_PER_BLOCK / sizeof(void *))
75
76typedef unsigned char * block_p;
77typedef block_p *block_ptr;
78
79typedef struct {
80  off_t      size;             /* size of file in bytes */
81  block_ptr  indirect;         /* array of 128 data blocks pointers */
82  block_ptr  doubly_indirect;  /* 128 indirect blocks */
83  block_ptr  triply_indirect;  /* 128 doubly indirect blocks */
84} IMFS_memfile_t;
85
86/*
87 *  Important block numbers for "memfiles"
88 */
89
90#define FIRST_INDIRECT           (0)
91#define LAST_INDIRECT            (IMFS_MEMFILE_BLOCK_SLOTS - 1)
92
93#define FIRST_DOUBLY_INDIRECT    (LAST_INDIRECT + 1)
94#define LAST_DOUBLY_INDIRECT     \
95   (LAST_INDIRECT + \
96     (IMFS_MEMFILE_BLOCK_SLOTS * IMFS_MEMFILE_BLOCK_SLOTS))
97
98#define FIRST_TRIPLY_INDIRECT    (LAST_DOUBLY_INDIRECT + 1)
99#define LAST_TRIPLY_INDIRECT \
100   (LAST_DOUBLY_INDIRECT +\
101     (IMFS_MEMFILE_BLOCK_SLOTS * \
102        IMFS_MEMFILE_BLOCK_SLOTS * IMFS_MEMFILE_BLOCK_SLOTS))
103
104#define IMFS_MEMFILE_MAXIMUM_SIZE \
105  (LAST_TRIPLY_INDIRECT * IMFS_MEMFILE_BYTES_PER_BLOCK)
106
107/*
108 *  What types of IMFS file systems entities there can be.
109 */
110
111#define IMFS_jnode_types_t rtems_filesystem_node_types_t
112#define IMFS_DIRECTORY     RTEMS_FILESYSTEM_DIRECTORY
113#define IMFS_DEVICE        RTEMS_FILESYSTEM_DEVICE
114#define IMFS_HARD_LINK     RTEMS_FILESYSTEM_HARD_LINK
115#define IMFS_SYM_LINK      RTEMS_FILESYSTEM_SYM_LINK
116#define IMFS_MEMORY_FILE   RTEMS_FILESYSTEM_MEMORY_FILE
117
118#define IMFS_NUMBER_OF_TYPES  (IMFS_MEMORY_FILE + 1)
119
120typedef union {
121  IMFS_directory_t   directory;
122  IMFS_device_t      device;
123  IMFS_link_t        hard_link;
124  IMFS_sym_link_t    sym_link;   
125  IMFS_memfile_t     file;   
126} IMFS_types_union;
127
128/*
129 *  The control structure for an IMFS jnode.
130 */
131
132struct IMFS_jnode_tt {
133  Chain_Node               Node;             /* for chaining them together */
134  IMFS_jnode_t            *Parent;           /* Parent node */
135  char                     name[NAME_MAX+1]; /* "basename" */
136  mode_t                   st_mode;          /* File mode */
137  nlink_t                  st_nlink;         /* Link count */
138  ino_t                    st_ino;           /* inode */
139
140  uid_t                    st_uid;           /* User ID of owner */
141  gid_t                    st_gid;           /* Group ID of owner */
142
143  time_t                   st_atime;         /* Time of last access */
144  time_t                   st_mtime;         /* Time of last modification */
145  time_t                   st_ctime;         /* Time of last status change */
146  IMFS_jnode_types_t       type;             /* Type of this entry */
147  IMFS_types_union         info;
148};
149
150#define IMFS_update_atime( _jnode )         \
151  do {                                      \
152    struct timeval tv;                      \
153    gettimeofday( &tv, 0 );                 \
154    _jnode->st_atime  = (time_t) tv.tv_sec; \
155  } while (0)
156               
157#define IMFS_update_mtime( _jnode )         \
158  do {                                      \
159    struct timeval tv;                      \
160    gettimeofday( &tv, 0 );                 \
161    _jnode->st_mtime  = (time_t) tv.tv_sec; \
162  } while (0)
163               
164#define IMFS_update_ctime( _jnode )         \
165  do {                                      \
166    struct timeval tv;                      \
167    gettimeofday( &tv, 0 );                 \
168    _jnode->st_ctime  = (time_t) tv.tv_sec; \
169  } while (0)
170
171#define IMFS_atime_mtime_update( _jnode )   \
172  do {                                      \
173    struct timeval tv;                      \
174    gettimeofday( &tv, 0 );                 \
175    _jnode->st_mtime  = (time_t) tv.tv_sec; \
176    _jnode->st_atime  = (time_t) tv.tv_sec; \
177  } while (0)
178
179typedef struct {
180  ino_t    ino_count;
181} IMFS_fs_info_t;
182
183#define increment_and_check_linkcounts( _fs_info )                  \
184  ((IMFS_fs_info_t * )_fs_info)->link_counts++;                     \
185  if ( ((IMFS_fs_info_t * )_fs_info)->link_counts  > MAXSYMLINKS )  \
186    set_errno_and_return_minus_one( ELOOP )
187
188#define decrement_linkcounts(  _fs_info )             \
189  ((IMFS_fs_info_t * )_fs_info)->link_counts--;       
190
191/*
192 *  Type defination for tokens returned from IMFS_get_token
193 */
194
195typedef enum {
196  IMFS_NO_MORE_PATH,
197  IMFS_CURRENT_DIR,
198  IMFS_UP_DIR,
199  IMFS_NAME,
200  IMFS_INVALID_TOKEN
201} IMFS_token_types;
202
203/*
204 *  Shared Data
205 */
206
207extern rtems_filesystem_file_handlers_r       device_handlers;
208extern rtems_filesystem_file_handlers_r       memfile_handlers;
209extern rtems_filesystem_file_handlers_r       dir_handlers;
210extern rtems_filesystem_file_handlers_r       null_handlers;
211extern rtems_filesystem_operations_table      IMFS_ops;
212extern rtems_filesystem_limits_and_options_t  IMFS_LIMITS_AND_OPTIONS;
213
214/*
215 *  Routines
216 */
217
218int IMFS_initialize(
219   rtems_filesystem_mount_table_entry_t *mt_entry
220);
221
222int IMFS_fsunmount(
223   rtems_filesystem_mount_table_entry_t *mt_entry
224);
225
226
227/*
228 * Returns the number of characters copied from path to token.
229 */
230IMFS_token_types IMFS_get_token(
231  const char       *path,
232  char             *token,
233  int              *token_len
234);
235
236void IMFS_dump( void );
237
238void IMFS_initialize_jnode(
239  IMFS_jnode_t        *the_jnode,
240  IMFS_jnode_types_t   type,
241  IMFS_jnode_t        *the_parent,
242  char                *name,
243  mode_t               mode
244);
245
246IMFS_jnode_t *IMFS_find_match_in_dir(
247  IMFS_jnode_t *directory,                         /* IN */
248  char         *name                               /* IN */
249);
250
251rtems_filesystem_node_types_t IMFS_node_type(
252  rtems_filesystem_location_info_t    *pathloc     /* IN */
253);
254
255int IMFS_stat(
256  rtems_filesystem_location_info_t *loc,           /* IN  */
257  struct stat                      *buf            /* OUT */
258);
259
260int IMFS_evaluate_link(
261  rtems_filesystem_location_info_t *node,        /* IN/OUT */
262  int                               flags        /* IN     */
263);
264
265int IMFS_eval_path( 
266  const char                        *pathname,     /* IN     */
267  int                               flags,         /* IN     */
268  rtems_filesystem_location_info_t  *pathloc       /* IN/OUT */
269);
270
271
272int IMFS_link(
273  rtems_filesystem_location_info_t  *to_loc,      /* IN */
274  rtems_filesystem_location_info_t  *parent_loc,  /* IN */
275  const char                        *token        /* IN */
276);
277
278int IMFS_unlink(
279  rtems_filesystem_location_info_t  *pathloc       /* IN */
280);
281
282int IMFS_chown(
283  rtems_filesystem_location_info_t  *pathloc,      /* IN */
284  uid_t                              owner,        /* IN */
285  gid_t                              group         /* IN */
286);
287
288int IMFS_freenodinfo(
289  rtems_filesystem_location_info_t  *pathloc       /* IN */
290);
291
292int IMFS_rmnod(
293  rtems_filesystem_location_info_t  *pathloc       /* IN */
294);
295
296int IMFS_mknod(
297  const char                        *path,         /* IN */
298  mode_t                             mode,         /* IN */
299  dev_t                              dev,          /* IN */
300  rtems_filesystem_location_info_t  *pathloc       /* IN/OUT */
301);
302
303IMFS_jnode_t *IMFS_create_node(
304  rtems_filesystem_location_info_t  *parent_loc,   /* IN  */
305  IMFS_jnode_types_t                 type,         /* IN  */
306  char                              *name,         /* IN  */
307  mode_t                             mode,         /* IN  */
308  IMFS_types_union                  *info          /* IN  */
309);
310
311int IMFS_evaluate_for_make(
312  const char                         *path,        /* IN     */
313  rtems_filesystem_location_info_t   *pathloc,     /* IN/OUT */
314  const char                        **name         /* OUT    */
315);
316
317int IMFS_mount(
318  rtems_filesystem_mount_table_entry_t *mt_entry  /* IN */
319);
320
321int IMFS_unmount(
322  rtems_filesystem_mount_table_entry_t *mt_entry  /* IN */
323);
324
325int IMFS_freenod(
326  rtems_filesystem_location_info_t  *node         /* IN/OUT */
327);
328
329int IMFS_memfile_remove(
330 IMFS_jnode_t  *the_jnode         /* IN/OUT */
331);
332
333int memfile_ftruncate(
334  rtems_libio_t *iop,               /* IN  */
335  off_t          length             /* IN  */
336);
337int imfs_dir_open(
338  rtems_libio_t *iop,             /* IN  */
339  const char    *pathname,        /* IN  */
340  unsigned32     flag,            /* IN  */
341  unsigned32     mode             /* IN  */
342);
343int imfs_dir_close(
344  rtems_libio_t *iop             /* IN  */
345);
346int imfs_dir_read(
347  rtems_libio_t *iop,              /* IN  */
348  void          *buffer,           /* IN  */
349  unsigned32     count             /* IN  */
350);
351int imfs_dir_lseek(
352  rtems_libio_t        *iop,              /* IN  */
353  off_t                 offset,           /* IN  */
354  int                   whence            /* IN  */
355);
356int imfs_dir_fstat(
357  rtems_filesystem_location_info_t *loc,         /* IN  */
358  struct stat                      *buf          /* OUT */
359);
360int memfile_open(
361  rtems_libio_t *iop,             /* IN  */
362  const char    *pathname,        /* IN  */
363  unsigned32     flag,            /* IN  */
364  unsigned32     mode             /* IN  */
365);
366int memfile_close(
367  rtems_libio_t *iop             /* IN  */
368);
369int memfile_read(
370  rtems_libio_t *iop,             /* IN  */
371  void          *buffer,          /* IN  */
372  unsigned32     count            /* IN  */
373);
374int memfile_write(
375  rtems_libio_t *iop,             /* IN  */
376  const void    *buffer,          /* IN  */
377  unsigned32     count            /* IN  */
378);
379int memfile_ioctl(
380  rtems_libio_t *iop,             /* IN  */
381  unsigned32     command,         /* IN  */
382  void          *buffer           /* IN  */
383);
384int memfile_lseek(
385  rtems_libio_t        *iop,        /* IN  */
386  off_t                 offset,     /* IN  */
387  int                   whence      /* IN  */
388);
389int device_open(
390  rtems_libio_t *iop,            /* IN  */
391  const char    *pathname,       /* IN  */
392  unsigned32     flag,           /* IN  */
393  unsigned32     mode            /* IN  */
394);
395int device_close(
396  rtems_libio_t *iop             /* IN  */
397);
398int device_read(
399  rtems_libio_t *iop,            /* IN  */
400  void          *buffer,         /* IN  */
401  unsigned32     count           /* IN  */
402);
403int device_write(
404  rtems_libio_t *iop,               /* IN  */
405  const void    *buffer,            /* IN  */
406  unsigned32     count              /* IN  */
407);
408int device_ioctl(
409  rtems_libio_t *iop,               /* IN  */
410  unsigned32     command,           /* IN  */
411  void          *buffer             /* IN  */
412);
413int device_lseek(
414  rtems_libio_t *iop,               /* IN  */
415  off_t          offset,            /* IN  */
416  int            whence             /* IN  */
417);
418int IMFS_utime(
419  rtems_filesystem_location_info_t  *pathloc,       /* IN */
420  time_t                             actime,        /* IN */
421  time_t                             modtime        /* IN */
422);
423int IMFS_fchmod(
424  rtems_filesystem_location_info_t *loc,
425  mode_t                            mode
426);
427
428int IMFS_symlink(
429  rtems_filesystem_location_info_t  *parent_loc,  /* IN */
430  const char                        *link_name,
431  const char                        *node_name
432);
433
434int IMFS_readlink(
435 rtems_filesystem_location_info_t   *loc,         /* IN */
436 char                               *buf,         /* OUT */
437 size_t                             bufsize   
438);
439
440int IMFS_fdatasync(
441  rtems_libio_t *iop
442);
443
444#ifdef __cplusplus
445}
446#endif
447
448#endif
449/* end of include file */
Note: See TracBrowser for help on using the repository browser.