source: rtems/cpukit/include/rtems/imfs.h @ 2afb22b

Last change on this file since 2afb22b was 2afb22b, checked in by Chris Johns <chrisj@…>, on Dec 23, 2017 at 7:18:56 AM

Remove make preinstall

A speciality of the RTEMS build system was the make preinstall step. It
copied header files from arbitrary locations into the build tree. The
header files were included via the -Bsome/build/tree/path GCC command
line option.

This has at least seven problems:

  • The make preinstall step itself needs time and disk space.
  • Errors in header files show up in the build tree copy. This makes it hard for editors to open the right file to fix the error.
  • There is no clear relationship between source and build tree header files. This makes an audit of the build process difficult.
  • The visibility of all header files in the build tree makes it difficult to enforce API barriers. For example it is discouraged to use BSP-specifics in the cpukit.
  • An introduction of a new build system is difficult.
  • Include paths specified by the -B option are system headers. This may suppress warnings.
  • The parallel build had sporadic failures on some hosts.

This patch removes the make preinstall step. All installed header
files are moved to dedicated include directories in the source tree.
Let @RTEMS_CPU@ be the target architecture, e.g. arm, powerpc, sparc,
etc. Let @RTEMS_BSP_FAMILIY@ be a BSP family base directory, e.g.
erc32, imx, qoriq, etc.

The new cpukit include directories are:

  • cpukit/include
  • cpukit/score/cpu/@RTEMS_CPU@/include
  • cpukit/libnetworking

The new BSP include directories are:

  • bsps/include
  • bsps/@RTEMS_CPU@/include
  • bsps/@RTEMS_CPU@/@RTEMS_BSP_FAMILIY@/include

There are build tree include directories for generated files.

The include directory order favours the most general header file, e.g.
it is not possible to override general header files via the include path
order.

The "bootstrap -p" option was removed. The new "bootstrap -H" option
should be used to regenerate the "headers.am" files.

Update #3254.

  • Property mode set to 100644
