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

4.104.115
Last change on this file since f1eb199a was 7baa484, checked in by Chris Johns <chrisj@…>, on 06/12/09 at 01:53:33

2009-06-12 Chris Johns <chrisj@…>

  • libblock/src/bdbuf.c: Update comments.
  • libblock/src/bdpart.c, libblock/src/ide_part_table.c: Get the device from the rdev field of the stat buf.
  • libcsupport/include/rtems/libio.h: Add a path length to evalpath handler. Add parent locations to rmmod and unlink handlers.
  • libcsupport/include/rtems/libio_.h: Add a path length to rtems_filesystem_evaluate_path. Add rtems_filesystem_evaluate_relative_path, rtems_filesystem_dirname, and rtems_filesystem_prefix_separators. Remove rtems_filesystem_evaluate_parent.
  • libcsupport/src/base_fs.c, libcsupport/src/chdir.c, libcsupport/src/chmod.c, libcsupport/src/chown.c, libcsupport/src/chroot.c, libcsupport/src/fchdir.c, libcsupport/src/link.c, libcsupport/src/mount.c, libcsupport/src/open.c, libcsupport/src/privateenv.c, libcsupport/src/readlink.c, libcsupport/src/unmount.c, libcsupport/src/utime.c, libcsupport/src/unmount.c, libcsupport/src/utime.c, libfs/src/devfs/devfs.h, libfs/src/devfs/devfs_eval.c, libfs/src/devfs/devstat.c, libfs/src/dosfs/msdos_create.c, libfs/src/dosfs/msdos_misc.c, libfs/src/imfs/imfs.h, libfs/src/imfs/imfs_eval.c, libfs/src/imfs/imfs_load_tar.c, libfs/src/imfs/ioman.c, libfs/src/pipe/pipe.c, libmisc/fsmount/fsmount.c, libnetworking/lib/ftpfs.c: Add the length parameter to the eval call.
  • libcsupport/src/eval.c: Add rtems_filesystem_prefix_separators, rtems_filesystem_dirname, rtems_filesystem_evaluate_relative_path. Add the length parameter to the eval call.
  • libcsupport/src/rmdir.c: Find the parent pathloc then the node pathloc from that node. Remove the call to find the parent given the node pathloc.
  • libcsupport/src/stat.c: Add the length parameter to the eval call. Set the device into the rdev field.
  • libcsupport/src/unlink.c: Find the parent pathloc then the node pathloc from that node. Remove the call to find the parent given the node pathloc.
  • libfs/src/dosfs/fat.c, libfs/src/dosfs/msdos_format.c: Get the disk device number from the stat rdev field.
  • libfs/src/dosfs/msdos.h: Add the length parameter to the eval call. Add the parent pathloc to the rmnod handler.
  • libfs/src/dosfs/msdos_dir.c: Add the parent pathloc to the rmnod handler.
  • libfs/src/dosfs/msdos_eval.c: Add the length parameter to the eval and token call.
  • libfs/src/imfs/imfs_directory.c: Add the parent pathloc to the rmnod handler.
  • libfs/src/imfs/imfs_fchmod.c: Do not test the mode flags for only the allowed flags. Add the missing flags spec'ed in the POSIX standard.
  • libfs/src/imfs/imfs_fsunmount.c, libfs/src/imfs/imfs_rmnod.c, libfs/src/imfs/imfs_unlink.c, libfs/src/imfs/memfile.c: Add the parent node. Currently ignored in the IMFS.
  • libfs/src/imfs/imfs_stat.c: Return the device number in the rdev field.
  • libfs/src/imfs/imfs_mknod.c, libfs/src/imfs/imfs_symlink.c : Add the length parameter to the token call.
  • libfs/src/nfsclient/src/nfs.c: Add the length parameter to the eval call and parent node to the rmnod and unlink command.
  • libmisc/shell/internal.h: Remove the libc mounter decl to make public.
  • libmisc/shell/main_mount.c: Add support for hooking external mount support for new file systems.
  • libmisc/shell/shell.h: Add helper functions for the mount command.
  • Property mode set to 100644
