source: rtems/cpukit/include/rtems/imfs.h @ 478dc89

5
Last change on this file since 478dc89 was 478dc89, checked in by Sebastian Huber <sebastian.huber@…>, on Mar 16, 2018 at 6:01:48 AM

imfs: Use most efficient way to get the time

As a side-effect, this fixes some warnings.

Close #3350.

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