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

4.115
Last change on this file since e354eb4f was e354eb4f, checked in by Alex Ivanov <alexivanov97@…>, on 01/08/13 at 14:02:58

libfs: Doxygen Clean Up Task #1

http://www.google-melange.com/gci/task/view/google/gci2012/8120204

Patch committed with fixes for whitespace issues.

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