source: rtems/cpukit/libfs/src/imfs/imfs.h @ 72d2ec4d

4.104.114.95
Last change on this file since 72d2ec4d was 72d2ec4d, checked in by Chris Johns <chrisj@…>, on 07/03/08 at 01:37:38

2008-07-03 Chris Johns <chrisj@…>

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