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

4.115
Last change on this file since f785492 was f785492, checked in by Sebastian Huber <sebastian.huber@…>, on Feb 14, 2015 at 7:07:19 PM

IMFS: Add CONFIGURE_IMFS_DISABLE_READDIR

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