source: rtems/cpukit/libfs/src/imfs/imfs.h @ 7c007cf

4.104.114.95
Last change on this file since 7c007cf was 7c007cf, checked in by Thomas Doerfler <Thomas.Doerfler@…>, on 07/10/08 at 06:03:51

Added S_IRWXU, S_IRWXG and S_IRWXO to file mode.

  • Property mode set to 100644
File size: 14.3 KB
RevLine 
[07a3253d]1/*
2 *  Header file for the In-Memory File System
3 *
[6c7928b]4 *  COPYRIGHT (c) 1989-2007.
[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
[cf0539b1]9 *  http://www.rtems.com/license/LICENSE.
[07a3253d]10 *
11 *  $Id$
12 */
13
[a6f5d89]14#ifndef _RTEMS_IMFS_H
15#define _RTEMS_IMFS_H
[07a3253d]16
17#ifdef __cplusplus
18extern "C" {
19#endif
20
21#include <rtems.h>
[ebbe119e]22#include <rtems/chain.h>
[07a3253d]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 {
[72d2ec4d]45  rtems_chain_control                    Entries;
[07a3253d]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 {
[bf95ccb5]59  char *name;
[07a3253d]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
[c9b005a9]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 
[07a3253d]88#define IMFS_MEMFILE_BLOCK_SLOTS \
89  (IMFS_MEMFILE_BYTES_PER_BLOCK / sizeof(void *))
90
[eb12bf4]91typedef uint8_t *block_p;
[07a3253d]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
[0ef748fb]101typedef struct {
102  off_t      size;             /* size of file in bytes */
103  block_p    direct;           /* pointer to file image */
104} IMFS_linearfile_t;
105
[07a3253d]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
[d1941587]137#define IMFS_LINEAR_FILE   (IMFS_MEMORY_FILE + 1)
[07a3253d]138
[0ef748fb]139#define IMFS_NUMBER_OF_TYPES  (IMFS_LINEAR_FILE + 1)
[07a3253d]140
141typedef union {
142  IMFS_directory_t   directory;
143  IMFS_device_t      device;
144  IMFS_link_t        hard_link;
[a5305f6b]145  IMFS_sym_link_t    sym_link;
146  IMFS_memfile_t     file;
147  IMFS_linearfile_t  linearfile;
[07a3253d]148} IMFS_types_union;
149
[3cf8394]150/*
151 *  Maximum length of a "basename" of an IMFS file/node.
152 */
153
154#define IMFS_NAME_MAX  32
155
[07a3253d]156/*
157 *  The control structure for an IMFS jnode.
158 */
159
160struct IMFS_jnode_tt {
[72d2ec4d]161  rtems_chain_node    Node;                  /* for chaining them together */
[3cf8394]162  IMFS_jnode_t       *Parent;                /* Parent node */
[a5305f6b]163  char                name[IMFS_NAME_MAX+1]; /* "basename" */
[3cf8394]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
[df49c60]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 */
[3cf8394]174  IMFS_jnode_types_t  type;                  /* Type of this entry */
175  IMFS_types_union    info;
[07a3253d]176};
177
178#define IMFS_update_atime( _jnode )         \
179  do {                                      \
180    struct timeval tv;                      \
181    gettimeofday( &tv, 0 );                 \
[df49c60]182    _jnode->stat_atime  = (time_t) tv.tv_sec; \
[07a3253d]183  } while (0)
[a5305f6b]184
[07a3253d]185#define IMFS_update_mtime( _jnode )         \
186  do {                                      \
187    struct timeval tv;                      \
188    gettimeofday( &tv, 0 );                 \
[df49c60]189    _jnode->stat_mtime  = (time_t) tv.tv_sec; \
[07a3253d]190  } while (0)
[a5305f6b]191
[07a3253d]192#define IMFS_update_ctime( _jnode )         \
193  do {                                      \
194    struct timeval tv;                      \
195    gettimeofday( &tv, 0 );                 \
[df49c60]196    _jnode->stat_ctime  = (time_t) tv.tv_sec; \
[07a3253d]197  } while (0)
198
199#define IMFS_atime_mtime_update( _jnode )   \
200  do {                                      \
201    struct timeval tv;                      \
202    gettimeofday( &tv, 0 );                 \
[df49c60]203    _jnode->stat_mtime  = (time_t) tv.tv_sec; \
204    _jnode->stat_atime  = (time_t) tv.tv_sec; \
[07a3253d]205  } while (0)
206
207typedef struct {
[bf95ccb5]208  ino_t                                   ino_count;
209  const rtems_filesystem_file_handlers_r *memfile_handlers;
210  const rtems_filesystem_file_handlers_r *directory_handlers;
[07a3253d]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
[bf95ccb5]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;
[07a3253d]236
237/*
238 *  Routines
239 */
240
[a5305f6b]241int IMFS_initialize(
[07a3253d]242   rtems_filesystem_mount_table_entry_t *mt_entry
243);
244
[a5305f6b]245int miniIMFS_initialize(
[657e1bf6]246   rtems_filesystem_mount_table_entry_t *mt_entry
247);
248
[a5305f6b]249int IMFS_initialize_support(
[bf95ccb5]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
[657e1bf6]254);
255
[07a3253d]256int IMFS_fsunmount(
257   rtems_filesystem_mount_table_entry_t *mt_entry
258);
259
[d1941587]260int rtems_tarfs_load(
[1996aee7]261   char         *mountpoint,
[eb12bf4]262   uint8_t      *tar_image,
[1996aee7]263   size_t        tar_size
[0ef748fb]264);
[07a3253d]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
[a5305f6b]299int IMFS_Set_handlers(
300  rtems_filesystem_location_info_t   *loc
[7f6a0750]301);
302
[07a3253d]303int IMFS_evaluate_link(
304  rtems_filesystem_location_info_t *node,        /* IN/OUT */
305  int                               flags        /* IN     */
306);
307
[a5305f6b]308int IMFS_eval_path(
[07a3253d]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(
[bf95ccb5]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  */
[07a3253d]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);
[b568ccb]376
[07a3253d]377int imfs_dir_open(
378  rtems_libio_t *iop,             /* IN  */
379  const char    *pathname,        /* IN  */
[f91bbe64]380  uint32_t       flag,            /* IN  */
381  uint32_t       mode             /* IN  */
[07a3253d]382);
[b568ccb]383
[07a3253d]384int imfs_dir_close(
385  rtems_libio_t *iop             /* IN  */
386);
[b568ccb]387
[d32359a7]388ssize_t imfs_dir_read(
[07a3253d]389  rtems_libio_t *iop,              /* IN  */
390  void          *buffer,           /* IN  */
[7192476f]391  size_t         count             /* IN  */
[07a3253d]392);
[b568ccb]393
[07a3253d]394int imfs_dir_lseek(
395  rtems_libio_t        *iop,              /* IN  */
396  off_t                 offset,           /* IN  */
397  int                   whence            /* IN  */
398);
[b568ccb]399
[07a3253d]400int imfs_dir_fstat(
401  rtems_filesystem_location_info_t *loc,         /* IN  */
402  struct stat                      *buf          /* OUT */
403);
[b568ccb]404
405int imfs_dir_rmnod(
406  rtems_filesystem_location_info_t      *pathloc       /* IN */
407);
408
[07a3253d]409int memfile_open(
410  rtems_libio_t *iop,             /* IN  */
411  const char    *pathname,        /* IN  */
[f91bbe64]412  uint32_t       flag,            /* IN  */
413  uint32_t       mode             /* IN  */
[07a3253d]414);
[b568ccb]415
[07a3253d]416int memfile_close(
417  rtems_libio_t *iop             /* IN  */
418);
[b568ccb]419
[d32359a7]420ssize_t memfile_read(
[07a3253d]421  rtems_libio_t *iop,             /* IN  */
422  void          *buffer,          /* IN  */
[7192476f]423  size_t         count            /* IN  */
[07a3253d]424);
[b568ccb]425
[d32359a7]426ssize_t memfile_write(
[07a3253d]427  rtems_libio_t *iop,             /* IN  */
428  const void    *buffer,          /* IN  */
[7192476f]429  size_t         count            /* IN  */
[07a3253d]430);
[b568ccb]431
[07a3253d]432int memfile_ioctl(
433  rtems_libio_t *iop,             /* IN  */
[f91bbe64]434  uint32_t       command,         /* IN  */
[07a3253d]435  void          *buffer           /* IN  */
436);
[b568ccb]437
[07a3253d]438int memfile_lseek(
439  rtems_libio_t        *iop,        /* IN  */
440  off_t                 offset,     /* IN  */
441  int                   whence      /* IN  */
442);
[b568ccb]443
444int memfile_rmnod(
445  rtems_filesystem_location_info_t      *pathloc       /* IN */
446);
447
[07a3253d]448int device_open(
449  rtems_libio_t *iop,            /* IN  */
450  const char    *pathname,       /* IN  */
[f91bbe64]451  uint32_t       flag,           /* IN  */
452  uint32_t       mode            /* IN  */
[07a3253d]453);
[b568ccb]454
[07a3253d]455int device_close(
456  rtems_libio_t *iop             /* IN  */
457);
[b568ccb]458
[d32359a7]459ssize_t device_read(
[07a3253d]460  rtems_libio_t *iop,            /* IN  */
461  void          *buffer,         /* IN  */
[7192476f]462  size_t         count           /* IN  */
[07a3253d]463);
[b568ccb]464
[d32359a7]465ssize_t device_write(
[07a3253d]466  rtems_libio_t *iop,               /* IN  */
467  const void    *buffer,            /* IN  */
[7192476f]468  size_t         count              /* IN  */
[07a3253d]469);
[b568ccb]470
[07a3253d]471int device_ioctl(
472  rtems_libio_t *iop,               /* IN  */
[f91bbe64]473  uint32_t       command,           /* IN  */
[07a3253d]474  void          *buffer             /* IN  */
475);
[b568ccb]476
[07a3253d]477int device_lseek(
478  rtems_libio_t *iop,               /* IN  */
479  off_t          offset,            /* IN  */
480  int            whence             /* IN  */
481);
[b568ccb]482
[7c007cf]483int device_ftruncate(
484  rtems_libio_t *iop,               /* IN  */
485  off_t          length             /* IN  */
486);
487
[07a3253d]488int IMFS_utime(
489  rtems_filesystem_location_info_t  *pathloc,       /* IN */
490  time_t                             actime,        /* IN */
491  time_t                             modtime        /* IN */
492);
[b568ccb]493
[07a3253d]494int IMFS_fchmod(
495  rtems_filesystem_location_info_t *loc,
496  mode_t                            mode
497);
498
499int IMFS_symlink(
500  rtems_filesystem_location_info_t  *parent_loc,  /* IN */
501  const char                        *link_name,
502  const char                        *node_name
503);
504
505int IMFS_readlink(
506 rtems_filesystem_location_info_t   *loc,         /* IN */
507 char                               *buf,         /* OUT */
[a5305f6b]508 size_t                             bufsize
[07a3253d]509);
510
[49629bd8]511int IMFS_fdatasync(
512  rtems_libio_t *iop
513);
514
[578a415]515int IMFS_fcntl(
516  int            cmd,
517  rtems_libio_t *iop
518);
519
[94b357c2]520int IMFS_rmnod(
521  rtems_filesystem_location_info_t      *pathloc       /* IN */
522);
523
[07a3253d]524#ifdef __cplusplus
525}
526#endif
527
528#endif
529/* end of include file */
Note: See TracBrowser for help on using the repository browser.