source: rtems/cpukit/libfs/src/imfs/imfs.h @ 8162008

4.104.115
Last change on this file since 8162008 was 8162008, checked in by Chris Johns <chrisj@…>, on 05/15/10 at 06:29:55

2010-05-15 Chris Johns <chrisj@…>

  • libfs/src/imfs/imfs_initsupp.c, libfs/src/imfs/imfs.h, libfs/src/imfs/imfs_stat.c: PR1419. Return a device for the IMFS.
  • Property mode set to 100644
File size: 16.0 KB
Line 
1/*
2 *  Header file for the In-Memory File System
3 *
4 *  COPYRIGHT (c) 1989-2010.
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#include <rtems.h>
18#include <rtems/chain.h>
19
20#include <sys/types.h>
21#include <limits.h>
22#include <rtems/libio.h>
23
24#include <rtems/pipe.h>
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30/*
31 *  File name macros
32 */
33
34#define IMFS_is_valid_name_char( _ch ) ( 1 )
35
36#define IMFS_is_separator( _ch ) \
37   rtems_filesystem_is_separator( _ch )
38
39/*
40 *  Data types
41 */
42
43struct IMFS_jnode_tt;
44typedef struct IMFS_jnode_tt IMFS_jnode_t;
45
46typedef struct {
47  rtems_chain_control                    Entries;
48  rtems_filesystem_mount_table_entry_t  *mt_fs;
49}  IMFS_directory_t;
50
51typedef struct {
52  rtems_device_major_number  major;
53  rtems_device_minor_number  minor;
54}  IMFS_device_t;
55
56typedef struct {
57  IMFS_jnode_t  *link_node;
58} IMFS_link_t;
59
60typedef struct {
61  char *name;
62} IMFS_sym_link_t;
63
64typedef struct {
65  pipe_control_t  *pipe;
66} IMFS_fifo_t;
67
68/*
69 *  IMFS "memfile" information
70 *
71 *  The data structure for the in-memory "memfiles" is based on classic UNIX.
72 *
73 *  block_ptr is a pointer to a block of IMFS_MEMFILE_BYTES_PER_BLOCK in
74 *  length which could be data or a table of pointers to blocks.
75 *
76 *  Setting IMFS_MEMFILE_BYTES_PER_BLOCK to different values has a significant
77 *  impact on the maximum file size supported as well as the amount of
78 *  memory wasted due to internal file fragmentation.  The following
79 *  is a list of maximum file sizes based on various settings
80 *
81 *    max_filesize with blocks of   16 is         1,328
82 *    max_filesize with blocks of   32 is        18,656
83 *    max_filesize with blocks of   64 is       279,488
84 *    max_filesize with blocks of  128 is     4,329,344
85 *    max_filesize with blocks of  256 is    68,173,568
86 *    max_filesize with blocks of  512 is 1,082,195,456
87 */
88
89#define IMFS_MEMFILE_DEFAULT_BYTES_PER_BLOCK     128
90  extern int imfs_rq_memfile_bytes_per_block;
91  extern int imfs_memfile_bytes_per_block;
92
93#define IMFS_MEMFILE_BYTES_PER_BLOCK imfs_memfile_bytes_per_block
94#define IMFS_MEMFILE_BLOCK_SLOTS \
95  (IMFS_MEMFILE_BYTES_PER_BLOCK / sizeof(void *))
96
97typedef uint8_t *block_p;
98typedef block_p *block_ptr;
99
100typedef struct {
101  rtems_off64_t size;             /* size of file in bytes */
102  block_ptr     indirect;         /* array of 128 data blocks pointers */
103  block_ptr     doubly_indirect;  /* 128 indirect blocks */
104  block_ptr     triply_indirect;  /* 128 doubly indirect blocks */
105} IMFS_memfile_t;
106
107typedef struct {
108  rtems_off64_t size;             /* size of file in bytes */
109  block_p       direct;           /* pointer to file image */
110} IMFS_linearfile_t;
111
112/*
113 *  Important block numbers for "memfiles"
114 */
115
116#define FIRST_INDIRECT           (0)
117#define LAST_INDIRECT            (IMFS_MEMFILE_BLOCK_SLOTS - 1)
118
119#define FIRST_DOUBLY_INDIRECT    (LAST_INDIRECT + 1)
120#define LAST_DOUBLY_INDIRECT     \
121   (LAST_INDIRECT + \
122     (IMFS_MEMFILE_BLOCK_SLOTS * IMFS_MEMFILE_BLOCK_SLOTS))
123
124#define FIRST_TRIPLY_INDIRECT    (LAST_DOUBLY_INDIRECT + 1)
125#define LAST_TRIPLY_INDIRECT \
126   (LAST_DOUBLY_INDIRECT +\
127     (IMFS_MEMFILE_BLOCK_SLOTS * \
128        IMFS_MEMFILE_BLOCK_SLOTS * IMFS_MEMFILE_BLOCK_SLOTS))
129
130#define IMFS_MEMFILE_MAXIMUM_SIZE \
131  (LAST_TRIPLY_INDIRECT * IMFS_MEMFILE_BYTES_PER_BLOCK)
132
133/*
134 *  What types of IMFS file systems entities there can be.
135 */
136
137#define IMFS_jnode_types_t rtems_filesystem_node_types_t
138#define IMFS_DIRECTORY     RTEMS_FILESYSTEM_DIRECTORY
139#define IMFS_DEVICE        RTEMS_FILESYSTEM_DEVICE
140#define IMFS_HARD_LINK     RTEMS_FILESYSTEM_HARD_LINK
141#define IMFS_SYM_LINK      RTEMS_FILESYSTEM_SYM_LINK
142#define IMFS_MEMORY_FILE   RTEMS_FILESYSTEM_MEMORY_FILE
143#define IMFS_LINEAR_FILE   (IMFS_MEMORY_FILE + 1)
144#define IMFS_FIFO          (IMFS_LINEAR_FILE + 1)
145
146#define IMFS_NUMBER_OF_TYPES  (IMFS_FIFO + 1)
147
148typedef union {
149  IMFS_directory_t   directory;
150  IMFS_device_t      device;
151  IMFS_link_t        hard_link;
152  IMFS_sym_link_t    sym_link;
153  IMFS_memfile_t     file;
154  IMFS_linearfile_t  linearfile;
155  IMFS_fifo_t        fifo;
156} IMFS_types_union;
157
158/*
159 * Major device number for the IMFS. This is not a real device number because
160 * the IMFS is just a file system and does not have a driver.
161 */
162#define IMFS_DEVICE_MAJOR_NUMBER (0xfffe)
163
164/*
165 *  Maximum length of a "basename" of an IMFS file/node.
166 */
167
168#define IMFS_NAME_MAX  32
169
170/*
171 *  The control structure for an IMFS jnode.
172 */
173
174struct IMFS_jnode_tt {
175  rtems_chain_node    Node;                  /* for chaining them together */
176  IMFS_jnode_t       *Parent;                /* Parent node */
177  char                name[IMFS_NAME_MAX+1]; /* "basename" */
178  mode_t              st_mode;               /* File mode */
179  nlink_t             st_nlink;              /* Link count */
180  ino_t               st_ino;                /* inode */
181
182  uid_t               st_uid;                /* User ID of owner */
183  gid_t               st_gid;                /* Group ID of owner */
184
185  time_t              stat_atime;            /* Time of last access */
186  time_t              stat_mtime;            /* Time of last modification */
187  time_t              stat_ctime;            /* Time of last status change */
188  IMFS_jnode_types_t  type;                  /* Type of this entry */
189  IMFS_types_union    info;
190};
191
192#define IMFS_update_atime( _jnode )         \
193  do {                                      \
194    struct timeval tv;                      \
195    gettimeofday( &tv, 0 );                 \
196    _jnode->stat_atime  = (time_t) tv.tv_sec; \
197  } while (0)
198
199#define IMFS_update_mtime( _jnode )         \
200  do {                                      \
201    struct timeval tv;                      \
202    gettimeofday( &tv, 0 );                 \
203    _jnode->stat_mtime  = (time_t) tv.tv_sec; \
204  } while (0)
205
206#define IMFS_update_ctime( _jnode )         \
207  do {                                      \
208    struct timeval tv;                      \
209    gettimeofday( &tv, 0 );                 \
210    _jnode->stat_ctime  = (time_t) tv.tv_sec; \
211  } while (0)
212
213#define IMFS_mtime_ctime_update( _jnode )   \
214  do {                                      \
215    struct timeval tv;                      \
216    gettimeofday( &tv, 0 );                 \
217    _jnode->stat_mtime  = (time_t) tv.tv_sec; \
218    _jnode->stat_ctime  = (time_t) tv.tv_sec; \
219  } while (0)
220
221typedef struct {
222  int                                     instance;
223  ino_t                                   ino_count;
224  const rtems_filesystem_file_handlers_r *memfile_handlers;
225  const rtems_filesystem_file_handlers_r *directory_handlers;
226} IMFS_fs_info_t;
227
228/*
229 *  Type defination for tokens returned from IMFS_get_token
230 */
231
232typedef enum {
233  IMFS_NO_MORE_PATH,
234  IMFS_CURRENT_DIR,
235  IMFS_UP_DIR,
236  IMFS_NAME,
237  IMFS_INVALID_TOKEN
238} IMFS_token_types;
239
240/*
241 *  Shared Data
242 */
243
244extern const rtems_filesystem_file_handlers_r       IMFS_directory_handlers;
245extern const rtems_filesystem_file_handlers_r       IMFS_device_handlers;
246extern const rtems_filesystem_file_handlers_r       IMFS_link_handlers;
247extern const rtems_filesystem_file_handlers_r       IMFS_memfile_handlers;
248extern const rtems_filesystem_file_handlers_r       IMFS_fifo_handlers;
249extern const rtems_filesystem_operations_table      IMFS_ops;
250extern const rtems_filesystem_operations_table      miniIMFS_ops;
251extern const rtems_filesystem_limits_and_options_t  IMFS_LIMITS_AND_OPTIONS;
252
253/*
254 *  Routines
255 */
256
257extern int IMFS_initialize(
258   rtems_filesystem_mount_table_entry_t *mt_entry
259);
260
261extern int miniIMFS_initialize(
262   rtems_filesystem_mount_table_entry_t *mt_entry
263);
264
265extern int IMFS_initialize_support(
266   rtems_filesystem_mount_table_entry_t       *mt_entry,
267   const rtems_filesystem_operations_table    *op_table,
268   const rtems_filesystem_file_handlers_r     *memfile_handlers,
269   const rtems_filesystem_file_handlers_r     *directory_handlers
270);
271
272extern int IMFS_fsunmount(
273   rtems_filesystem_mount_table_entry_t *mt_entry
274);
275
276extern int rtems_tarfs_load(
277   char         *mountpoint,
278   uint8_t      *tar_image,
279   size_t        tar_size
280);
281
282/*
283 * Returns the number of characters copied from path to token.
284 */
285extern IMFS_token_types IMFS_get_token(
286  const char       *path,
287  int               pathlen,
288  char             *token,
289  int              *token_len
290);
291
292extern void IMFS_dump( void );
293
294extern void IMFS_initialize_jnode(
295  IMFS_jnode_t        *the_jnode,
296  IMFS_jnode_types_t   type,
297  IMFS_jnode_t        *the_parent,
298  char                *name,
299  mode_t               mode
300);
301
302extern IMFS_jnode_t *IMFS_find_match_in_dir(
303  IMFS_jnode_t *directory,                         /* IN */
304  char         *name                               /* IN */
305);
306
307extern rtems_filesystem_node_types_t IMFS_node_type(
308  rtems_filesystem_location_info_t    *pathloc     /* IN */
309);
310
311extern int IMFS_stat(
312  rtems_filesystem_location_info_t *loc,           /* IN  */
313  struct stat                      *buf            /* OUT */
314);
315
316extern int IMFS_Set_handlers(
317  rtems_filesystem_location_info_t   *loc
318);
319
320extern int IMFS_evaluate_link(
321  rtems_filesystem_location_info_t *node,        /* IN/OUT */
322  int                               flags        /* IN     */
323);
324
325extern int IMFS_eval_path(
326  const char                        *pathname,     /* IN     */
327  int                               pathnamelen,   /* IN     */
328  int                               flags,         /* IN     */
329  rtems_filesystem_location_info_t  *pathloc       /* IN/OUT */
330);
331
332extern int IMFS_link(
333  rtems_filesystem_location_info_t  *to_loc,      /* IN */
334  rtems_filesystem_location_info_t  *parent_loc,  /* IN */
335  const char                        *token        /* IN */
336);
337
338extern int IMFS_unlink(
339  rtems_filesystem_location_info_t  *parent_pathloc, /* IN */
340  rtems_filesystem_location_info_t  *pathloc         /* IN */
341);
342
343extern int IMFS_chown(
344  rtems_filesystem_location_info_t  *pathloc,      /* IN */
345  uid_t                              owner,        /* IN */
346  gid_t                              group         /* IN */
347);
348
349extern int IMFS_freenodinfo(
350  rtems_filesystem_location_info_t  *pathloc       /* IN */
351);
352
353extern int IMFS_mknod(
354  const char                        *path,         /* IN */
355  mode_t                             mode,         /* IN */
356  dev_t                              dev,          /* IN */
357  rtems_filesystem_location_info_t  *pathloc       /* IN/OUT */
358);
359
360extern IMFS_jnode_t *IMFS_allocate_node(
361  IMFS_jnode_types_t                type,         /* IN  */
362  const char                       *name,         /* IN  */
363  mode_t                            mode          /* IN  */
364);
365
366extern IMFS_jnode_t *IMFS_create_root_node(void);
367
368extern IMFS_jnode_t *IMFS_create_node(
369  rtems_filesystem_location_info_t *parent_loc,   /* IN  */
370  IMFS_jnode_types_t                type,         /* IN  */
371  const char                       *name,         /* IN  */
372  mode_t                            mode,         /* IN  */
373  const IMFS_types_union           *info          /* IN  */
374);
375
376extern int IMFS_evaluate_for_make(
377  const char                         *path,       /* IN     */
378  rtems_filesystem_location_info_t   *pathloc,    /* IN/OUT */
379  const char                        **name        /* OUT    */
380);
381
382extern int IMFS_mount(
383  rtems_filesystem_mount_table_entry_t *mt_entry  /* IN */
384);
385
386extern int IMFS_unmount(
387  rtems_filesystem_mount_table_entry_t *mt_entry  /* IN */
388);
389
390extern int IMFS_freenod(
391  rtems_filesystem_location_info_t  *node         /* IN/OUT */
392);
393
394extern int IMFS_memfile_remove(
395 IMFS_jnode_t  *the_jnode         /* IN/OUT */
396);
397
398extern int memfile_ftruncate(
399  rtems_libio_t *iop,               /* IN  */
400  rtems_off64_t  length             /* IN  */
401);
402
403extern int imfs_dir_open(
404  rtems_libio_t *iop,             /* IN  */
405  const char    *pathname,        /* IN  */
406  uint32_t       flag,            /* IN  */
407  uint32_t       mode             /* IN  */
408);
409
410extern int imfs_dir_close(
411  rtems_libio_t *iop             /* IN  */
412);
413
414extern ssize_t imfs_dir_read(
415  rtems_libio_t *iop,              /* IN  */
416  void          *buffer,           /* IN  */
417  size_t         count             /* IN  */
418);
419
420extern rtems_off64_t imfs_dir_lseek(
421  rtems_libio_t        *iop,              /* IN  */
422  rtems_off64_t         offset,           /* IN  */
423  int                   whence            /* IN  */
424);
425
426extern int imfs_dir_fstat(
427  rtems_filesystem_location_info_t *loc,         /* IN  */
428  struct stat                      *buf          /* OUT */
429);
430
431extern int imfs_dir_rmnod(
432  rtems_filesystem_location_info_t *parent_pathloc, /* IN */
433  rtems_filesystem_location_info_t *pathloc         /* IN */
434);
435
436extern int memfile_open(
437  rtems_libio_t *iop,             /* IN  */
438  const char    *pathname,        /* IN  */
439  uint32_t       flag,            /* IN  */
440  uint32_t       mode             /* IN  */
441);
442
443extern int memfile_close(
444  rtems_libio_t *iop             /* IN  */
445);
446
447extern ssize_t memfile_read(
448  rtems_libio_t *iop,             /* IN  */
449  void          *buffer,          /* IN  */
450  size_t         count            /* IN  */
451);
452
453extern ssize_t memfile_write(
454  rtems_libio_t *iop,             /* IN  */
455  const void    *buffer,          /* IN  */
456  size_t         count            /* IN  */
457);
458
459extern int memfile_ioctl(
460  rtems_libio_t *iop,             /* IN  */
461  uint32_t       command,         /* IN  */
462  void          *buffer           /* IN  */
463);
464
465extern rtems_off64_t memfile_lseek(
466  rtems_libio_t        *iop,        /* IN  */
467  rtems_off64_t         offset,     /* IN  */
468  int                   whence      /* IN  */
469);
470
471extern int memfile_rmnod(
472  rtems_filesystem_location_info_t  *parent_pathloc, /* IN */
473  rtems_filesystem_location_info_t  *pathloc         /* IN */
474);
475
476extern int device_open(
477  rtems_libio_t *iop,            /* IN  */
478  const char    *pathname,       /* IN  */
479  uint32_t       flag,           /* IN  */
480  uint32_t       mode            /* IN  */
481);
482
483extern int device_close(
484  rtems_libio_t *iop             /* IN  */
485);
486
487extern ssize_t device_read(
488  rtems_libio_t *iop,            /* IN  */
489  void          *buffer,         /* IN  */
490  size_t         count           /* IN  */
491);
492
493extern ssize_t device_write(
494  rtems_libio_t *iop,               /* IN  */
495  const void    *buffer,            /* IN  */
496  size_t         count              /* IN  */
497);
498
499extern int device_ioctl(
500  rtems_libio_t *iop,               /* IN  */
501  uint32_t       command,           /* IN  */
502  void          *buffer             /* IN  */
503);
504
505extern rtems_off64_t device_lseek(
506  rtems_libio_t *iop,               /* IN  */
507  rtems_off64_t  offset,            /* IN  */
508  int            whence             /* IN  */
509);
510
511extern int device_ftruncate(
512  rtems_libio_t *iop,               /* IN  */
513  rtems_off64_t  length             /* IN  */
514);
515
516extern int IMFS_utime(
517  rtems_filesystem_location_info_t  *pathloc,       /* IN */
518  time_t                             actime,        /* IN */
519  time_t                             modtime        /* IN */
520);
521
522extern int IMFS_fchmod(
523  rtems_filesystem_location_info_t *loc,
524  mode_t                            mode
525);
526
527extern int IMFS_symlink(
528  rtems_filesystem_location_info_t  *parent_loc,  /* IN */
529  const char                        *link_name,
530  const char                        *node_name
531);
532
533extern int IMFS_readlink(
534 rtems_filesystem_location_info_t   *loc,         /* IN */
535 char                               *buf,         /* OUT */
536 size_t                             bufsize
537);
538
539extern int IMFS_rename(
540  rtems_filesystem_location_info_t  *old_loc,         /* IN */
541  rtems_filesystem_location_info_t  *old_parent_loc,  /* IN */
542  rtems_filesystem_location_info_t  *new_parent_loc,  /* IN */
543  const char                        *new_name         /* IN */
544);
545
546extern int IMFS_fdatasync(
547  rtems_libio_t *iop
548);
549
550extern int IMFS_fcntl(
551  int            cmd,
552  rtems_libio_t *iop
553);
554
555extern int IMFS_rmnod(
556  rtems_filesystem_location_info_t  *parent_pathloc, /* IN */
557  rtems_filesystem_location_info_t  *pathloc         /* IN */
558);
559
560#ifdef __cplusplus
561}
562#endif
563
564#endif
565/* end of include file */
Note: See TracBrowser for help on using the repository browser.