source: rtems/cpukit/libfs/src/imfs/imfs.h @ 22ad8263

4.115
Last change on this file since 22ad8263 was 22ad8263, checked in by Ralf Corsepius <ralf.corsepius@…>, on 11/06/11 at 11:57:10

2011-11-06 Ralf Corsépius <ralf.corsepius@…>

PR1945/cpukit

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