File size: 15.2 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#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 *  Maximum length of a "basename" of an IMFS file/node.
160 */
161
162#define IMFS_NAME_MAX  32
163
164/*
165 *  The control structure for an IMFS jnode.
166 */
167
168struct IMFS_jnode_tt {
169  rtems_chain_node    Node;                  /* for chaining them together */
170  IMFS_jnode_t       *Parent;                /* Parent node */
171  char                name[IMFS_NAME_MAX+1]; /* "basename" */
172  mode_t              st_mode;               /* File mode */
173  nlink_t             st_nlink;              /* Link count */
174  ino_t               st_ino;                /* inode */
175
176  uid_t               st_uid;                /* User ID of owner */
177  gid_t               st_gid;                /* Group ID of owner */
178
179  time_t              stat_atime;            /* Time of last access */
180  time_t              stat_mtime;            /* Time of last modification */
181  time_t              stat_ctime;            /* Time of last status change */
182  IMFS_jnode_types_t  type;                  /* Type of this entry */
183  IMFS_types_union    info;
184};
185
186#define IMFS_update_atime( _jnode )         \
187  do {                                      \
188    struct timeval tv;                      \
189    gettimeofday( &tv, 0 );                 \
190    _jnode->stat_atime  = (time_t) tv.tv_sec; \
191  } while (0)
192
193#define IMFS_update_mtime( _jnode )         \
194  do {                                      \
195    struct timeval tv;                      \
196    gettimeofday( &tv, 0 );                 \
197    _jnode->stat_mtime  = (time_t) tv.tv_sec; \
198  } while (0)
199
200#define IMFS_update_ctime( _jnode )         \
201  do {                                      \
202    struct timeval tv;                      \
203    gettimeofday( &tv, 0 );                 \
204    _jnode->stat_ctime  = (time_t) tv.tv_sec; \
205  } while (0)
206
207#define IMFS_mtime_ctime_update( _jnode )   \
208  do {                                      \
209    struct timeval tv;                      \
210    gettimeofday( &tv, 0 );                 \
211    _jnode->stat_mtime  = (time_t) tv.tv_sec; \
212    _jnode->stat_ctime  = (time_t) tv.tv_sec; \
213  } while (0)
214
215typedef struct {
216  ino_t                                   ino_count;
217  const rtems_filesystem_file_handlers_r *memfile_handlers;
218  const rtems_filesystem_file_handlers_r *directory_handlers;
219} IMFS_fs_info_t;
220
221/*
222 *  Type defination for tokens returned from IMFS_get_token
223 */
224
225typedef enum {
226  IMFS_NO_MORE_PATH,
227  IMFS_CURRENT_DIR,
228  IMFS_UP_DIR,
229  IMFS_NAME,
230  IMFS_INVALID_TOKEN
231} IMFS_token_types;
232
233/*
234 *  Shared Data
235 */
236
237extern const rtems_filesystem_file_handlers_r       IMFS_directory_handlers;
238extern const rtems_filesystem_file_handlers_r       IMFS_device_handlers;
239extern const rtems_filesystem_file_handlers_r       IMFS_link_handlers;
240extern const rtems_filesystem_file_handlers_r       IMFS_memfile_handlers;
241extern const rtems_filesystem_file_handlers_r       IMFS_fifo_handlers;
242extern const rtems_filesystem_operations_table      IMFS_ops;
243extern const rtems_filesystem_operations_table      miniIMFS_ops;
244extern const rtems_filesystem_limits_and_options_t  IMFS_LIMITS_AND_OPTIONS;
245
246/*
247 *  Routines
248 */
249
250extern int IMFS_initialize(
251   rtems_filesystem_mount_table_entry_t *mt_entry
252);
253
254extern int miniIMFS_initialize(
255   rtems_filesystem_mount_table_entry_t *mt_entry
256);
257
258extern int IMFS_initialize_support(
259   rtems_filesystem_mount_table_entry_t       *mt_entry,
260   const rtems_filesystem_operations_table    *op_table,
261   const rtems_filesystem_file_handlers_r     *memfile_handlers,
262   const rtems_filesystem_file_handlers_r     *directory_handlers
263);
264
265extern int IMFS_fsunmount(
266   rtems_filesystem_mount_table_entry_t *mt_entry
267);
268
269extern int rtems_tarfs_load(
270   char         *mountpoint,
271   uint8_t      *tar_image,
272   size_t        tar_size
273);
274
275/*
276 * Returns the number of characters copied from path to token.
277 */
278extern IMFS_token_types IMFS_get_token(
279  const char       *path,
280  int               pathlen,
281  char             *token,
282  int              *token_len
283);
284
285extern void IMFS_dump( void );
286
287extern void IMFS_initialize_jnode(
288  IMFS_jnode_t        *the_jnode,
289  IMFS_jnode_types_t   type,
290  IMFS_jnode_t        *the_parent,
291  char                *name,
292  mode_t               mode
293);
294
295extern IMFS_jnode_t *IMFS_find_match_in_dir(
296  IMFS_jnode_t *directory,                         /* IN */
297  char         *name                               /* IN */
298);
299
300extern rtems_filesystem_node_types_t IMFS_node_type(
301  rtems_filesystem_location_info_t    *pathloc     /* IN */
302);
303
304extern int IMFS_stat(
305  rtems_filesystem_location_info_t *loc,           /* IN  */
306  struct stat                      *buf            /* OUT */
307);
308
309extern int IMFS_Set_handlers(
310  rtems_filesystem_location_info_t   *loc
311);
312
313extern int IMFS_evaluate_link(
314  rtems_filesystem_location_info_t *node,        /* IN/OUT */
315  int                               flags        /* IN     */
316);
317
318extern int IMFS_eval_path(
319  const char                        *pathname,     /* IN     */
320  int                               pathnamelen,   /* IN     */
321  int                               flags,         /* IN     */
322  rtems_filesystem_location_info_t  *pathloc       /* IN/OUT */
323);
324
325
326extern int IMFS_link(
327  rtems_filesystem_location_info_t  *to_loc,      /* IN */
328  rtems_filesystem_location_info_t  *parent_loc,  /* IN */
329  const char                        *token        /* IN */
330);
331
332extern int IMFS_unlink(
333  rtems_filesystem_location_info_t  *parent_pathloc, /* IN */
334  rtems_filesystem_location_info_t  *pathloc         /* IN */
335);
336
337extern int IMFS_chown(
338  rtems_filesystem_location_info_t  *pathloc,      /* IN */
339  uid_t                              owner,        /* IN */
340  gid_t                              group         /* IN */
341);
342
343extern int IMFS_freenodinfo(
344  rtems_filesystem_location_info_t  *pathloc       /* IN */
345);
346
347extern int IMFS_mknod(
348  const char                        *path,         /* IN */
349  mode_t                             mode,         /* IN */
350  dev_t                              dev,          /* IN */
351  rtems_filesystem_location_info_t  *pathloc       /* IN/OUT */
352);
353
354extern IMFS_jnode_t *IMFS_create_node(
355  rtems_filesystem_location_info_t *parent_loc,   /* IN  */
356  IMFS_jnode_types_t                type,         /* IN  */
357  const char                       *name,         /* IN  */
358  mode_t                            mode,         /* IN  */
359  const IMFS_types_union           *info          /* IN  */
360);
361
362extern int IMFS_evaluate_for_make(
363  const char                         *path,        /* IN     */
364  rtems_filesystem_location_info_t   *pathloc,     /* IN/OUT */
365  const char                        **name         /* OUT    */
366);
367
368extern int IMFS_mount(
369  rtems_filesystem_mount_table_entry_t *mt_entry  /* IN */
370);
371
372extern int IMFS_unmount(
373  rtems_filesystem_mount_table_entry_t *mt_entry  /* IN */
374);
375
376extern int IMFS_freenod(
377  rtems_filesystem_location_info_t  *node         /* IN/OUT */
378);
379
380extern int IMFS_memfile_remove(
381 IMFS_jnode_t  *the_jnode         /* IN/OUT */
382);
383
384extern int memfile_ftruncate(
385  rtems_libio_t *iop,               /* IN  */
386  rtems_off64_t  length             /* IN  */
387);
388
389extern int imfs_dir_open(
390  rtems_libio_t *iop,             /* IN  */
391  const char    *pathname,        /* IN  */
392  uint32_t       flag,            /* IN  */
393  uint32_t       mode             /* IN  */
394);
395
396extern int imfs_dir_close(
397  rtems_libio_t *iop             /* IN  */
398);
399
400extern ssize_t imfs_dir_read(
401  rtems_libio_t *iop,              /* IN  */
402  void          *buffer,           /* IN  */
403  size_t         count             /* IN  */
404);
405
406extern rtems_off64_t imfs_dir_lseek(
407  rtems_libio_t        *iop,              /* IN  */
408  rtems_off64_t         offset,           /* IN  */
409  int                   whence            /* IN  */
410);
411
412extern int imfs_dir_fstat(
413  rtems_filesystem_location_info_t *loc,         /* IN  */
414  struct stat                      *buf          /* OUT */
415);
416
417extern int imfs_dir_rmnod(
418  rtems_filesystem_location_info_t *parent_pathloc, /* IN */
419  rtems_filesystem_location_info_t *pathloc         /* IN */
420);
421
422extern int memfile_open(
423  rtems_libio_t *iop,             /* IN  */
424  const char    *pathname,        /* IN  */
425  uint32_t       flag,            /* IN  */
426  uint32_t       mode             /* IN  */
427);
428
429extern int memfile_close(
430  rtems_libio_t *iop             /* IN  */
431);
432
433extern ssize_t memfile_read(
434  rtems_libio_t *iop,             /* IN  */
435  void          *buffer,          /* IN  */
436  size_t         count            /* IN  */
437);
438
439extern ssize_t memfile_write(
440  rtems_libio_t *iop,             /* IN  */
441  const void    *buffer,          /* IN  */
442  size_t         count            /* IN  */
443);
444
445extern int memfile_ioctl(
446  rtems_libio_t *iop,             /* IN  */
447  uint32_t       command,         /* IN  */
448  void          *buffer           /* IN  */
449);
450
451extern rtems_off64_t memfile_lseek(
452  rtems_libio_t        *iop,        /* IN  */
453  rtems_off64_t         offset,     /* IN  */
454  int                   whence      /* IN  */
455);
456
457extern int memfile_rmnod(
458  rtems_filesystem_location_info_t  *parent_pathloc, /* IN */
459  rtems_filesystem_location_info_t  *pathloc         /* IN */
460);
461
462extern int device_open(
463  rtems_libio_t *iop,            /* IN  */
464  const char    *pathname,       /* IN  */
465  uint32_t       flag,           /* IN  */
466  uint32_t       mode            /* IN  */
467);
468
469extern int device_close(
470  rtems_libio_t *iop             /* IN  */
471);
472
473extern ssize_t device_read(
474  rtems_libio_t *iop,            /* IN  */
475  void          *buffer,         /* IN  */
476  size_t         count           /* IN  */
477);
478
479extern ssize_t device_write(
480  rtems_libio_t *iop,               /* IN  */
481  const void    *buffer,            /* IN  */
482  size_t         count              /* IN  */
483);
484
485extern int device_ioctl(
486  rtems_libio_t *iop,               /* IN  */
487  uint32_t       command,           /* IN  */
488  void          *buffer             /* IN  */
489);
490
491extern rtems_off64_t device_lseek(
492  rtems_libio_t *iop,               /* IN  */
493  rtems_off64_t  offset,            /* IN  */
494  int            whence             /* IN  */
495);
496
497extern int device_ftruncate(
498  rtems_libio_t *iop,               /* IN  */
499  rtems_off64_t  length             /* IN  */
500);
501
502extern int IMFS_utime(
503  rtems_filesystem_location_info_t  *pathloc,       /* IN */
504  time_t                             actime,        /* IN */
505  time_t                             modtime        /* IN */
506);
507
508extern int IMFS_fchmod(
509  rtems_filesystem_location_info_t *loc,
510  mode_t                            mode
511);
512
513extern int IMFS_symlink(
514  rtems_filesystem_location_info_t  *parent_loc,  /* IN */
515  const char                        *link_name,
516  const char                        *node_name
517);
518
519extern int IMFS_readlink(
520 rtems_filesystem_location_info_t   *loc,         /* IN */
521 char                               *buf,         /* OUT */
522 size_t                             bufsize
523);
524
525extern int IMFS_fdatasync(
526  rtems_libio_t *iop
527);
528
529extern int IMFS_fcntl(
530  int            cmd,
531  rtems_libio_t *iop
532);
533
534extern int IMFS_rmnod(
535  rtems_filesystem_location_info_t  *parent_pathloc, /* IN */
536  rtems_filesystem_location_info_t  *pathloc         /* IN */
537);
538
539#ifdef __cplusplus
540}
541#endif
542
543#endif
544/* end of include file */
Note: See TracBrowser for help on using the repository browser.