source: rtems/cpukit/include/rtems/imfs.h @ 98c01a5

Last change on this file since 98c01a5 was 98c01a5, checked in by Sebastian Huber <sebastian.huber@…>, on Nov 8, 2018 at 10:32:13 AM

rtems: Avoid <rtems/score/timecounter.h> in API

Use a real function for rtems_clock_get_uptime_seconds().

Update #3598.

  • Property mode set to 100644
File size: 22.5 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#include <rtems/score/timecounter.h>
25
26/**
27 * @brief In-Memory File System Support.
28 *
29 * @defgroup IMFS In-Memory File System Support
30 *
31 * @ingroup FileSystemTypesAndMount
32 */
33/**@{*/
34
35#ifdef __cplusplus
36extern "C" {
37#endif
38
39/*
40 *  Data types
41 */
42
43struct IMFS_jnode_tt;
44typedef struct IMFS_jnode_tt IMFS_jnode_t;
45
46/**
47 *  IMFS "memfile" information
48 *
49 *  The data structure for the in-memory "memfiles" is based on classic UNIX.
50 *
51 *  block_ptr is a pointer to a block of IMFS_MEMFILE_BYTES_PER_BLOCK in
52 *  length which could be data or a table of pointers to blocks.
53 *
54 *  Setting IMFS_MEMFILE_BYTES_PER_BLOCK to different values has a significant
55 *  impact on the maximum file size supported as well as the amount of
56 *  memory wasted due to internal file fragmentation.  The following
57 *  is a list of maximum file sizes based on various settings
58 *
59 *  @code
60 *    max_filesize with blocks of   16 is         1,328
61 *    max_filesize with blocks of   32 is        18,656
62 *    max_filesize with blocks of   64 is       279,488
63 *    max_filesize with blocks of  128 is     4,329,344
64 *    max_filesize with blocks of  256 is    68,173,568
65 *    max_filesize with blocks of  512 is 1,082,195,456
66 *  @endcode
67 */
68#define IMFS_MEMFILE_DEFAULT_BYTES_PER_BLOCK     128
69  extern int imfs_rq_memfile_bytes_per_block;
70  extern int imfs_memfile_bytes_per_block;
71
72#define IMFS_MEMFILE_BYTES_PER_BLOCK imfs_memfile_bytes_per_block
73#define IMFS_MEMFILE_BLOCK_SLOTS \
74  (IMFS_MEMFILE_BYTES_PER_BLOCK / sizeof(void *))
75
76typedef uint8_t *block_p;
77typedef block_p *block_ptr;
78
79/*
80 *  Important block numbers for "memfiles"
81 */
82#define FIRST_INDIRECT           (0)
83#define LAST_INDIRECT            (IMFS_MEMFILE_BLOCK_SLOTS - 1)
84
85#define FIRST_DOUBLY_INDIRECT    (LAST_INDIRECT + 1)
86#define LAST_DOUBLY_INDIRECT     \
87   (LAST_INDIRECT + \
88     (IMFS_MEMFILE_BLOCK_SLOTS * IMFS_MEMFILE_BLOCK_SLOTS))
89
90#define FIRST_TRIPLY_INDIRECT    (LAST_DOUBLY_INDIRECT + 1)
91#define LAST_TRIPLY_INDIRECT \
92   (LAST_DOUBLY_INDIRECT +\
93     (IMFS_MEMFILE_BLOCK_SLOTS * \
94        IMFS_MEMFILE_BLOCK_SLOTS * IMFS_MEMFILE_BLOCK_SLOTS))
95
96#define IMFS_MEMFILE_MAXIMUM_SIZE \
97  (LAST_TRIPLY_INDIRECT * IMFS_MEMFILE_BYTES_PER_BLOCK)
98
99/** @} */
100
101/**
102 * @addtogroup IMFSGenericNodes
103 */
104/**@{*/
105
106/**
107 * @brief Initializes an IMFS node.
108 *
109 * @param[in] node The IMFS node.
110 * @param[in] arg The user provided argument pointer.  It may contain node
111 *   specific initialization information.
112 *
113 * @retval node Successful operation.
114 * @retval NULL An error occurred.  The @c errno indicates the error.  This
115 * will abort the make operation.
116 *
117 * @see IMFS_node_control, IMFS_node_initialize_default(), and
118 * IMFS_node_initialize_generic().
119 */
120typedef IMFS_jnode_t *(*IMFS_node_control_initialize)(
121  IMFS_jnode_t *node,
122  void *arg
123);
124
125/**
126 * @brief Returns the node and does nothing else.
127 *
128 * @param[in] node The IMFS node.
129 * @param[in] arg The user provided argument pointer.  It is not used.
130 *
131 * @retval node Returns always the node passed as parameter.
132 *
133 * @see IMFS_node_control.
134 */
135IMFS_jnode_t *IMFS_node_initialize_default(
136  IMFS_jnode_t *node,
137  void *arg
138);
139
140IMFS_jnode_t *IMFS_node_initialize_directory(
141  IMFS_jnode_t *node,
142  void *arg
143);
144
145/**
146 * @brief Returns the node and sets the generic node context.
147 *
148 * @param[in] node The IMFS node.
149 * @param[in] arg The user provided argument pointer.  It must contain the
150 *   generic context.
151 *
152 * @retval node Returns always the node passed as parameter.
153 *
154 * @see IMFS_node_control.
155 */
156IMFS_jnode_t *IMFS_node_initialize_generic(
157  IMFS_jnode_t *node,
158  void *arg
159);
160
161/**
162 * @brief Prepares the removal of an IMFS node from its parent directory.
163 *
164 * @param[in] node The IMFS node.
165 *
166 * @retval node Successful operation.
167 * @retval NULL An error occurred.  The @c errno indicates the error.  This
168 * will abort the removal operation.
169 *
170 * @see IMFS_node_control and IMFS_node_remove_default().
171 */
172typedef IMFS_jnode_t *(*IMFS_node_control_remove)(
173  IMFS_jnode_t *node
174);
175
176/**
177 * @brief Returns the node and does nothing else.
178 *
179 * @param[in] node The IMFS node.
180 *
181 * @retval node Returns always the node passed as parameter.
182 *
183 * @see IMFS_node_control.
184 */
185IMFS_jnode_t *IMFS_node_remove_default(
186  IMFS_jnode_t *node
187);
188
189IMFS_jnode_t *IMFS_node_remove_directory( IMFS_jnode_t *node );
190
191/**
192 * @brief Destroys an IMFS node.
193 *
194 * @param[in] node The IMFS node.
195 *
196 * @see IMFS_node_control and IMFS_node_destroy_default().
197 */
198typedef void (*IMFS_node_control_destroy)( IMFS_jnode_t *node );
199
200/**
201 * @brief Frees the node.
202 *
203 * @param[in] node The IMFS node.
204 *
205 * @see IMFS_node_control.
206 */
207void IMFS_node_destroy_default( IMFS_jnode_t *node );
208
209/**
210 * @brief IMFS node control.
211 */
212typedef struct {
213  const rtems_filesystem_file_handlers_r *handlers;
214  IMFS_node_control_initialize node_initialize;
215  IMFS_node_control_remove node_remove;
216  IMFS_node_control_destroy node_destroy;
217} IMFS_node_control;
218
219typedef struct {
220  IMFS_node_control node_control;
221  size_t node_size;
222} IMFS_mknod_control;
223
224/** @} */
225
226/**
227 * @addtogroup IMFS
228 */
229/**@{*/
230
231/*
232 *  Maximum length of a "basename" of an IMFS file/node.
233 */
234
235#define IMFS_NAME_MAX _POSIX_NAME_MAX
236
237/*
238
239 *  The control structure for an IMFS jnode.
240 */
241
242struct IMFS_jnode_tt {
243  rtems_chain_node    Node;                  /* for chaining them together */
244  IMFS_jnode_t       *Parent;                /* Parent node */
245  const char         *name;                  /* "basename" (not \0 terminated) */
246  uint16_t            namelen;               /* Length of "basename" */
247  uint16_t            flags;                 /* Node flags */
248  mode_t              st_mode;               /* File mode */
249  unsigned short      reference_count;
250  nlink_t             st_nlink;              /* Link count */
251
252  uid_t               st_uid;                /* User ID of owner */
253  gid_t               st_gid;                /* Group ID of owner */
254
255  time_t              stat_atime;            /* Time of last access */
256  time_t              stat_mtime;            /* Time of last modification */
257  time_t              stat_ctime;            /* Time of last status change */
258  const IMFS_node_control *control;
259};
260
261#define IMFS_NODE_FLAG_NAME_ALLOCATED 0x1
262
263typedef struct {
264  IMFS_jnode_t                          Node;
265  rtems_chain_control                   Entries;
266  rtems_filesystem_mount_table_entry_t *mt_fs;
267} IMFS_directory_t;
268
269typedef struct {
270  IMFS_jnode_t              Node;
271  rtems_device_major_number major;
272  rtems_device_minor_number minor;
273} IMFS_device_t;
274
275typedef struct {
276  IMFS_jnode_t  Node;
277  IMFS_jnode_t *link_node;
278} IMFS_link_t;
279
280typedef struct {
281  IMFS_jnode_t  Node;
282  char         *name;
283} IMFS_sym_link_t;
284
285typedef struct {
286  IMFS_jnode_t Node;
287  size_t       size;             /* size of file in bytes */
288} IMFS_filebase_t;
289
290typedef struct {
291  IMFS_filebase_t File;
292  block_ptr       indirect;         /* array of 128 data blocks pointers */
293  block_ptr       doubly_indirect;  /* 128 indirect blocks */
294  block_ptr       triply_indirect;  /* 128 doubly indirect blocks */
295} IMFS_memfile_t;
296
297typedef struct {
298  IMFS_filebase_t File;
299  block_p         direct;           /* pointer to file image */
300} IMFS_linearfile_t;
301
302/* Support copy on write for linear files */
303typedef union {
304  IMFS_jnode_t      Node;
305  IMFS_filebase_t   File;
306  IMFS_memfile_t    Memfile;
307  IMFS_linearfile_t Linearfile;
308} IMFS_file_t;
309
310typedef struct {
311  IMFS_jnode_t    Node;
312  pipe_control_t *pipe;
313} IMFS_fifo_t;
314
315typedef struct {
316  IMFS_jnode_t  Node;
317  void         *context;
318} IMFS_generic_t;
319
320static inline IMFS_directory_t *IMFS_iop_to_directory(
321  const rtems_libio_t *iop
322)
323{
324  return (IMFS_directory_t *) iop->pathinfo.node_access;
325}
326
327static inline IMFS_device_t *IMFS_iop_to_device( const rtems_libio_t *iop )
328{
329  return (IMFS_device_t *) iop->pathinfo.node_access;
330}
331
332static inline IMFS_file_t *IMFS_iop_to_file( const rtems_libio_t *iop )
333{
334  return (IMFS_file_t *) iop->pathinfo.node_access;
335}
336
337static inline IMFS_memfile_t *IMFS_iop_to_memfile( const rtems_libio_t *iop )
338{
339  return (IMFS_memfile_t *) iop->pathinfo.node_access;
340}
341
342static inline time_t _IMFS_get_time( void )
343{
344  struct bintime now;
345
346  /* Use most efficient way to get the time in seconds (CLOCK_REALTIME) */
347  _Timecounter_Getbintime( &now );
348
349  return now.sec;
350}
351
352static inline void IMFS_update_atime( IMFS_jnode_t *jnode )
353{
354  jnode->stat_atime = _IMFS_get_time();
355}
356
357static inline void IMFS_update_mtime( IMFS_jnode_t *jnode )
358{
359  jnode->stat_mtime = _IMFS_get_time();
360}
361
362static inline void IMFS_update_ctime( IMFS_jnode_t *jnode )
363{
364  jnode->stat_ctime = _IMFS_get_time();
365}
366
367static inline void IMFS_mtime_ctime_update( IMFS_jnode_t *jnode )
368{
369  time_t now;
370
371  now = _IMFS_get_time();
372
373  jnode->stat_mtime = now;
374  jnode->stat_ctime = now;
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.