File size: 22.4 KB
Line 
1/**
2 * @file
3 *
4 * @brief 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.org/license/LICENSE.
14 */
15
16#ifndef _RTEMS_IMFS_H
17#define _RTEMS_IMFS_H
18
19#include <limits.h>
20
21#include <rtems/libio_.h>
22#include <rtems/pipe.h>
23
24/**
25 * @brief In-Memory File System Support.
26 *
27 * @defgroup IMFS In-Memory File System Support
28 *
29 * @ingroup FileSystemTypesAndMount
30 */
31/**@{*/
32
33#ifdef __cplusplus
34extern "C" {
35#endif
36
37/*
38 *  Data types
39 */
40
41struct IMFS_jnode_tt;
42typedef struct IMFS_jnode_tt IMFS_jnode_t;
43
44/**
45 *  IMFS "memfile" information
46 *
47 *  The data structure for the in-memory "memfiles" is based on classic UNIX.
48 *
49 *  block_ptr is a pointer to a block of IMFS_MEMFILE_BYTES_PER_BLOCK in
50 *  length which could be data or a table of pointers to blocks.
51 *
52 *  Setting IMFS_MEMFILE_BYTES_PER_BLOCK to different values has a significant
53 *  impact on the maximum file size supported as well as the amount of
54 *  memory wasted due to internal file fragmentation.  The following
55 *  is a list of maximum file sizes based on various settings
56 *
57 *  @code
58 *    max_filesize with blocks of   16 is         1,328
59 *    max_filesize with blocks of   32 is        18,656
60 *    max_filesize with blocks of   64 is       279,488
61 *    max_filesize with blocks of  128 is     4,329,344
62 *    max_filesize with blocks of  256 is    68,173,568
63 *    max_filesize with blocks of  512 is 1,082,195,456
64 *  @endcode
65 */
66#define IMFS_MEMFILE_DEFAULT_BYTES_PER_BLOCK     128
67  extern int imfs_rq_memfile_bytes_per_block;
68  extern int imfs_memfile_bytes_per_block;
69
70#define IMFS_MEMFILE_BYTES_PER_BLOCK imfs_memfile_bytes_per_block
71#define IMFS_MEMFILE_BLOCK_SLOTS \
72  (IMFS_MEMFILE_BYTES_PER_BLOCK / sizeof(void *))
73
74typedef uint8_t *block_p;
75typedef block_p *block_ptr;
76
77/*
78 *  Important block numbers for "memfiles"
79 */
80#define FIRST_INDIRECT           (0)
81#define LAST_INDIRECT            (IMFS_MEMFILE_BLOCK_SLOTS - 1)
82
83#define FIRST_DOUBLY_INDIRECT    (LAST_INDIRECT + 1)
84#define LAST_DOUBLY_INDIRECT     \
85   (LAST_INDIRECT + \
86     (IMFS_MEMFILE_BLOCK_SLOTS * IMFS_MEMFILE_BLOCK_SLOTS))
87
88#define FIRST_TRIPLY_INDIRECT    (LAST_DOUBLY_INDIRECT + 1)
89#define LAST_TRIPLY_INDIRECT \
90   (LAST_DOUBLY_INDIRECT +\
91     (IMFS_MEMFILE_BLOCK_SLOTS * \
92        IMFS_MEMFILE_BLOCK_SLOTS * IMFS_MEMFILE_BLOCK_SLOTS))
93
94#define IMFS_MEMFILE_MAXIMUM_SIZE \
95  (LAST_TRIPLY_INDIRECT * IMFS_MEMFILE_BYTES_PER_BLOCK)
96
97/** @} */
98
99/**
100 * @addtogroup IMFSGenericNodes
101 */
102/**@{*/
103
104/**
105 * @brief Initializes an IMFS node.
106 *
107 * @param[in] node The IMFS node.
108 * @param[in] arg The user provided argument pointer.  It may contain node
109 *   specific initialization information.
110 *
111 * @retval node Successful operation.
112 * @retval NULL An error occurred.  The @c errno indicates the error.  This
113 * will abort the make operation.
114 *
115 * @see IMFS_node_control, IMFS_node_initialize_default(), and
116 * IMFS_node_initialize_generic().
117 */
118typedef IMFS_jnode_t *(*IMFS_node_control_initialize)(
119  IMFS_jnode_t *node,
120  void *arg
121);
122
123/**
124 * @brief Returns the node and does nothing else.
125 *
126 * @param[in] node The IMFS node.
127 * @param[in] arg The user provided argument pointer.  It is not used.
128 *
129 * @retval node Returns always the node passed as parameter.
130 *
131 * @see IMFS_node_control.
132 */
133IMFS_jnode_t *IMFS_node_initialize_default(
134  IMFS_jnode_t *node,
135  void *arg
136);
137
138IMFS_jnode_t *IMFS_node_initialize_directory(
139  IMFS_jnode_t *node,
140  void *arg
141);
142
143/**
144 * @brief Returns the node and sets the generic node context.
145 *
146 * @param[in] node The IMFS node.
147 * @param[in] arg The user provided argument pointer.  It must contain the
148 *   generic context.
149 *
150 * @retval node Returns always the node passed as parameter.
151 *
152 * @see IMFS_node_control.
153 */
154IMFS_jnode_t *IMFS_node_initialize_generic(
155  IMFS_jnode_t *node,
156  void *arg
157);
158
159/**
160 * @brief Prepares the removal of an IMFS node from its parent directory.
161 *
162 * @param[in] node The IMFS node.
163 *
164 * @retval node Successful operation.
165 * @retval NULL An error occurred.  The @c errno indicates the error.  This
166 * will abort the removal operation.
167 *
168 * @see IMFS_node_control and IMFS_node_remove_default().
169 */
170typedef IMFS_jnode_t *(*IMFS_node_control_remove)(
171  IMFS_jnode_t *node
172);
173
174/**
175 * @brief Returns the node and does nothing else.
176 *
177 * @param[in] node The IMFS node.
178 *
179 * @retval node Returns always the node passed as parameter.
180 *
181 * @see IMFS_node_control.
182 */
183IMFS_jnode_t *IMFS_node_remove_default(
184  IMFS_jnode_t *node
185);
186
187IMFS_jnode_t *IMFS_node_remove_directory( IMFS_jnode_t *node );
188
189/**
190 * @brief Destroys an IMFS node.
191 *
192 * @param[in] node The IMFS node.
193 *
194 * @see IMFS_node_control and IMFS_node_destroy_default().
195 */
196typedef void (*IMFS_node_control_destroy)( IMFS_jnode_t *node );
197
198/**
199 * @brief Frees the node.
200 *
201 * @param[in] node The IMFS node.
202 *
203 * @see IMFS_node_control.
204 */
205void IMFS_node_destroy_default( IMFS_jnode_t *node );
206
207/**
208 * @brief IMFS node control.
209 */
210typedef struct {
211  const rtems_filesystem_file_handlers_r *handlers;
212  IMFS_node_control_initialize node_initialize;
213  IMFS_node_control_remove node_remove;
214  IMFS_node_control_destroy node_destroy;
215} IMFS_node_control;
216
217typedef struct {
218  IMFS_node_control node_control;
219  size_t node_size;
220} IMFS_mknod_control;
221
222/** @} */
223
224/**
225 * @addtogroup IMFS
226 */
227/**@{*/
228
229/*
230 *  Maximum length of a "basename" of an IMFS file/node.
231 */
232
233#define IMFS_NAME_MAX _POSIX_NAME_MAX
234
235/*
236
237 *  The control structure for an IMFS jnode.
238 */
239
240struct IMFS_jnode_tt {
241  rtems_chain_node    Node;                  /* for chaining them together */
242  IMFS_jnode_t       *Parent;                /* Parent node */
243  const char         *name;                  /* "basename" (not \0 terminated) */
244  uint16_t            namelen;               /* Length of "basename" */
245  uint16_t            flags;                 /* Node flags */
246  mode_t              st_mode;               /* File mode */
247  unsigned short      reference_count;
248  nlink_t             st_nlink;              /* Link count */
249
250  uid_t               st_uid;                /* User ID of owner */
251  gid_t               st_gid;                /* Group ID of owner */
252
253  time_t              stat_atime;            /* Time of last access */
254  time_t              stat_mtime;            /* Time of last modification */
255  time_t              stat_ctime;            /* Time of last status change */
256  const IMFS_node_control *control;
257};
258
259#define IMFS_NODE_FLAG_NAME_ALLOCATED 0x1
260
261typedef struct {
262  IMFS_jnode_t                          Node;
263  rtems_chain_control                   Entries;
264  rtems_filesystem_mount_table_entry_t *mt_fs;
265} IMFS_directory_t;
266
267typedef struct {
268  IMFS_jnode_t              Node;
269  rtems_device_major_number major;
270  rtems_device_minor_number minor;
271} IMFS_device_t;
272
273typedef struct {
274  IMFS_jnode_t  Node;
275  IMFS_jnode_t *link_node;
276} IMFS_link_t;
277
278typedef struct {
279  IMFS_jnode_t  Node;
280  char         *name;
281} IMFS_sym_link_t;
282
283typedef struct {
284  IMFS_jnode_t Node;
285  size_t       size;             /* size of file in bytes */
286} IMFS_filebase_t;
287
288typedef struct {
289  IMFS_filebase_t File;
290  block_ptr       indirect;         /* array of 128 data blocks pointers */
291  block_ptr       doubly_indirect;  /* 128 indirect blocks */
292  block_ptr       triply_indirect;  /* 128 doubly indirect blocks */
293} IMFS_memfile_t;
294
295typedef struct {
296  IMFS_filebase_t File;
297  block_p         direct;           /* pointer to file image */
298} IMFS_linearfile_t;
299
300/* Support copy on write for linear files */
301typedef union {
302  IMFS_jnode_t      Node;
303  IMFS_filebase_t   File;
304  IMFS_memfile_t    Memfile;
305  IMFS_linearfile_t Linearfile;
306} IMFS_file_t;
307
308typedef struct {
309  IMFS_jnode_t    Node;
310  pipe_control_t *pipe;
311} IMFS_fifo_t;
312
313typedef struct {
314  IMFS_jnode_t  Node;
315  void         *context;
316} IMFS_generic_t;
317
318static inline IMFS_directory_t *IMFS_iop_to_directory(
319  const rtems_libio_t *iop
320)
321{
322  return (IMFS_directory_t *) iop->pathinfo.node_access;
323}
324
325static inline IMFS_device_t *IMFS_iop_to_device( const rtems_libio_t *iop )
326{
327  return (IMFS_device_t *) iop->pathinfo.node_access;
328}
329
330static inline IMFS_file_t *IMFS_iop_to_file( const rtems_libio_t *iop )
331{
332  return (IMFS_file_t *) iop->pathinfo.node_access;
333}
334
335static inline IMFS_memfile_t *IMFS_iop_to_memfile( const rtems_libio_t *iop )
336{
337  return (IMFS_memfile_t *) iop->pathinfo.node_access;
338}
339
340static inline void IMFS_update_atime( IMFS_jnode_t *jnode )
341{
342  struct timeval now;
343
344  gettimeofday( &now, 0 );
345
346  jnode->stat_atime = now.tv_sec;
347}
348
349static inline void IMFS_update_mtime( IMFS_jnode_t *jnode )
350{
351  struct timeval now;
352
353  gettimeofday( &now, 0 );
354
355  jnode->stat_mtime = now.tv_sec;
356}
357
358static inline void IMFS_update_ctime( IMFS_jnode_t *jnode )
359{
360  struct timeval now;
361
362  gettimeofday( &now, 0 );
363
364  jnode->stat_ctime = now.tv_sec;
365}
366
367static inline void IMFS_mtime_ctime_update( IMFS_jnode_t *jnode )
368{
369  struct timeval now;
370
371  gettimeofday( &now, 0 );
372
373  jnode->stat_mtime = now.tv_sec;
374  jnode->stat_ctime = now.tv_sec;
375}
376
377typedef struct {
378  const IMFS_mknod_control *directory;
379  const IMFS_mknod_control *device;
380  const IMFS_mknod_control *file;
381  const IMFS_mknod_control *fifo;
382} IMFS_mknod_controls;
383
384typedef struct {
385  IMFS_directory_t Root_directory;
386  const IMFS_mknod_controls *mknod_controls;
387} IMFS_fs_info_t;
388
389typedef struct {
390  IMFS_fs_info_t *fs_info;
391  const rtems_filesystem_operations_table *ops;
392  const IMFS_mknod_controls *mknod_controls;
393} IMFS_mount_data;
394
395/*
396 *  Shared Data
397 */
398
399extern const IMFS_mknod_control IMFS_mknod_control_dir_default;
400extern const IMFS_mknod_control IMFS_mknod_control_dir_minimal;
401extern const IMFS_mknod_control IMFS_mknod_control_device;
402extern const IMFS_mknod_control IMFS_mknod_control_memfile;
403extern const IMFS_node_control IMFS_node_control_linfile;
404extern const IMFS_mknod_control IMFS_mknod_control_fifo;
405extern const IMFS_mknod_control IMFS_mknod_control_enosys;
406
407extern const rtems_filesystem_limits_and_options_t  IMFS_LIMITS_AND_OPTIONS;
408
409/*
410 *  Routines
411 */
412
413extern int IMFS_initialize(
414   rtems_filesystem_mount_table_entry_t *mt_entry,
415   const void                           *data
416);
417
418extern int IMFS_initialize_support(
419  rtems_filesystem_mount_table_entry_t *mt_entry,
420  const void                           *data
421);
422
423/**
424 * @brief Unmount this instance of IMFS.
425 */
426extern void IMFS_fsunmount(
427   rtems_filesystem_mount_table_entry_t *mt_entry
428);
429
430/**
431 * @brief RTEMS load tarfs.
432 *
433 * This file implements the "mount" procedure for tar-based IMFS
434 * extensions.  The TAR is not actually mounted under the IMFS.
435 * Directories from the TAR file are created as usual in the IMFS.
436 * File entries are created as IMFS_LINEAR_FILE nodes with their nods
437 * pointing to addresses in the TAR image.
438 *
439 * Here we create the mountpoint directory and load the tarfs at
440 * that node.  Once the IMFS has been mounted, we work through the
441 * tar image and perform as follows:
442 *  - For directories, simply call mkdir().  The IMFS creates nodes as
443 *    needed.
444 *  - For files, we make our own calls to IMFS eval_for_make and
445 *    create_node.
446 *
447 * TAR file format:
448 *
449 * @code
450 *   Offset   Length                 Contents
451 *     0    100  bytes  File name ('\0' terminated, 99 maxmum length)
452 *   100      8  bytes  File mode (in octal ascii)
453 *   108      8  bytes  User ID (in octal ascii)
454 *   116      8  bytes  Group ID (in octal ascii)
455 *   124     12  bytes  File size (s) (in octal ascii)
456 *   136     12  bytes  Modify time (in octal ascii)
457 *   148      8  bytes  Header checksum (in octal ascii)
458 *   156      1  bytes  Link flag
459 *   157    100  bytes  Linkname ('\0' terminated, 99 maxmum length)
460 *   257      8  bytes  Magic PAX ("ustar\0" + 2 bytes padding)
461 *   257      8  bytes  Magic GNU tar ("ustar  \0")
462 *   265     32  bytes  User name ('\0' terminated, 31 maxmum length)
463 *   297     32  bytes  Group name ('\0' terminated, 31 maxmum length)
464 *   329      8  bytes  Major device ID (in octal ascii)
465 *   337      8  bytes  Minor device ID (in octal ascii)
466 *   345    167  bytes  Padding
467 *   512   (s+p) bytes  File contents (s+p) := (((s) + 511) & ~511),
468 *                      round up to 512 bytes
469 * @endcode
470 *
471 *  Checksum:
472 *  @code
473 *    int   i, sum;
474 *    char *header = tar_header_pointer;
475 *
476 *    sum = 0;
477 *    for (i = 0; i < 512; i++)
478 *        sum += 0xFF & header[i];
479 * @endcode
480 */
481extern int rtems_tarfs_load(
482   const char *mountpoint,
483   uint8_t *tar_image,
484   size_t tar_size
485);
486
487/**
488 * @brief Destroy an IMFS node.
489 */
490extern void IMFS_node_destroy( IMFS_jnode_t *node );
491
492/**
493 * @brief Clone an IMFS node.
494 */
495extern int IMFS_node_clone( rtems_filesystem_location_info_t *loc );
496
497/**
498 * @brief Free an IMFS node.
499 */
500extern void IMFS_node_free( const rtems_filesystem_location_info_t *loc );
501
502/**
503 * @brief Perform a status processing for the IMFS.
504 *
505 * This routine provides a stat for the IMFS file system.
506 */
507extern int IMFS_stat(
508  const rtems_filesystem_location_info_t *loc,
509  struct stat *buf
510);
511
512extern int IMFS_stat_file(
513  const rtems_filesystem_location_info_t *loc,
514  struct stat *buf
515);
516
517/**
518 * @brief IMFS evaluation node support.
519 */
520extern void IMFS_eval_path(
521  rtems_filesystem_eval_path_context_t *ctx
522);
523
524/**
525 * @brief Create a new IMFS link node.
526 *
527 * The following rouine creates a new link node under parent with the
528 * name given in name.  The link node is set to point to the node at
529 * to_loc.
530 */
531extern int IMFS_link(
532  const rtems_filesystem_location_info_t *parentloc,
533  const rtems_filesystem_location_info_t *targetloc,
534  const char *name,
535  size_t namelen
536);
537
538/**
539 * @brief Change the owner of IMFS.
540 *
541 * This routine is the implementation of the chown() system
542 * call for the IMFS.
543 */
544extern int IMFS_chown(
545  const rtems_filesystem_location_info_t *loc,
546  uid_t owner,
547  gid_t group
548);
549
550/**
551 * @brief Create an IMFS node.
552 *
553 * Routine to create a node in the IMFS file system.
554 */
555extern int IMFS_mknod(
556  const rtems_filesystem_location_info_t *parentloc,
557  const char *name,
558  size_t namelen,
559  mode_t mode,
560  dev_t dev
561);
562
563extern IMFS_jnode_t *IMFS_initialize_node(
564  IMFS_jnode_t *node,
565  const IMFS_node_control *node_control,
566  const char *name,
567  size_t namelen,
568  mode_t mode,
569  void *arg
570);
571
572/**
573 * @brief Create an IMFS node.
574 *
575 * Create an IMFS filesystem node of an arbitrary type that is NOT
576 * the root directory node.
577 */
578extern IMFS_jnode_t *IMFS_create_node(
579  const rtems_filesystem_location_info_t *parentloc,
580  const IMFS_node_control *node_control,
581  size_t node_size,
582  const char *name,
583  size_t namelen,
584  mode_t mode,
585  void *arg
586);
587
588static inline bool IMFS_is_imfs_instance(
589  const rtems_filesystem_location_info_t *loc
590)
591{
592  return loc->mt_entry->ops->clonenod_h == IMFS_node_clone;
593}
594
595/** @} */
596
597/**
598 * @defgroup IMFSGenericNodes IMFS Generic Nodes
599 *
600 * @ingroup LibIO
601 *
602 * @brief Generic nodes are an alternative to standard drivers in RTEMS.
603 *
604 * The handlers of a generic node are called with less overhead compared to the
605 * standard driver operations.  The usage of file system node handlers enable
606 * more features like support for fsync() and fdatasync().  The generic nodes
607 * use the reference counting of the IMFS.  This provides automatic node
608 * destruction when the last reference vanishes.
609 *
610 * @{
611 */
612
613/**
614 * @brief Initializer for a generic node control.
615 *
616 * @param[in] handlers The file system node handlers.
617 * @param[in] init The node initialization method.
618 * @param[in] destroy The node destruction method.
619 */
620#define IMFS_GENERIC_INITIALIZER( handlers, init, destroy ) \
621  { \
622    ( handlers ), \
623    ( init ), \
624    IMFS_node_remove_default, \
625    ( destroy ) \
626  }
627
628/**
629 * @brief Makes a generic IMFS node.
630 *
631 * @param[in] path The path to the new generic IMFS node.
632 * @param[in] mode The node mode.
633 * @param[in] node_control The node control.
634 * @param[in] context The node control handler context.
635 *
636 * @retval 0 Successful operation.
637 * @retval -1 An error occurred.  The @c errno indicates the error.
638 *
639 * @code
640 * #include <sys/stat.h>
641 * #include <assert.h>
642 * #include <fcntl.h>
643 *
644 * #include <rtems/imfs.h>
645 *
646 * static const rtems_filesystem_file_handlers_r some_node_handlers = {
647 *   ...
648 * };
649 *
650 * static IMFS_jnode_t *some_node_init(IMFS_jnode_t *node, void *arg)
651 * {
652 *   void *context;
653 *
654 *   node = IMFS_node_initialize_generic(node, arg);
655 *   context = IMFS_generic_get_context_by_node(node);
656 *
657 *   return node;
658 * }
659 *
660 * static void some_node_destroy(IMFS_jnode_t *node)
661 * {
662 *   void *context = IMFS_generic_get_context_by_node(node);
663 *
664 *   IMFS_node_destroy_default(node);
665 * }
666 *
667 * static const IMFS_node_control some_node_control = IMFS_GENERIC_INITIALIZER(
668 *   &some_node_handlers,
669 *   some_node_init,
670 *   some_node_destroy
671 * );
672 *
673 * void example(void *some_node_context)
674 * {
675 *   int rv;
676 *
677 *   rv = IMFS_make_generic_node(
678 *     "/path/to/some/generic/node",
679 *     S_IFCHR | S_IRWXU | S_IRWXG | S_IRWXO,
680 *     &some_node_control,
681 *     some_node_context
682 *   );
683 *   assert(rv == 0);
684 * }
685 * @endcode
686 */
687extern int IMFS_make_generic_node(
688  const char *path,
689  mode_t mode,
690  const IMFS_node_control *node_control,
691  void *context
692);
693
694/** @} */
695
696/**
697 * @addtogroup IMFS
698 */
699/**@{*/
700
701/**
702 * @brief Mount an IMFS.
703 */
704extern int IMFS_mount(
705  rtems_filesystem_mount_table_entry_t *mt_entry  /* IN */
706);
707
708/**
709 * @brief Unmount an IMFS.
710 */
711extern int IMFS_unmount(
712  rtems_filesystem_mount_table_entry_t *mt_entry  /* IN */
713);
714
715/**
716 * @name IMFS Memory File Handlers
717 *
718 * This section contains the set of handlers used to process operations on
719 * IMFS memory file nodes.  The memory files are created in memory using
720 * malloc'ed memory.  Thus any data stored in one of these files is lost
721 * at system shutdown unless special arrangements to copy the data to
722 * some type of non-volailte storage are made by the application.
723 */
724/**@{*/
725
726extern ssize_t IMFS_memfile_write(
727  IMFS_memfile_t      *memfile,
728  off_t                start,
729  const unsigned char *source,
730  unsigned int         length
731);
732
733/** @} */
734
735/**
736 * @name IMFS Device Node Handlers
737 *
738 * This section contains the set of handlers used to map operations on
739 * IMFS device nodes onto calls to the RTEMS Classic API IO Manager.
740 */
741/**@{*/
742
743extern int device_open(
744  rtems_libio_t *iop,            /* IN  */
745  const char    *pathname,       /* IN  */
746  int            oflag,          /* IN  */
747  mode_t         mode            /* IN  */
748);
749
750extern int device_close(
751  rtems_libio_t *iop             /* IN  */
752);
753
754extern ssize_t device_read(
755  rtems_libio_t *iop,            /* IN  */
756  void          *buffer,         /* IN  */
757  size_t         count           /* IN  */
758);
759
760extern ssize_t device_write(
761  rtems_libio_t *iop,               /* IN  */
762  const void    *buffer,            /* IN  */
763  size_t         count              /* IN  */
764);
765
766extern int device_ioctl(
767  rtems_libio_t   *iop,
768  ioctl_command_t  command,
769  void            *buffer
770);
771
772extern int device_ftruncate(
773  rtems_libio_t *iop,               /* IN  */
774  off_t          length             /* IN  */
775);
776
777/** @} */
778
779/**
780 * @brief Set IMFS file access and modification times.
781 *
782 *
783 * This routine is the implementation of the utime() system
784 * call for the IMFS.
785 */
786extern int IMFS_utime(
787  const rtems_filesystem_location_info_t *loc,
788  time_t actime,
789  time_t modtime
790);
791
792/**
793 * @brief Change the IMFS file mode.
794 */
795extern int IMFS_fchmod(
796  const rtems_filesystem_location_info_t *loc,
797  mode_t mode
798);
799
800/**
801 * @brief Create a new IMFS symbolic link node.
802 *
803 * The following rouine creates a new symbolic link node under parent
804 * with the name given in name.  The node is set to point to the node at
805 * to_loc.
806 */
807extern int IMFS_symlink(
808  const rtems_filesystem_location_info_t *parentloc,
809  const char *name,
810  size_t namelen,
811  const char *target
812);
813
814/**
815 * @brief Put IMFS symbolic link into buffer.
816 *
817 * The following rouine puts the symbolic links destination name into
818 * buff.
819 *
820 */
821extern ssize_t IMFS_readlink(
822  const rtems_filesystem_location_info_t *loc,
823  char *buf,
824  size_t bufsize
825);
826
827/**
828 * @brief Rename the IMFS.
829 *
830 * The following rouine creates a new link node under parent with the
831 * name given in name and removes the old.
832 */
833extern int IMFS_rename(
834  const rtems_filesystem_location_info_t *oldparentloc,
835  const rtems_filesystem_location_info_t *oldloc,
836  const rtems_filesystem_location_info_t *newparentloc,
837  const char *name,
838  size_t namelen
839);
840/**
841 * @brief IMFS node removal handler.
842 *
843 * This file contains the handler used to remove a node when a file type
844 * does not require special actions.
845 */
846extern int IMFS_rmnod(
847  const rtems_filesystem_location_info_t *parentloc,
848  const rtems_filesystem_location_info_t *loc
849);
850
851/*
852 *  Turn on IMFS assertions when RTEMS_DEBUG is defined.
853 */
854#ifdef RTEMS_DEBUG
855  #include <assert.h>
856
857  #define IMFS_assert(_x) assert(_x)
858#else
859  #define IMFS_assert(_x)
860#endif
861
862static inline void IMFS_Set_handlers( rtems_filesystem_location_info_t *loc )
863{
864  IMFS_jnode_t *node = (IMFS_jnode_t *) loc->node_access;
865
866  loc->handlers = node->control->handlers;
867}
868
869static inline void IMFS_add_to_directory(
870  IMFS_jnode_t *dir_node,
871  IMFS_jnode_t *entry_node
872)
873{
874  IMFS_directory_t *dir = (IMFS_directory_t *) dir_node;
875
876  entry_node->Parent = dir_node;
877  rtems_chain_append_unprotected( &dir->Entries, &entry_node->Node );
878}
879
880static inline void IMFS_remove_from_directory( IMFS_jnode_t *node )
881{
882  IMFS_assert( node->Parent != NULL );
883  node->Parent = NULL;
884  rtems_chain_extract_unprotected( &node->Node );
885}
886
887static inline bool IMFS_is_directory( const IMFS_jnode_t *node )
888{
889  return S_ISDIR( node->st_mode );
890}
891
892#define IMFS_STAT_FMT_HARD_LINK 0
893
894static inline bool IMFS_is_hard_link( mode_t mode )
895{
896  return ( mode & S_IFMT ) == IMFS_STAT_FMT_HARD_LINK;
897}
898
899static inline ino_t IMFS_node_to_ino( const IMFS_jnode_t *node )
900{
901  return (ino_t) ((uintptr_t) node);
902}
903
904/** @} */
905
906/**
907 * @addtogroup IMFSGenericNodes
908 */
909/**@{*/
910
911static inline void *IMFS_generic_get_context_by_node(
912  const IMFS_jnode_t *node
913)
914{
915  const IMFS_generic_t *generic = (const IMFS_generic_t *) node;
916
917  return generic->context;
918}
919
920static inline void *IMFS_generic_get_context_by_location(
921  const rtems_filesystem_location_info_t *loc
922)
923{
924  return loc->node_access_2;
925}
926
927static inline void *IMFS_generic_get_context_by_iop(
928  const rtems_libio_t *iop
929)
930{
931  return IMFS_generic_get_context_by_location( &iop->pathinfo );
932}
933
934static inline dev_t IMFS_generic_get_device_identifier_by_node(
935  const IMFS_jnode_t *node
936)
937{
938  return rtems_filesystem_make_dev_t_from_pointer( node );
939}
940
941#ifdef __cplusplus
942}
943#endif
944/** @} */
945#endif
946/* end of include file */
Note: See TracBrowser for help on using the repository browser.