source: rtems-docs/filesystem/filesystem.rst @ 9e27b86

4.115
Last change on this file since 9e27b86 was 5daabd2, checked in by Amar Takhar <amar@…>, on 01/16/16 at 04:41:06

Initial reST documentation using Sphinx.

  • Property mode set to 100644
File size: 108.9 KB
Line 
1:orphan:
2
3
4
5.. COMMENT: %**end of header
6
7.. COMMENT: COPYRIGHT (c) 1989-2013.
8
9.. COMMENT: On-Line Applications Research Corporation (OAR).
10
11.. COMMENT: All rights reserved.
12
13.. COMMENT: Master file for the Filesystem Design Guide
14
15.. COMMENT: COPYRIGHT (c) 1988-2002.
16
17.. COMMENT: On-Line Applications Research Corporation (OAR).
18
19.. COMMENT: All rights reserved.
20
21.. COMMENT: The following determines which set of the tables and figures we will use.
22
23.. COMMENT: We default to ASCII but if available TeX or HTML versions will
24
25.. COMMENT: be used instead.
26
27.. COMMENT: @clear use-html
28
29.. COMMENT: @clear use-tex
30
31.. COMMENT: The following variable says to use texinfo or html for the two column
32
33.. COMMENT: texinfo tables.  For somethings the format does not look good in html.
34
35.. COMMENT: With our adjustment to the left column in TeX, it nearly always looks
36
37.. COMMENT: good printed.
38
39.. COMMENT: Custom whitespace adjustments.  We could fiddle a bit more.
40
41.. COMMENT: Title Page Stuff
42
43.. COMMENT: I don't really like having a short title page.  -joel
44
45.. COMMENT: @shorttitlepage RTEMS Filesystem Design Guide
46
47=============================
48RTEMS Filesystem Design Guide
49=============================
50
51.. COMMENT: COPYRIGHT (c) 1988-2015.
52
53.. COMMENT: On-Line Applications Research Corporation (OAR).
54
55.. COMMENT: All rights reserved.
56
57.. COMMENT: The following puts a space somewhere on an otherwise empty page so we
58
59.. COMMENT: can force the copyright description onto a left hand page.
60
61COPYRIGHT © 1988 - 2015.
62
63On-Line Applications Research Corporation (OAR).
64
65The authors have used their best efforts in preparing
66this material.  These efforts include the development, research,
67and testing of the theories and programs to determine their
68effectiveness.  No warranty of any kind, expressed or implied,
69with regard to the software or the material contained in this
70document is provided.  No liability arising out of the
71application or use of any product described in this document is
72assumed.  The authors reserve the right to revise this material
73and to make changes from time to time in the content hereof
74without obligation to notify anyone of such revision or changes.
75
76The RTEMS Project is hosted at http://www.rtems.org.  Any
77inquiries concerning RTEMS, its related support components, or its
78documentation should be directed to the Community Project hosted athttp://www.rtems.org.
79
80Any inquiries for commercial services including training, support, custom
81development, application development assistance should be directed tohttp://www.rtems.com.
82
83.. COMMENT: This prevents a black box from being printed on "overflow" lines.
84
85.. COMMENT: The alternative is to rework a sentence to avoid this problem.
86
87RTEMS Filesystem Design Guide
88#############################
89
90.. COMMENT: COPYRIGHT (c) 1989-2011.
91
92.. COMMENT: On-Line Applications Research Corporation (OAR).
93
94.. COMMENT: All rights reserved.
95
96Preface
97#######
98
99This document describes the implementation of the RTEMS filesystem
100infrastructure.  This infrastructure supports the following
101capabilities:
102
103- Mountable file systems
104
105- Hierarchical file system directory structure
106
107- POSIX compliant set of routines for the manipulation of files and directories
108
109- Individual file and directory support for the following:
110  # Permissions for read, write and execute
111  # User ID
112  # Group ID
113  # Access time
114  # Modification time
115  # Creation time
116
117- Hard links to files and directories
118
119- Symbolic links to files and directories
120
121This has been implemented to provide the framework for a UNIX-like
122file system support. POSIX file and directory functions have been
123implemented that allow a standard method of accessing file, device and
124directory information within file systems. The file system concept that
125has been implemented allows for expansion and adaptation of the file
126system to a variety of existing and future data storage devices. To this
127end, file system mount and unmount capabilities have been included in this
128RTEMS framework.
129
130This framework slightly alters the manner in which devices are handled
131under RTEMS from that of public release 4.0.0 and earlier.  Devices that
132are defined under a given RTEMS configuration will now be registered as
133files in a mounted file system.  Access to these device drivers and their
134associated devices may now be performed through the traditional file system
135open(), read(), write(), lseek(), fstat() and ioctl() functions in addition
136to the interface provided by the IO Manager in the RTEMS Classic API.
137
138An In-Memory File System (IMFS) is included which provides full POSIX
139filesystem functionality yet is RAM based.  The IMFS maintains a
140node structure for each file, device, and directory in each mounted
141instantiation of its file system. The node structure is used to
142manage ownership, access rights, access time, modification time,
143and creation time.  A union of structures within the IMFS nodal
144structure provide for manipulation of file data, device selection,
145or directory content as required by the nodal type. Manipulation of
146these properties is accomplished through the POSIX set of file and
147directory functions.  In addition to being useful in its own right,
148the IMFS serves as a full featured example filesystem.
149
150The intended audience for this document is those persons implementing
151their own filesystem.  Users of the filesystem may find information
152on the implementation useful.  But the user interface to the filesystem
153is through the ISO/ANSI C Library and POSIX 1003.1b file and directory
154APIs.
155
156.. COMMENT: COPYRIGHT (c) 1988-2002.
157
158.. COMMENT: On-Line Applications Research Corporation (OAR).
159
160.. COMMENT: All rights reserved.
161
162Pathname Evaluation
163###################
164
165This chapter describes the pathname evaluation process for the
166RTEMS Filesystem Infrastructure.
167.. code:: c
168
169    XXX Include graphic of the path evaluation process
170
171Pathname Evaluation Handlers
172============================
173
174There are two pathname evaluation routines.  The handler patheval()
175is called to find, verify privlages on and return information on a node
176that exists.  The handler evalformake() is called to find, verify
177permissions, and return information on a node that is to become a parent.
178Additionally, evalformake() returns a pointer to the start of the name of
179the new node to be created.
180
181Pathname evaluation is specific to a filesystem.
182Each filesystem is required to provide both a patheval() and an evalformake()
183routine.  Both of these routines gets a name to evaluate and a node indicating
184where to start the evaluation.
185
186Crossing a Mount Point During Path Evaluation
187=============================================
188
189If the filesystem supports the mount command, the evaluate routines
190must handle crossing the mountpoint.  The evaluate routine should evaluate
191the name upto the first directory node where the new filesystem is mounted.
192The filesystem may process terminator characters prior to calling the
193evaluate routine for the new filesystem.   A pointer to the portion of the
194name which has not been evaluated along with the root node of the new
195file system ( gotten from the mount table entry ) is passed to the correct
196mounted filesystem evaluate routine.
197
198The rtems_filesystem_location_info_t Structure
199==============================================
200
201The ``rtems_filesystem_location_info_t`` structure contains all information
202necessary for identification of a node.
203
204The generic rtems filesystem code defines two global
205rtems_filesystem_location_info_t structures, the``rtems_filesystem_root`` and the ``rtems_filesystem_current``.
206Both are initially defined to be the root node of the base filesystem.
207Once the chdir command is correctly used the ``rtems_filesystem_current``
208is set to the location specified by the command.
209
210The filesystem generic code peeks at the first character in the name to be
211evaluated.  If this character is a valid seperator, the``rtems_filesystem_root`` is used as the node to start the evaluation
212with.  Otherwise, the ``rtems_filesystem_current`` node is used as the
213node to start evaluating with.  Therefore, a valid
214rtems_filesystem_location_info_t is given to the evaluate routine to start
215evaluation with.  The evaluate routines are then responsible for making
216any changes necessary to this structure to correspond to the name being
217parsed.
218.. code:: c
219
220    struct rtems_filesystem_location_info_tt {
221    void                                     \*node_access;
222    rtems_filesystem_file_handlers_r         \*handlers;
223    rtems_filesystem_operations_table        \*ops;
224    rtems_filesystem_mount_table_entry_t     \*mt_entry;
225    };
226
227*node_access*
228    This element is filesystem specific.  A filesystem can define and store
229    any information necessary to identify a node at this location.  This element
230    is normally filled in by the filesystem’s evaluate routine. For the
231    filesystem’s root node, the filesystem’s initilization routine should
232    fill this in, and it should remain valid until the instance of the
233    filesystem is unmounted.
234
235*handlers*
236    This element is defined as a set of routines that may change within a
237    given filesystem based upon node type.  For example a directory and a
238    memory file may have to completely different read routines.  This element
239    is set to an initialization state defined by the mount table, and may
240    be set to the desired state by the evaluation routines.
241
242*ops*
243    This element is defined as a set of routines that remain static for the
244    filesystem.  This element identifies entry points into the filesystem
245    to the generic code.
246
247*mt_entry*
248    This element identifies the mount table entry for this instance of the
249    filesystem.
250
251.. COMMENT: COPYRIGHT (c) 1988-2002.
252
253.. COMMENT: On-Line Applications Research Corporation (OAR).
254
255.. COMMENT: All rights reserved.
256
257System Initialization
258#####################
259
260After the RTEMS initialization is performed, the application’s
261initialization will be performed. Part of initialization is a call to
262rtems_filesystem_initialize(). This routine will mount the ‘In Memory File
263System’ as the base filesystem.  Mounting the base filesystem consists
264of the following:
265
266- Initialization of mount table chain control structure
267
268- Allocation of a ``jnode`` structure that will server as the root node
269  of the ‘In Memory Filesystem’
270
271- Initialization of the allocated ``jnode`` with the appropriate OPS,
272  directory handlers and pathconf limits and options.
273
274- Allocation of a memory region for filesystem specific global
275  management variables
276
277- Creation of first mount table entry for the base filesystem
278
279- Initialization of the first mount table chain entry to indicate that
280  the mount point is NULL and the mounted filesystem is the base file
281  system
282
283After the base filesystem has been mounted, the following operations are
284performed under its directory structure:
285
286- Creation of the /dev directory
287
288- Registration of devices under /dev directory
289
290Base Filesystem
291===============
292
293RTEMS initially mounts a RAM based file system known as the base file system.
294The root directory of this file system tree serves as the logical root of the
295directory hierarchy (Figure 3). Under the root directory a ‘/dev’ directory
296is created under which all I/O device directories and files are registered as
297part of the file system hierarchy.
298.. code:: c
299
300    Figure of the tree structure goes here.
301
302A RAM based file system draws its management resources from memory. File and
303directory nodes are simply allocated blocks of memory. Data associated with
304regular files is stored in collections of memory blocks. When the system is
305turned off or restarted all memory-based components of the file system are
306lost.
307
308The base file system serves as a starting point for the mounting of file
309systems that are resident on semi-permanent storage media. Examples of such
310media include non- volatile memory, flash memory and IDE hard disk drives
311(Figure 3). File systems of other types will be mounted onto mount points
312within the base file system or other file systems that are subordinate to the
313base file system. The framework set up under the base file system will allow
314for these new file system types and the unique data and functionality that is
315required to manage the future file systems.
316
317Base Filesystem Mounting
318------------------------
319
320At present, the first file system to be mounted is the ‘In Memory File
321System’. It is mounted using a standard MOUNT() command in which the mount
322point is NULL.  This flags the mount as the first file system to be
323registered under the operating system and appropriate initialization of file
324system management information is performed (See figures 4 and 5). If a
325different file system type is desired as the base file system, alterations
326must be made to base_fs.c. This routine handles the mount of the base file
327system.
328
329.. code:: c
330
331    Figure of the mount table chain goes here.
332
333Once the root of the base file system has been established and it has been
334recorded as the mount point of the base file system, devices are integrated
335into the base file system. For every device that is configured into the
336system (See ioman.c) a device registration process is performed. Device
337registration produces a unique dev_t handle that consists of a major and
338minor device number. In addition, the configuration information for each
339device contains a text string that represents the fully qualified pathname to
340that device’s place in the base file system’s hierarchy. A file system node
341is created for the device along the specified registration path.
342
343.. code:: c
344
345    Figure  of the Mount Table Processing goes here.
346
347Note: Other file systems can be mounted but they are mounted onto points
348(directory mount points) in the base file system.
349
350.. COMMENT: COPYRIGHT (c) 1988-2002.
351
352.. COMMENT: On-Line Applications Research Corporation (OAR).
353
354.. COMMENT: All rights reserved.
355
356Mounting and Unmounting Filesystems
357###################################
358
359Mount Points
360============
361
362The following is the list of the characteristics of a mount point:
363
364- The mount point must be a directory. It may have files and other
365  directories under it. These files and directories will be hidden when the
366  filesystem is mounted.
367
368- The task must have read/write/execute permissions to the mount point
369  or the mount attempt will be rejected.
370
371- Only one filesystem can be mounted to a single mount point.
372
373- The Root of the mountable filesystem will be referenced by the name
374  of the mount point after the mount is complete.
375
376Mount Table Chain
377=================
378
379The mount table chain is a dynamic list of structures that describe
380mounted filesystems a specific points in the filesystem hierarchy. It is
381initialized to an empty state during the base filesystem initialization.
382The mount operation will add entries to the mount table chain. The
383un-mount operation will remove entries from the mount table chain.
384
385Each entry in the mount table chain is of the following type:
386.. code:: c
387
388    struct rtems_filesystem_mount_table_entry_tt
389    {
390    Chain_Node                             Node;
391    rtems_filesystem_location_info_t       mt_point_node;
392    rtems_filesystem_location_info_t       mt_fs_root;
393    int                                    options;
394    void                                  \*fs_info;
395    rtems_filesystem_limits_and_options_t  pathconf_limits_and_options;
396    /*
397    *  When someone adds a mounted filesystem on a real device,
398    *  this will need to be used.
399    *
400    *  The best option long term for this is probably an
401    *  open file descriptor.
402    \*/
403    char                                  \*dev;
404    };
405
406*Node*
407    The Node is used to produce a linked list of mount table entry nodes.
408
409*mt_point_node*
410    The mt_point_node contains all information necessary to access the
411    directory where a filesystem is mounted onto.  This element may contain
412    memory that is allocated during a path evaluation of the filesystem
413    containing the mountpoint directory.  The generic code allows this
414    memory to be returned by unmount when the filesystem identified by
415    mt_fs_root is unmounted.
416
417*mt_fs_root*
418    The mt_fs_root contains all information necessary to identify the root
419    of the mounted filesystem. The user is never allowed access to this
420    node by the generic code, but it is used to identify to the mounted
421    filesystem where to start evaluation of pathnames at.
422
423*options*
424    XXX
425
426*fs_info*
427    The fs_info element is a location available for use by the mounted file
428    system to identify unique things applicable to this instance of the file
429    system.  For example the IMFS uses this space to provide node
430    identification that is unique for each instance (mounting) of the filesystem.
431
432*pathconf_limits_and_options*
433    XXX
434
435*dev*
436    This character string represents the device where the filesystem will reside.
437
438Adding entries to the chain during mount
439========================================
440
441When a filesystem is mounted, its presence and location in the file
442system hierarchy is recorded in a dynamic list structure known as a chain.
443A unique rtems_filesystem_mount_table_entry_tt structure is logged for
444each filesystem that is mounted. This includes the base filesystem.
445
446Removing entries from the chain during unmount
447==============================================
448
449When a filesystem is dismounted its entry in the mount table chain is
450extracted and the memory for this entry is freed.
451
452.. COMMENT: COPYRIGHT (c) 1988-2002.
453
454.. COMMENT: On-Line Applications Research Corporation (OAR).
455
456.. COMMENT: All rights reserved.
457
458System Call Development Notes
459#############################
460
461This set of routines represents the application’s interface to files and directories
462under the RTEMS filesystem. All routines are compliant with POSIX standards if a
463specific interface has been established. The list below represents the routines that have
464been included as part of the application’s interface.
465
466# access()
467
468# chdir()
469
470# chmod()
471
472# chown()
473
474# close()
475
476# closedir()
477
478# dup()
479
480# dup2()
481
482# fchmod()
483
484# fcntl()
485
486# fdatasync()
487
488# fpathconf()
489
490# fstat()
491
492# ioctl()
493
494# link()
495
496# lseek()
497
498# mkdir()
499
500# mkfifo()
501
502# mknod()
503
504# mount()
505
506# open()
507
508# opendir()
509
510# pathconf()
511
512# read()
513
514# readdir()
515
516# unmount()
517
518The sections that follow provide developmental information concerning each
519of these functions.
520
521.. COMMENT: @page
522
523access
524======
525
526**File:**
527
528access.c
529
530**Processing:**
531
532This routine is layered on the stat() function. It acquires the current
533status information for the specified file and then determines if the
534caller has the ability to access the file for read, write or execute
535according to the mode argument to this function.
536
537**Development Comments:**
538
539This routine is layered on top of the stat() function. As long as the
540st_mode element in the returned structure follow the standard UNIX
541conventions, this function should support other filesystems without
542alteration.
543
544.. COMMENT: @page
545
546chdir
547=====
548
549**File:**
550
551chdir.c
552
553**Processing:**
554
555This routine will determine if the pathname that we are attempting to make
556that current directory exists and is in fact a directory. If these
557conditions are met the global indication of the current directory
558(rtems_filesystem_current) is set to the rtems_filesystem_location_info_t
559structure that is returned by the rtems_filesystem_evaluate_path()
560routine.
561
562**Development Comments:**
563
564This routine is layered on the rtems_filesystem_evaluate_path() routine
565and the filesystem specific OP table function node_type().
566
567The routine node_type() must be a routine provided for each filesystem
568since it must access the filesystems node information to determine which
569of the following types the node is:
570
571- RTEMS_FILESYSTEM_DIRECTORY
572
573- RTEMS_FILESYSTEM_DEVICE
574
575- RTEMS_FILESYSTEM_HARD_LINK
576
577- RTEMS_FILESYSTEM_MEMORY_FILE
578
579This acknowledges that the form of the node management information can
580vary from one filesystem implementation to another.
581
582RTEMS has a special global structure that maintains the current directory
583location. This global variable is of type rtems_filesystem_location_info_t
584and is called rtems_filesystem_current. This structure is not always
585valid. In order to determine if the structure is valid, you must first
586test the node_access element of this structure. If the pointer is NULL,
587then the structure does not contain a valid indication of what the current
588directory is.
589
590.. COMMENT: @page
591
592chmod
593=====
594
595**File:**
596
597chmod.c
598
599**Processing:**
600
601This routine is layered on the open(), fchmod() and close() functions. As
602long as the standard interpretation of the mode_t value is maintained,
603this routine should not need modification to support other filesystems.
604
605**Development Comments:**
606
607The routine first determines if the selected file can be open with
608read/write access.  This is required to allow modification of the mode
609associated with the selected path.
610
611The fchmod() function is used to actually change the mode of the path
612using the integer file descriptor returned by the open() function.
613
614After mode modification, the open file descriptor is closed.
615
616.. COMMENT: @page
617
618chown
619=====
620
621**File:**
622
623chown.c
624
625**Processing:**
626
627This routine is layered on the rtems_filesystem_evaluate_path() and the
628file system specific chown() routine that is specified in the OPS table
629for the file system.
630
631**Development Comments:**
632
633rtems_filesystem_evaluate_path() is used to determine if the path
634specified actually exists. If it does a rtems_filesystem_location_info_t
635structure will be obtained that allows the shell function to locate the
636OPS table that is to be used for this filesystem.
637
638It is possible that the chown() function that should be in the OPS table
639is not defined. A test for a non-NULL OPS table chown() entry is performed
640before the function is called.
641
642If the chown() function is defined in the indicated OPS table, the
643function is called with the rtems_filesystem_location_info_t structure
644returned from the path evaluation routine, the desired owner, and group
645information.
646
647.. COMMENT: @page
648
649close
650=====
651
652**File:**
653
654close.c
655
656**Processing:**
657
658This routine will allow for the closing of both network connections and
659file system devices. If the file descriptor is associated with a network
660device, the appropriate network function handler will be selected from a
661table of previously registered network functions (rtems_libio_handlers)
662and that function will be invoked.
663
664If the file descriptor refers to an entry in the filesystem, the
665appropriate handler will be selected using information that has been
666placed in the file control block for the device (rtems_libio_t structure).
667
668**Development Comments:**
669
670rtems_file_descriptor_type examines some of the upper bits of the file
671descriptor index. If it finds that the upper bits are set in the file
672descriptor index, the device referenced is a network device.
673
674Network device handlers are obtained from a special registration table
675(rtems_libio_handlers) that is set up during network initialization. The
676network handler invoked and the status of the network handler will be
677returned to the calling process.
678
679If none of the upper bits are set in the file descriptor index, the file
680descriptor refers to an element of the RTEMS filesystem.
681
682The following sequence will be performed for any filesystem file
683descriptor:
684
685# Use the rtems_libio_iop() function to obtain the rtems_libio_t
686  structure for the file descriptor
687
688# Range check the file descriptor using rtems_libio_check_fd()
689
690# Determine if there is actually a function in the selected handler
691  table that processes the close() operation for the filesystem and node
692  type selected.  This is generally done to avoid execution attempts on
693  functions that have not been implemented.
694
695# If the function has been defined it is invoked with the file control
696  block pointer as its argument.
697
698# The file control block that was associated with the open file
699  descriptor is marked as free using rtems_libio_free().
700
701# The return code from the close handler is then passed back to the
702  calling program.
703
704.. COMMENT: @page
705
706closedir
707========
708
709**File:**
710
711closedir.c
712
713**Processing:**
714
715The code was obtained from the BSD group. This routine must clean up the
716memory resources that are required to track an open directory. The code is
717layered on the close() function and standard memory free() functions. It
718should not require alterations to support other filesystems.
719
720**Development Comments:**
721
722The routine alters the file descriptor and the index into the DIR
723structure to make it an invalid file descriptor. Apparently the memory
724that is about to be freed may still be referenced before it is
725reallocated.
726
727The dd_buf structure’s memory is reallocated before the control structure
728that contains the pointer to the dd_buf region.
729
730DIR control memory is reallocated.
731
732The close() function is used to free the file descriptor index.
733
734.. COMMENT: @page
735
736dup()      Unimplemented
737========================
738
739**File:**
740
741dup.c
742
743**Processing:**
744
745**Development Comments:**
746
747.. COMMENT: @page
748
749dup2()      Unimplemented
750=========================
751
752**File:**
753
754dup2.c
755
756**Processing:**
757
758**Development Comments:**
759
760.. COMMENT: @page
761
762fchmod
763======
764
765**File:**
766
767fchmod.c
768
769**Processing:**
770
771This routine will alter the permissions of a node in a filesystem. It is
772layered on the following functions and macros:
773
774- rtems_file_descriptor_type()
775
776- rtems_libio_iop()
777
778- rtems_libio_check_fd()
779
780- rtems_libio_check_permissions()
781
782- fchmod() function that is referenced by the handler table in the
783  file control block associated with this file descriptor
784
785**Development Comments:**
786
787The routine will test to see if the file descriptor index is associated
788with a network connection. If it is, an error is returned from this
789routine.
790
791The file descriptor index is used to obtain the associated file control
792block.
793
794The file descriptor value is range checked.
795
796The file control block is examined to determine if it has write
797permissions to allow us to alter the mode of the file.
798
799A test is made to determine if the handler table that is referenced in the
800file control block contains an entry for the fchmod() handler function. If
801it does not, an error is returned to the calling routine.
802
803If the fchmod() handler function exists, it is called with the file
804control block and the desired mode as parameters.
805
806.. COMMENT: @page
807
808fcntl()
809=======
810
811**File:**
812
813fcntl.c
814
815**Processing:**
816
817This routine currently only interacts with the file control block. If the
818structure of the file control block and the associated meanings do not
819change, the partial implementation of fcntl() should remain unaltered for
820other filesystem implementations.
821
822**Development Comments:**
823
824The only commands that have been implemented are the F_GETFD and F_SETFD.
825The commands manipulate the LIBIO_FLAGS_CLOSE_ON_EXEC bit in the``flags`` element of the file control block associated with the file
826descriptor index.
827
828The current implementation of the function performs the sequence of
829operations below:
830
831# Test to see if we are trying to operate on a file descriptor
832  associated with a network connection
833
834# Obtain the file control block that is associated with the file
835  descriptor index
836
837# Perform a range check on the file descriptor index.
838
839.. COMMENT: @page
840
841fdatasync
842=========
843
844**File:**
845
846fdatasync.c
847
848**Processing:**
849
850This routine is a template in the in memory filesystem that will route us to the
851appropriate handler function to carry out the fdatasync() processing. In the in
852memory filesystem this function is not necessary. Its function in a disk based file
853system that employs a memory cache is to flush all memory based data buffers to
854disk. It is layered on the following functions and macros:
855
856- rtems_file_descriptor_type()
857
858- rtems_libio_iop()
859
860- rtems_libio_check_fd()
861
862- rtems_libio_check_permissions()
863
864- fdatasync() function that is referenced by the handler table in the
865  file control block associated with this file descriptor
866
867**Development Comments:**
868
869The routine will test to see if the file descriptor index is associated
870with a network connection. If it is, an error is returned from this
871routine.
872
873The file descriptor index is used to obtain the associated file control
874block.
875
876The file descriptor value is range checked.
877
878The file control block is examined to determine if it has write
879permissions to the file.
880
881A test is made to determine if the handler table that is referenced in the
882file control block contains an entry for the fdatasync() handler function.
883If it does not an error is returned to the calling routine.
884
885If the fdatasync() handler function exists, it is called with the file
886control block as its parameter.
887
888.. COMMENT: @page
889
890fpathconf
891=========
892
893**File:**
894
895fpathconf.c
896
897**Processing:**
898
899This routine is layered on the following functions and macros:
900
901- rtems_file_descriptor_type()
902
903- rtems_libio_iop()
904
905- rtems_libio_check_fd()
906
907- rtems_libio_check_permissions()
908
909When a filesystem is mounted, a set of constants is specified for the
910filesystem.  These constants are stored with the mount table entry for the
911filesystem. These constants appear in the POSIX standard and are listed
912below.
913
914- PCLINKMAX
915
916- PCMAXCANON
917
918- PCMAXINPUT
919
920- PCNAMEMAX
921
922- PCPATHMAX
923
924- PCPIPEBUF
925
926- PCCHOWNRESTRICTED
927
928- PCNOTRUNC
929
930- PCVDISABLE
931
932- PCASYNCIO
933
934- PCPRIOIO
935
936- PCSYNCIO
937
938This routine will find the mount table information associated the file
939control block for the specified file descriptor parameter. The mount table
940entry structure contains a set of filesystem specific constants that can
941be accessed by individual identifiers.
942
943**Development Comments:**
944
945The routine will test to see if the file descriptor index is associated
946with a network connection. If it is, an error is returned from this
947routine.
948
949The file descriptor index is used to obtain the associated file control
950block.
951
952The file descriptor value is range checked.
953
954The file control block is examined to determine if it has read permissions
955to the file.
956
957Pathinfo in the file control block is used to locate the mount table entry
958for the filesystem associated with the file descriptor.
959
960The mount table entry contains the pathconf_limits_and_options element.
961This element is a table of constants that is associated with the
962filesystem.
963
964The name argument is used to reference the desired constant from the
965pathconf_limits_and_options table.
966
967.. COMMENT: @page
968
969fstat
970=====
971
972**File:**
973
974fstat.c
975
976**Processing:**
977
978This routine will return information concerning a file or network
979connection. If the file descriptor is associated with a network
980connection, the current implementation of ``fstat()`` will return a
981mode set to ``S_IFSOCK``. In a later version, this routine will map the
982status of a network connection to an external handler routine.
983
984If the file descriptor is associated with a node under a filesystem, the
985fstat()  routine will map to the fstat() function taken from the node
986handler table.
987
988**Development Comments:**
989
990This routine validates that the struct stat pointer is not NULL so that
991the return location is valid.
992
993The struct stat is then initialized to all zeros.
994
995rtems_file_descriptor_type() is then used to determine if the file
996descriptor is associated with a network connection. If it is, network
997status processing is performed. In the current implementation, the file
998descriptor type processing needs to be improved. It currently just drops
999into the normal processing for file system nodes.
1000
1001If the file descriptor is associated with a node under a filesystem, the
1002following steps are performed:
1003
1004# Obtain the file control block that is associated with the file descriptor
1005  index.
1006
1007# Range check the file descriptor index.
1008
1009# Test to see if there is a non-NULL function pointer in the handler
1010  table for the fstat() function. If there is, invoke the function with the
1011  file control block and the pointer to the stat structure.
1012
1013.. COMMENT: @page
1014
1015ioctl
1016=====
1017
1018**File:**
1019
1020ioctl.c
1021
1022**Processing:**
1023
1024Not defined in the POSIX 1003.1b standard but commonly supported in most
1025UNIX and POSIX system. Ioctl() is a catchall for I/O operations. Routine
1026is layered on external network handlers and filesystem specific handlers.
1027The development of new filesystems should not alter the basic processing
1028performed by this routine.
1029
1030**Development Comments:**
1031
1032The file descriptor is examined to determine if it is associated with a
1033network device. If it is processing is mapped to an external network
1034handler. The value returned by this handler is then returned to the
1035calling program.
1036
1037File descriptors that are associated with a filesystem undergo the
1038following processing:
1039
1040# The file descriptor index is used to obtain the associated file
1041  control block.
1042
1043# The file descriptor value is range checked.
1044
1045# A test is made to determine if the handler table that is referenced
1046  in the file control block contains an entry for the ioctl() handler
1047  function. If it does not, an error is returned to the calling routine.
1048
1049# If the ioctl() handler function exists, it is called with the file
1050  control block, the command and buffer as its parameters.
1051
1052# The return code from this function is then sent to the calling
1053  routine.
1054
1055.. COMMENT: @page
1056
1057link
1058====
1059
1060**File:**
1061
1062link.c
1063
1064**Processing:**
1065
1066This routine will establish a hard link to a file, directory or a device.
1067The target of the hard link must be in the same filesystem as the new link
1068being created. A link to an existing link is also permitted but the
1069existing link is evaluated before the new link is made. This implies that
1070links to links are reduced to links to files, directories or devices
1071before they are made.
1072
1073**Development Comments:**
1074
1075Calling parameters:
1076const char   \*existing
1077const char   \*new
1078
1079link() will determine if the target of the link actually exists using
1080rtems_filesystem_evaluate_path()
1081
1082rtems_filesystem_get_start_loc() is used to determine where to start the
1083path evaluation of the new name. This macro examines the first characters
1084of the name to see if the name of the new link starts with a
1085rtems_filesystem_is_separator. If it does the search starts from the root
1086of the RTEMS filesystem; otherwise the search will start from the current
1087directory.
1088
1089The OPS table evalformake() function for the parent’s filesystem is used
1090to locate the node that will be the parent of the new link. It will also
1091locate the start of the new path’s name. This name will be used to define
1092a child under the parent directory.
1093
1094If the parent is found, the routine will determine if the hard link that
1095we are trying to create will cross a filesystem boundary. This is not
1096permitted for hard-links.
1097
1098If the hard-link does not cross a filesystem boundary, a check is
1099performed to determine if the OPS table contains an entry for the link()
1100function.
1101
1102If a link() function is defined, the OPS table link() function will be
1103called to establish the actual link within the filesystem.
1104
1105The return code from the OPS table link() function is returned to the
1106calling program.
1107
1108.. COMMENT: @page
1109
1110lseek
1111=====
1112
1113**File:**
1114
1115lseek.c
1116
1117**Processing:**
1118
1119This routine is layered on both external handlers and filesystem / node
1120type specific handlers. This routine should allow for the support of new
1121filesystems without modification.
1122
1123**Development Comments:**
1124
1125This routine will determine if the file descriptor is associated with a
1126network device. If it is lseek will map to an external network handler.
1127The handler will be called with the file descriptor, offset and whence as
1128its calling parameters. The return code from the external handler will be
1129returned to the calling routine.
1130
1131If the file descriptor is not associated with a network connection, it is
1132associated with a node in a filesystem. The following steps will be
1133performed for filesystem nodes:
1134
1135# The file descriptor is used to obtain the file control block for the
1136  node.
1137
1138# The file descriptor is range checked.
1139
1140# The offset element of the file control block is altered as indicated
1141  by the offset and whence calling parameters
1142
1143# The handler table in the file control block is examined to determine
1144  if it contains an entry for the lseek() function. If it does not an error
1145  is returned to the calling program.
1146
1147# The lseek() function from the designated handler table is called
1148  with the file control block, offset and whence as calling arguments
1149
1150# The return code from the lseek() handler function is returned to the
1151  calling program
1152
1153.. COMMENT: @page
1154
1155mkdir
1156=====
1157
1158**File:**
1159
1160mkdir.c
1161
1162**Processing:**
1163
1164This routine attempts to create a directory node under the filesystem. The
1165routine is layered the mknod() function.
1166
1167**Development Comments:**
1168
1169See mknod() for developmental comments.
1170
1171.. COMMENT: @page
1172
1173mkfifo
1174======
1175
1176**File:**
1177
1178mkfifo.c
1179
1180**Processing:**
1181
1182This routine attempts to create a FIFO node under the filesystem. The
1183routine is layered the mknod() function.
1184
1185**Development Comments:**
1186
1187See mknod() for developmental comments
1188
1189.. COMMENT: @page
1190
1191mknod
1192=====
1193
1194**File:**
1195
1196mknod.c
1197
1198**Processing:**
1199
1200This function will allow for the creation of the following types of nodes
1201under the filesystem:
1202
1203- directories
1204
1205- regular files
1206
1207- character devices
1208
1209- block devices
1210
1211- fifos
1212
1213At the present time, an attempt to create a FIFO will result in an ENOTSUP
1214error to the calling function. This routine is layered the filesystem
1215specific routines evalformake and mknod. The introduction of a new
1216filesystem must include its own evalformake and mknod function to support
1217the generic mknod() function.  Under this condition the generic mknod()
1218function should accommodate other filesystem types without alteration.
1219
1220**Development Comments:**
1221
1222Test for nodal types - I thought that this test should look like the
1223following code:
1224.. code:: c
1225
1226    if ( (mode & S_IFDIR) = = S_IFDIR) \||
1227    (mode & S_IFREG) = = S_IFREG) \||
1228    (mode & S_IFCHR) = = S_IFCHR) \||
1229    (mode & S_IFBLK) = = S_IFBLK) \||
1230    (mode & S_IFIFO) = = S_IFIFO))
1231    Set_errno_and_return_minus_one (EINVAL);
1232
1233Where:
1234
1235- S_IFREG (0100000) - Creation of a regular file
1236
1237- S_IFCHR (0020000) - Creation of a character device
1238
1239- S_IFBLK (0060000) - Creation of a block device
1240
1241- S_IFIFO (0010000) - Creation of a FIFO
1242
1243Determine if the pathname that we are trying to create starts at the root
1244directory or is relative to the current directory using the
1245rtems_filesystem_get_start_loc()  function.
1246
1247Determine if the pathname leads to a valid directory that can be accessed
1248for the creation of a node.
1249
1250If the pathname is a valid location to create a node, verify that a
1251filesystem specific mknod() function exists.
1252
1253If the mknod() function exists, call the filesystem specific mknod()
1254function.  Pass the name, mode, device type and the location information
1255associated with the directory under which the node will be created.
1256
1257.. COMMENT: @page
1258
1259mount
1260=====
1261
1262**File:**
1263
1264mount.c
1265
1266Arguments (Not a standard POSIX call):
1267
1268rtems_filesystem_mount_table_entry_t   \**mt_entry,
1269
1270If the mount operation is successful, this pointer to a pointer will be
1271set to reference the mount table chain entry that has been allocated for
1272this file system mount.
1273
1274rtems_filesystem_operations_table   \*fs_ops,
1275
1276This is a pointer to a table of functions that are associated with the
1277file system that we are about to mount. This is the mechanism to selected
1278file system type without keeping a dynamic database of all possible file
1279system types that are valid for the mount operation. Using this method, it
1280is only necessary to configure the filesystems that we wish to use into
1281the RTEMS build. Unused filesystems types will not be drawn into the
1282build.
1283
1284char                      \*fsoptions,
1285
1286This argument points to a string that selects mounting for read only
1287access or read/write access. Valid states are "RO" and "RW"
1288
1289char                      \*device,
1290
1291This argument is reserved for the name of a device that will be used to
1292access the filesystem information. Current filesystem implementations are
1293memory based and do not require a device to access filesystem information.
1294
1295char                      \*mount_point
1296
1297This is a pathname to a directory in a currently mounted filesystem that
1298allows read, write and execute permissions.  If successful, the node found
1299by evaluating this name, is stored in the mt_entry.
1300
1301**Processing:**
1302
1303This routine will handle the mounting of a filesystem on a mount point. If
1304the operation is successful, a pointer to the mount table chain entry
1305associated with the mounted filesystem will be returned to the calling
1306function. The specifics about the processing required at the mount point
1307and within the filesystem being mounted is isolated in the filesystem
1308specific mount() and fsmount_me()  functions. This allows the generic
1309mount() function to remain unaltered even if new filesystem types are
1310introduced.
1311
1312**Development Comments:**
1313
1314This routine will use get_file_system_options() to determine if the mount
1315options are valid ("RO" or "RW").
1316
1317It confirms that a filesystem ops-table has been selected.
1318
1319Space is allocated for a mount table entry and selective elements of the
1320temporary mount table entry are initialized.
1321
1322If a mount point is specified: The mount point is examined to determine
1323that it is a directory and also has the appropriate permissions to allow a
1324filesystem to be mounted.
1325
1326The current mount table chain is searched to determine that there is not
1327another filesystem mounted at the mount point we are trying to mount onto.
1328
1329If a mount function is defined in the ops table for the filesystem
1330containing the mount point, it is called at this time.
1331
1332If no mount point is specified: Processing if performed to set up the
1333mount table chain entry as the base filesystem.
1334
1335If the fsmount_me() function is specified for ops-table of the filesystem
1336being mounted, that function is called to initialize for the new
1337filesystem.
1338
1339On successful completion, the temporary mount table entry will be placed
1340on the mount table chain to record the presence of the mounted filesystem.
1341
1342.. COMMENT: @page
1343
1344open
1345====
1346
1347**File:**
1348
1349open.c
1350
1351**Processing:**
1352
1353This routine is layered on both RTEMS calls and filesystem specific
1354implementations of the open() function. These functional interfaces should
1355not change for new filesystems and therefore this code should be stable as
1356new file systems are introduced.
1357
1358**Development Comments:**
1359
1360This routine will allocate a file control block for the file or device
1361that we are about to open.
1362
1363It will then test to see if the pathname exists. If it does a
1364rtems_filesystem_location_info_t data structure will be filled out. This
1365structure contains information that associates node information,
1366filesystem specific functions and mount table chain information with the
1367pathname.
1368
1369If the create option has been it will attempt to create a node for a
1370regular file along the specified path. If a file already exists along this
1371path, an error will be generated; otherwise, a node will be allocated for
1372the file under the filesystem that contains the pathname. When a new node
1373is created, it is also evaluated so that an appropriate
1374rtems_filesystem_location_info_t data structure can be filled out for the
1375newly created node.
1376
1377If the file exists or the new file was created successfully, the file
1378control block structure will be initialized with handler table
1379information, node information and the rtems_filesystem_location_info_t
1380data structure that describes the node and filesystem data in detail.
1381
1382If an open() function exists in the filesystem specific handlers table for
1383the node that we are trying to open, it will be called at this time.
1384
1385If any error is detected in the process, cleanup is performed. It consists
1386of freeing the file control block structure that was allocated at the
1387beginning of the generic open() routine.
1388
1389On a successful open(), the index into the file descriptor table will be
1390calculated and returned to the calling routine.
1391
1392.. COMMENT: @page
1393
1394opendir
1395=======
1396
1397**File:**
1398
1399opendir.c
1400
1401**Processing:**
1402
1403This routine will attempt to open a directory for read access. It will
1404setup a DIR control structure that will be used to access directory
1405information. This routine is layered on the generic open() routine and
1406filesystem specific directory processing routines.
1407
1408**Development Comments:**
1409
1410The BSD group provided this routine.
1411
1412.. COMMENT: @page
1413
1414pathconf
1415========
1416
1417**File:**
1418
1419pathconf.c
1420
1421**Processing:**
1422
1423This routine will obtain the value of one of the path configuration
1424parameters and return it to the calling routine. It is layered on the
1425generic open() and fpathconf()  functions. These interfaces should not
1426change with the addition of new filesystem types.
1427
1428**Development Comments:**
1429
1430This routine will try to open the file indicated by path.
1431
1432If successful, the file descriptor will be used to access the pathconf
1433value specified by ``name`` using the fpathconf() function.
1434
1435The file that was accessed is then closed.
1436
1437.. COMMENT: @page
1438
1439read
1440====
1441
1442**File:**
1443
1444deviceio.c
1445
1446**Processing:**
1447
1448This routine is layered on a set of RTEMS calls and filesystem specific
1449read operations. The functions are layered in such a way as to isolate
1450them from change as new filesystems are introduced.
1451
1452**Development Comments:**
1453
1454This routine will examine the type of file descriptor it is sent.
1455
1456If the file descriptor is associated with a network device, the read
1457function will be mapped to a special network handler. The return code from
1458the network handler will then be sent as the return code from generic
1459read() function.
1460
1461For file descriptors that are associated with the filesystem the following
1462sequence will be performed:
1463
1464# Obtain the file control block associated with the file descriptor
1465
1466# Range check the file descriptor
1467
1468# Determine that the buffer pointer is not invalid
1469
1470# Check that the count is not zero
1471
1472# Check the file control block to see if we have permissions to read
1473
1474# If there is a read function in the handler table, invoke the handler
1475  table read() function
1476
1477# Use the return code from the handler table read function(number of
1478  bytes read) to increment the offset element of the file control block
1479
1480# Return the number of bytes read to the calling program
1481
1482.. COMMENT: @page
1483
1484readdir
1485=======
1486
1487**File:**
1488
1489readdir.c
1490
1491**Processing:**
1492
1493This routine was acquired from the BSD group. It has not been altered from
1494its original form.
1495
1496**Development Comments:**
1497
1498The routine calls a customized getdents() function that is provided by the
1499user.  This routine provides the filesystem specific aspects of reading a
1500directory.
1501
1502It is layered on the read() function in the directory handler table. This
1503function has been mapped to the Imfs_dir_read() function.
1504
1505.. COMMENT: @page
1506
1507unmount
1508=======
1509
1510**File:**
1511
1512unmount.c
1513
1514**Processing:**
1515
1516This routine will attempt to dismount a mounted filesystem and then free
1517all resources that were allocated for the management of that filesystem.
1518
1519**Development Comments:**
1520
1521- This routine will determine if there are any filesystems currently
1522  mounted under the filesystem that we are trying to dismount. This would
1523  prevent the dismount of the filesystem.
1524
1525- It will test to see if the current directory is in the filesystem
1526  that we are attempting to dismount. This would prevent the dismount of the
1527  filesystem.
1528
1529- It will scan all the currently open file descriptors to determine is
1530  there is an open file descriptor to a file in the filesystem that we are
1531  attempting to unmount().
1532
1533If the above preconditions are met then the following sequence is
1534performed:
1535
1536# Call the filesystem specific unmount() function for the filesystem
1537  that contains the mount point. This routine should indicate that the mount
1538  point no longer has a filesystem mounted below it.
1539
1540# Call the filesystem specific fsunmount_me() function for the mounted
1541  filesystem that we are trying to unmount(). This routine should clean up
1542  any resources that are no longer needed for the management of the file
1543  system being un-mounted.
1544
1545# Extract the mount table entry for the filesystem that was just
1546  dismounted from the mount table chain.
1547
1548# Free the memory associated with the extracted mount table entry.
1549
1550.. COMMENT: @page
1551
1552eval
1553====
1554
1555**File:**
1556
1557XXX
1558
1559**Processing:**
1560
1561XXX
1562
1563**Development Comments:**
1564
1565XXX
1566
1567.. COMMENT: @page
1568
1569getdentsc
1570=========
1571
1572**File:**
1573
1574XXX
1575
1576**Processing:**
1577
1578XXX
1579
1580**Development Comments:**
1581
1582XXX
1583
1584.. COMMENT: COPYRIGHT (c) 1988-2002.
1585
1586.. COMMENT: On-Line Applications Research Corporation (OAR).
1587
1588.. COMMENT: All rights reserved.
1589
1590Filesystem Implementation Requirements
1591######################################
1592
1593This chapter details the behavioral requirements that all filesystem
1594implementations must adhere to.
1595
1596General
1597=======
1598
1599The RTEMS filesystem framework was intended to be compliant with the
1600POSIX Files and Directories interface standard. The following filesystem
1601characteristics resulted in a functional switching layer.
1602.. code:: c
1603
1604    Figure of the Filesystem Functional Layering goes here.
1605    This figure includes networking and disk caching layering.
1606
1607# Application programs are presented with a standard set of POSIX
1608  compliant functions that allow them to interface with the files, devices
1609  and directories in the filesystem. The interfaces to these routines do
1610  not reflect the type of subordinate filesystem implementation in which
1611  the file will be found.
1612
1613# The filesystem framework developed under RTEMS allows for mounting
1614  filesystem of different types under the base filesystem.
1615
1616# The mechanics of locating file information may be quite different
1617  between filesystem types.
1618
1619# The process of locating a file may require crossing filesystem
1620  boundaries.
1621
1622# The transitions between filesystem and the processing required to
1623  access information in different filesystem is not visible at the level
1624  of the POSIX function call.
1625
1626# The POSIX interface standard provides file access by character
1627  pathname to the file in some functions and through an integer file
1628  descriptor in other functions.
1629
1630# The nature of the integer file descriptor and its associated
1631  processing is operating system and filesystem specific.
1632
1633# Directory and device information must be processed with some of the
1634  same routines that apply to files.
1635
1636# The form and content of directory and device information differs
1637  greatly from that of a regular file.
1638
1639# Files, directories and devices represent elements (nodes) of a tree
1640  hierarchy.
1641
1642# The rules for processing each of the node types that exist under the
1643  filesystem are node specific but are still not reflected in the POSIX
1644  interface routines.
1645
1646.. code:: c
1647
1648    Figure of the Filesystem Functional Layering goes here.
1649    This figure focuses on the Base Filesystem and IMFS.
1650
1651.. code:: c
1652
1653    Figure of the IMFS Memfile control blocks
1654
1655.. _File-and-Directory-Removal-Constraints:
1656
1657File and Directory Removal Constraints
1658======================================
1659
1660The following POSIX constraints must be honored by all filesystems.
1661
1662- If a node is a directory with children it cannot be removed.
1663
1664- The root node of any filesystem, whether the base filesystem or a
1665  mounted filesystem, cannot be removed.
1666
1667- A node that is a directory that is acting as the mount point of a file
1668  system cannot be removed.
1669
1670- On filesystems supporting hard links, a link count is maintained.
1671  Prior to node removal, the node’s link count is decremented by one.  The
1672  link count must be less than one to allow for removal of the node.
1673
1674API Layering
1675============
1676
1677Mapping of Generic System Calls to Filesystem Specific Functions
1678----------------------------------------------------------------
1679
1680The list of generic system calls includes the routines open(), read(),
1681write(), close(), etc..
1682
1683The Files and Directories section of the POSIX Application Programs
1684Interface specifies a set of functions with calling arguments that are
1685used to gain access to the information in a filesystem. To the
1686application program, these functions allow access to information in any
1687mounted filesystem without explicit knowledge of the filesystem type or
1688the filesystem mount configuration. The following are functions that are
1689provided to the application:
1690
1691# access()
1692
1693# chdir()
1694
1695# chmod()
1696
1697# chown()
1698
1699# close()
1700
1701# closedir()
1702
1703# fchmod()
1704
1705# fcntl()
1706
1707# fdatasync()
1708
1709# fpathconf()
1710
1711# fstat()
1712
1713# fsync()
1714
1715# ftruncate()
1716
1717# link()
1718
1719# lseek()
1720
1721# mkdir()
1722
1723# mknod()
1724
1725# mount()
1726
1727# open()
1728
1729# opendir()
1730
1731# pathconf()
1732
1733# read()
1734
1735# readdir()
1736
1737# rewinddir()
1738
1739# rmdir()
1740
1741# rmnod()
1742
1743# scandir()
1744
1745# seekdir()
1746
1747# stat()
1748
1749# telldir()
1750
1751# umask()
1752
1753# unlink()
1754
1755# unmount()
1756
1757# utime()
1758
1759# write()
1760
1761The filesystem’s type as well as the node type within the filesystem
1762determine the nature of the processing that must be performed for each of
1763the functions above. The RTEMS filesystem provides a framework that
1764allows new filesystem to be developed and integrated without alteration
1765to the basic framework.
1766
1767To provide the functional switching that is required, each of the POSIX
1768file and directory functions have been implemented as a shell function.
1769The shell function adheres to the POSIX interface standard. Within this
1770functional shell, filesystem and node type information is accessed which
1771is then used to invoke the appropriate filesystem and node type specific
1772routine to process the POSIX function call.
1773
1774File/Device/Directory function access via file control block - rtems_libio_t structure
1775--------------------------------------------------------------------------------------
1776
1777The POSIX open() function returns an integer file descriptor that is used
1778as a reference to file control block information for a specific file. The
1779file control block contains information that is used to locate node, file
1780system, mount table and functional handler information. The diagram in
1781Figure 8 depicts the relationship between and among the following
1782components.
1783
1784# File Descriptor Table
1785  This is an internal RTEMS structure that tracks all currently defined file
1786  descriptors in the system. The index that is returned by the file open()
1787  operation references a slot in this table. The slot contains a pointer to
1788  the file descriptor table entry for this file. The rtems_libio_t structure
1789  represents the file control block.
1790
1791# Allocation of entry in the File Descriptor Table
1792  Access to the file descriptor table is controlled through a semaphore that
1793  is implemented using the rtems_libio_allocate() function. This routine
1794  will grab a semaphore and then scan the file control blocks to determine
1795  which slot is free for use. The first free slot is marked as used and the
1796  index to this slot is returned as the file descriptor for the open()
1797  request. After the alterations have been made to the file control block
1798  table, the semaphore is released to allow further operations on the table.
1799
1800# Maximum number of entries in the file descriptor table is
1801  configurable through the src/exec/sapi/headers/confdefs.h file. If the
1802  CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS constant is defined its value
1803  will represent the maximum number of file descriptors that are allowed.
1804  If CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS is not specified a default
1805  value of 20 will be used as the maximum number of file descriptors
1806  allowed.
1807
1808# File control block - rtems_libio_t structure
1809  .. code:: c
1810      struct rtems_libio_tt {
1811      rtems_driver_name_t              \*driver;
1812      off_t                             size;
1813      off_t                             offset;
1814      unsigned32                        flags;
1815      rtems_filesystem_location_info_t  pathinfo;
1816      Objects_Id                        sem;
1817      unsigned32                        data0;
1818      void                              data1;
1819      void                              file_info;
1820      rtems_filesystem_file_handlers_r  handlers;
1821      };
1822  A file control block can exist for regular files, devices and directories.
1823  The following fields are important for regular file and directory access:
1824  - Size - For a file this represents the number of bytes currently
1825    stored in a file. For a directory this field is not filled in.
1826  - Offset - For a file this is the byte file position index relative to
1827    the start of the file. For a directory this is the byte offset into a
1828    sequence of dirent structures.
1829  - Pathinfo - This is a structure that provides a pointer to node
1830    information, OPS table functions, Handler functions and the mount table
1831    entry associated with this node.
1832  - file_info - A pointer to node information that is used by Handler
1833    functions
1834  - handlers - A pointer to a table of handler functions that operate on
1835    a file, device or directory through a file descriptor index
1836
1837File/Directory function access via rtems_filesystem_location_info_t structure
1838-----------------------------------------------------------------------------
1839
1840The rtems_filesystem_location_info_tt structure below provides sufficient
1841information to process nodes under a mounted filesystem.
1842.. code:: c
1843
1844    struct rtems_filesystem_location_info_tt {
1845    void                                     \*node_access;
1846    rtems_filesystem_file_handlers_r         \*handlers;
1847    rtems_filesystem_operations_table        \*ops;
1848    rtems_filesystem_mount_table_entry_t     \*mt_entry;
1849    };
1850
1851It contains a void pointer to filesystem specific nodal structure,
1852pointers to the OPS table for the filesystem that contains the node, the
1853node type specific handlers for the node and a reference pointer to the
1854mount table entry associated with the filesystem containing the node
1855
1856Operation Tables
1857================
1858
1859Filesystem specific operations are invoked indirectly.  The set of
1860routines that implement the filesystem are configured into two tables.
1861The Filesystem Handler Table has routines that are specific to a
1862filesystem but remain constant regardless of the actual file type.
1863The File Handler Table has routines that are both filesystem and file type
1864specific.
1865
1866Filesystem Handler Table Functions
1867----------------------------------
1868
1869OPS table functions are defined in a ``rtems_filesystem_operations_table``
1870structure.  It defines functions that are specific to a given filesystem.
1871One table exists for each filesystem that is supported in the RTEMS
1872configuration. The structure definition appears below and is followed by
1873general developmental information on each of the functions contained in this
1874function management structure.
1875.. code:: c
1876
1877    typedef struct {
1878    rtems_filesystem_evalpath_t        evalpath;
1879    rtems_filesystem_evalmake_t        evalformake;
1880    rtems_filesystem_link_t            link;
1881    rtems_filesystem_unlink_t          unlink;
1882    rtems_filesystem_node_type_t       node_type;
1883    rtems_filesystem_mknod_t           mknod;
1884    rtems_filesystem_rmnod_t           rmnod;
1885    rtems_filesystem_chown_t           chown;
1886    rtems_filesystem_freenode_t        freenod;
1887    rtems_filesystem_mount_t           mount;
1888    rtems_filesystem_fsmount_me_t      fsmount_me;
1889    rtems_filesystem_unmount_t         unmount;
1890    rtems_filesystem_fsunmount_me_t    fsunmount_me;
1891    rtems_filesystem_utime_t           utime;
1892    rtems_filesystem_evaluate_link_t   eval_link;
1893    rtems_filesystem_symlink_t         symlink;
1894    } rtems_filesystem_operations_table;
1895
1896.. COMMENT: @page
1897
1898evalpath Handler
1899~~~~~~~~~~~~~~~~
1900
1901**Corresponding Structure Element:**
1902
1903evalpath
1904
1905**Arguments:**
1906
1907.. code:: c
1908
1909    const char                        \*pathname,      /* IN     \*/
1910    int                                flags,         /* IN     \*/
1911    rtems_filesystem_location_info_t  \*pathloc        /* IN/OUT \*/
1912
1913**Description:**
1914
1915This routine is responsible for evaluating the pathname passed in
1916based upon the flags and the valid ``rthems_filesystem_location_info_t``.
1917Additionally, it must make any changes to pathloc necessary to identify
1918the pathname node.  This should include calling the evalpath for a mounted
1919filesystem, if the given filesystem supports the mount command.
1920
1921This routine returns a 0 if the evaluation was successful.
1922Otherwise, it returns a -1 and sets errno to the correct error.
1923
1924This routine is required and should NOT be set to NULL.
1925
1926.. COMMENT: @page
1927
1928evalformake Handler
1929~~~~~~~~~~~~~~~~~~~
1930
1931**Corresponding Structure Element:**
1932
1933evalformake
1934
1935**Arguments:**
1936
1937.. code:: c
1938
1939    const char                       \*path,       /* IN \*/
1940    rtems_filesystem_location_info_t \*pathloc,    /* IN/OUT \*/
1941    const char                      \**name        /* OUT    \*/
1942
1943**Description:**
1944
1945This method is given a path to evaluate and a valid start location.  It
1946is responsible for finding the parent node for a requested make command,
1947setting pathloc information to identify the parent node, and setting
1948the name pointer to the first character of the name of the new node.
1949Additionally, if the filesystem supports the mount command, this method
1950should call the evalformake routine for the mounted filesystem.
1951
1952This routine returns a 0 if the evaluation was successful.  Otherwise, it
1953returns a -1 and sets errno to the correct error.
1954
1955This routine is required and should NOT be set to NULL.  However, if
1956the filesystem does not support user creation of a new node, it may
1957set errno to ENOSYS and return -1.
1958
1959.. COMMENT: @page
1960
1961link Handler
1962~~~~~~~~~~~~
1963
1964**Corresponding Structure Element:**
1965
1966link
1967
1968**Arguments:**
1969
1970.. code:: c
1971
1972    rtems_filesystem_location_info_t    \*to_loc,      /* IN \*/
1973    rtems_filesystem_location_info_t    \*parent_loc,  /* IN \*/
1974    const char                          \*token        /* IN \*/
1975
1976**Description:**
1977
1978This routine is used to create a hard-link.
1979
1980It will first examine the st_nlink count of the node that we are trying to.
1981If the link count exceeds LINK_MAX an error will be returned.
1982
1983The name of the link will be normalized to remove extraneous separators from
1984the end of the name.
1985
1986This routine is not required and may be set to NULL.
1987
1988.. COMMENT: @page
1989
1990unlink Handler
1991~~~~~~~~~~~~~~
1992
1993**Corresponding Structure Element:**
1994
1995XXX
1996
1997**Arguments:**
1998
1999XXX
2000
2001**Description:**
2002
2003XXX
2004
2005.. COMMENT: @page
2006
2007node_type Handler
2008~~~~~~~~~~~~~~~~~
2009
2010**Corresponding Structure Element:**
2011
2012node_type()
2013
2014**Arguments:**
2015
2016.. code:: c
2017
2018    rtems_filesystem_location_info_t    \*pathloc        /* IN \*/
2019
2020**Description:**
2021
2022XXX
2023
2024.. COMMENT: @page
2025
2026mknod Handler
2027~~~~~~~~~~~~~
2028
2029**Corresponding Structure Element:**
2030
2031mknod()
2032
2033**Arguments:**
2034
2035.. code:: c
2036
2037    const char                          \*token,        /* IN \*/
2038    mode_t                               mode,         /* IN \*/
2039    dev_t                                dev,          /* IN \*/
2040    rtems_filesystem_location_info_t    \*pathloc       /* IN/OUT \*/
2041
2042**Description:**
2043
2044XXX
2045
2046.. COMMENT: @page
2047
2048rmnod Handler
2049~~~~~~~~~~~~~
2050
2051**Corresponding Structure Element:**
2052
2053XXX
2054
2055**Arguments:**
2056
2057XXX
2058
2059**Description:**
2060
2061XXX
2062
2063.. COMMENT: @page
2064
2065chown Handler
2066~~~~~~~~~~~~~
2067
2068**Corresponding Structure Element:**
2069
2070chown()
2071
2072**Arguments:**
2073
2074.. code:: c
2075
2076    rtems_filesystem_location_info_t    \*pathloc        /* IN \*/
2077    uid_t                                owner          /* IN \*/
2078    gid_t                                group          /* IN \*/
2079
2080**Description:**
2081
2082XXX
2083
2084.. COMMENT: @page
2085
2086freenod Handler
2087~~~~~~~~~~~~~~~
2088
2089**Corresponding Structure Element:**
2090
2091freenod()
2092
2093**Arguments:**
2094
2095.. code:: c
2096
2097    rtems_filesystem_location_info_t      \*pathloc       /* IN \*/
2098
2099**Description:**
2100
2101This routine is used by the generic code to allow memory to be allocated
2102during the evaluate routines, and set free when the generic code is finished
2103accessing a node.  If the evaluate routines allocate memory to identify
2104a node this routine should be utilized to free that memory.
2105
2106This routine is not required and may be set to NULL.
2107
2108.. COMMENT: @page
2109
2110mount Handler
2111~~~~~~~~~~~~~
2112
2113**Corresponding Structure Element:**
2114
2115mount()
2116
2117**Arguments:**
2118
2119.. code:: c
2120
2121    rtems_filesystem_mount_table_entry_t   \*mt_entry
2122
2123**Description:**
2124
2125XXX
2126
2127.. COMMENT: @page
2128
2129fsmount_me Handler
2130~~~~~~~~~~~~~~~~~~
2131
2132**Corresponding Structure Element:**
2133
2134XXX
2135
2136**Arguments:**
2137
2138.. code:: c
2139
2140    rtems_filesystem_mount_table_entry_t   \*mt_entry
2141
2142**Description:**
2143
2144This function is provided with a filesystem to take care of the internal
2145filesystem management details associated with mounting that filesystem
2146under the RTEMS environment.
2147
2148It is not responsible for the mounting details associated the filesystem
2149containing the mount point.
2150
2151The rtems_filesystem_mount_table_entry_t structure contains the key elements
2152below:
2153
2154rtems_filesystem_location_info_t         \*mt_point_node,
2155
2156This structure contains information about the mount point. This
2157allows us to find the ops-table and the handling functions
2158associated with the filesystem containing the mount point.
2159
2160rtems_filesystem_location_info_t         \*fs_root_node,
2161
2162This structure contains information about the root node in the file
2163system to be mounted. It allows us to find the ops-table and the
2164handling functions associated with the filesystem to be mounted.
2165
2166rtems_filesystem_options_t                 options,
2167
2168Read only or read/write access
2169
2170void                                         \*fs_info,
2171
2172This points to an allocated block of memory the will be used to
2173hold any filesystem specific information of a global nature. This
2174allocated region if important because it allows us to mount the
2175same filesystem type more than once under the RTEMS system.
2176Each instance of the mounted filesystem has its own set of global
2177management information that is separate from the global
2178management information associated with the other instances of the
2179mounted filesystem type.
2180
2181rtems_filesystem_limits_and_options_t    pathconf_info,
2182
2183The table contains the following set of values associated with the
2184mounted filesystem:
2185
2186- link_max
2187
2188- max_canon
2189
2190- max_input
2191
2192- name_max
2193
2194- path_max
2195
2196- pipe_buf
2197
2198- posix_async_io
2199
2200- posix_chown_restrictions
2201
2202- posix_no_trunc
2203
2204- posix_prio_io
2205
2206- posix_sync_io
2207
2208- posix_vdisable
2209
2210These values are accessed with the pathconf() and the fpathconf ()
2211functions.
2212
2213const char                                   \*dev
2214
2215The is intended to contain a string that identifies the device that contains
2216the filesystem information. The filesystems that are currently implemented
2217are memory based and don’t require a device specification.
2218
2219If the mt_point_node.node_access is NULL then we are mounting the base file
2220system.
2221
2222The routine will create a directory node for the root of the IMFS file
2223system.
2224
2225The node will have read, write and execute permissions for owner, group and
2226others.
2227
2228The node’s name will be a null string.
2229
2230A filesystem information structure(fs_info) will be allocated and
2231initialized for the IMFS filesystem. The fs_info pointer in the mount table
2232entry will be set to point the filesystem information structure.
2233
2234The pathconf_info element of the mount table will be set to the appropriate
2235table of path configuration constants (LIMITS_AND_OPTIONS).
2236
2237The fs_root_node structure will be filled in with the following:
2238
2239- pointer to the allocated root node of the filesystem
2240
2241- directory handlers for a directory node under the IMFS filesystem
2242
2243- OPS table functions for the IMFS
2244
2245A 0 will be returned to the calling routine if the process succeeded,
2246otherwise a 1 will be returned.
2247
2248.. COMMENT: @page
2249
2250unmount Handler
2251~~~~~~~~~~~~~~~
2252
2253**Corresponding Structure Element:**
2254
2255XXX
2256
2257**Arguments:**
2258
2259XXX
2260
2261**Description:**
2262
2263XXX
2264
2265.. COMMENT: @page
2266
2267fsunmount_me Handler
2268~~~~~~~~~~~~~~~~~~~~
2269
2270**Corresponding Structure Element:**
2271
2272imfs_fsunmount_me()
2273
2274**Arguments:**
2275
2276.. code:: c
2277
2278    rtems_filesystem_mount_table_entry_t   \*mt_entry
2279
2280**Description:**
2281
2282XXX
2283
2284.. COMMENT: @page
2285
2286utime Handler
2287~~~~~~~~~~~~~
2288
2289**Corresponding Structure Element:**
2290
2291XXX
2292
2293**Arguments:**
2294
2295XXX
2296
2297**Description:**
2298
2299XXX
2300
2301.. COMMENT: @page
2302
2303eval_link Handler
2304~~~~~~~~~~~~~~~~~
2305
2306**Corresponding Structure Element:**
2307
2308XXX
2309
2310**Arguments:**
2311
2312XXX
2313
2314**Description:**
2315
2316XXX
2317
2318.. COMMENT: @page
2319
2320symlink Handler
2321~~~~~~~~~~~~~~~
2322
2323**Corresponding Structure Element:**
2324
2325XXX
2326
2327**Arguments:**
2328
2329XXX
2330
2331**Description:**
2332
2333XXX
2334
2335.. COMMENT: @page
2336
2337File Handler Table Functions
2338----------------------------
2339
2340Handler table functions are defined in a ``rtems_filesystem_file_handlers_r``
2341structure. It defines functions that are specific to a node type in a given
2342filesystem. One table exists for each of the filesystem’s node types. The
2343structure definition appears below. It is followed by general developmental
2344information on each of the functions associated with regular files contained
2345in this function management structure.
2346.. code:: c
2347
2348    typedef struct {
2349    rtems_filesystem_open_t           open;
2350    rtems_filesystem_close_t          close;
2351    rtems_filesystem_read_t           read;
2352    rtems_filesystem_write_t          write;
2353    rtems_filesystem_ioctl_t          ioctl;
2354    rtems_filesystem_lseek_t          lseek;
2355    rtems_filesystem_fstat_t          fstat;
2356    rtems_filesystem_fchmod_t         fchmod;
2357    rtems_filesystem_ftruncate_t      ftruncate;
2358    rtems_filesystem_fpathconf_t      fpathconf;
2359    rtems_filesystem_fsync_t          fsync;
2360    rtems_filesystem_fdatasync_t      fdatasync;
2361    rtems_filesystem_fcntl_t          fcntl;
2362    } rtems_filesystem_file_handlers_r;
2363
2364.. COMMENT: @page
2365
2366open Handler
2367~~~~~~~~~~~~
2368
2369**Corresponding Structure Element:**
2370
2371open()
2372
2373**Arguments:**
2374
2375.. code:: c
2376
2377    rtems_libio_t   \*iop,
2378    const char      \*pathname,
2379    unsigned32       flag,
2380    unsigned32       mode
2381
2382**Description:**
2383
2384XXX
2385
2386.. COMMENT: @page
2387
2388close Handler
2389~~~~~~~~~~~~~
2390
2391**Corresponding Structure Element:**
2392
2393close()
2394
2395**Arguments:**
2396
2397.. code:: c
2398
2399    rtems_libio_t     \*iop
2400
2401**Description:**
2402
2403XXX
2404
2405**NOTES:**
2406
2407XXX
2408
2409.. COMMENT: @page
2410
2411read Handler
2412~~~~~~~~~~~~
2413
2414**Corresponding Structure Element:**
2415
2416read()
2417
2418**Arguments:**
2419
2420.. code:: c
2421
2422    rtems_libio_t     \*iop,
2423    void              \*buffer,
2424    unsigned32         count
2425
2426**Description:**
2427
2428XXX
2429
2430**NOTES:**
2431
2432XXX
2433
2434.. COMMENT: @page
2435
2436write Handler
2437~~~~~~~~~~~~~
2438
2439**Corresponding Structure Element:**
2440
2441XXX
2442
2443**Arguments:**
2444
2445XXX
2446
2447**Description:**
2448
2449XXX
2450
2451**NOTES:**
2452
2453XXX
2454
2455.. COMMENT: @page
2456
2457ioctl Handler
2458~~~~~~~~~~~~~
2459
2460**Corresponding Structure Element:**
2461
2462XXX
2463
2464**Arguments:**
2465
2466.. code:: c
2467
2468    rtems_libio_t     \*iop,
2469    unsigned32       command,
2470    void              \*buffer
2471
2472**Description:**
2473
2474XXX
2475
2476**NOTES:**
2477
2478XXX
2479
2480.. COMMENT: @page
2481
2482lseek Handler
2483~~~~~~~~~~~~~
2484
2485**Corresponding Structure Element:**
2486
2487lseek()
2488
2489**Arguments:**
2490
2491.. code:: c
2492
2493    rtems_libio_t     \*iop,
2494    off_t              offset,
2495    int                whence
2496
2497**Description:**
2498
2499XXX
2500
2501**NOTES:**
2502
2503XXX
2504
2505.. COMMENT: @page
2506
2507fstat Handler
2508~~~~~~~~~~~~~
2509
2510**Corresponding Structure Element:**
2511
2512fstat()
2513
2514**Arguments:**
2515
2516.. code:: c
2517
2518    rtems_filesystem_location_info_t   \*loc,
2519    struct stat                        \*buf
2520
2521**Description:**
2522
2523The following information is extracted from the filesystem
2524specific node and placed in the ``stat`` structure:
2525
2526- st_mode
2527
2528- st_nlink
2529
2530- st_ino
2531
2532- st_uid
2533
2534- st_gid
2535
2536- st_atime
2537
2538- st_mtime
2539
2540- st_ctime
2541
2542**NOTES:**
2543
2544Both the ``stat()`` and ``lstat()`` services are
2545implemented directly using the ``fstat()`` handler.  The
2546difference in behavior is determined by how the path is evaluated
2547prior to this handler being called on a particular
2548file entity.
2549
2550The ``fstat()`` system call is implemented directly
2551on top of this filesystem handler.
2552
2553.. COMMENT: @page
2554
2555fchmod Handler
2556~~~~~~~~~~~~~~
2557
2558**Corresponding Structure Element:**
2559
2560fchmod()
2561
2562**Arguments:**
2563
2564.. code:: c
2565
2566    rtems_libio_t     \*iop
2567    mode_t              mode
2568
2569**Description:**
2570
2571XXX
2572
2573**NOTES:**
2574
2575XXX
2576
2577.. COMMENT: @page
2578
2579ftruncate Handler
2580~~~~~~~~~~~~~~~~~
2581
2582**Corresponding Structure Element:**
2583
2584XXX
2585
2586**Arguments:**
2587
2588XXX
2589
2590**Description:**
2591
2592XXX
2593
2594**NOTES:**
2595
2596XXX
2597
2598fpathconf Handler
2599~~~~~~~~~~~~~~~~~
2600
2601**Corresponding Structure Element:**
2602
2603XXX
2604
2605**Arguments:**
2606
2607XXX
2608
2609**Description:**
2610
2611XXX
2612
2613**NOTES:**
2614
2615XXX
2616
2617.. COMMENT: @page
2618
2619fsync Handler
2620~~~~~~~~~~~~~
2621
2622**Corresponding Structure Element:**
2623
2624XXX
2625
2626**Arguments:**
2627
2628XXX
2629
2630**Description:**
2631
2632XXX
2633
2634**NOTES:**
2635
2636XXX
2637
2638.. COMMENT: @page
2639
2640fdatasync Handler
2641~~~~~~~~~~~~~~~~~
2642
2643**Corresponding Structure Element:**
2644
2645XXX
2646
2647**Arguments:**
2648
2649XXX
2650
2651**Description:**
2652
2653XXX
2654
2655**NOTES:**
2656
2657XXX
2658
2659.. COMMENT: @page
2660
2661fcntl Handler
2662~~~~~~~~~~~~~
2663
2664**Corresponding Structure Element:**
2665
2666XXX
2667
2668**Arguments:**
2669
2670XXX
2671
2672**Description:**
2673
2674XXX
2675
2676**NOTES:**
2677
2678XXX
2679
2680.. COMMENT: COPYRIGHT (c) 1988-2002.
2681
2682.. COMMENT: On-Line Applications Research Corporation (OAR).
2683
2684.. COMMENT: All rights reserved.
2685
2686In-Memory Filesystem
2687####################
2688
2689This chapter describes the In-Memory FileSystem (IMFS).  The IMFS is a
2690full featured POSIX filesystem that keeps all information in memory.
2691
2692IMFS Per Node Data Structure
2693============================
2694
2695Each regular file, device, hard link, and directory is represented by a data
2696structure called a ``jnode``. The ``jnode`` is formally represented by the
2697structure:
2698.. code:: c
2699
2700    struct IMFS_jnode_tt {
2701    Chain_Node          Node;             /* for chaining them together \*/
2702    IMFS_jnode_t       \*Parent;           /* Parent node \*/
2703    char                name[NAME_MAX+1]; /* "basename" \*/
2704    mode_t              st_mode;          /* File mode \*/
2705    nlink_t             st_nlink;         /* Link count \*/
2706    ino_t               st_ino;           /* inode \*/
2707    uid_t               st_uid;           /* User ID of owner \*/
2708    gid_t               st_gid;           /* Group ID of owner \*/
2709    time_t              st_atime;         /* Time of last access \*/
2710    time_t              st_mtime;         /* Time of last modification \*/
2711    time_t              st_ctime;         /* Time of last status change \*/
2712    IMFS_jnode_types_t  type;             /* Type of this entry \*/
2713    IMFS_typs_union     info;
2714    };
2715
2716The key elements of this structure are listed below together with a brief
2717explanation of their role in the filesystem.
2718
2719*Node*
2720    exists to allow the entire ``jnode`` structure to be included in a chain.
2721
2722*Parent*
2723    is a pointer to another ``jnode`` structure that is the logical parent of the
2724    node in which it appears.  This field may be NULL if the file associated with
2725    this node is deleted but there are open file descriptors on this file or
2726    there are still hard links to this node.
2727
2728*name*
2729    is the name of this node within the filesystem hierarchical tree. Example:  If
2730    the fully qualified pathname to the ``jnode`` was ``/a/b/c``, the``jnode`` name field would contain the null terminated string ``"c"``.
2731
2732*st_mode*
2733    is the standard Unix access permissions for the file or directory.
2734
2735*st_nlink*
2736    is the number of hard links to this file. When a ``jnode`` is first created
2737    its link count is set to 1. A ``jnode`` and its associated resources
2738    cannot be deleted unless its link count is less than 1.
2739
2740*st_ino*
2741    is a unique node identification number
2742
2743*st_uid*
2744    is the user ID of the file’s owner
2745
2746*st_gid*
2747    is the group ID of the file’s owner
2748
2749*st_atime*
2750    is the time of the last access to this file
2751
2752*st_mtime*
2753    is the time of the last modification of this file
2754
2755*st_ctime*
2756    is the time of the last status change to the file
2757
2758*type*
2759    is the indication of node type must be one of the following states:
2760    - IMFS_DIRECTORY
2761    - IMFS_MEMORY_FILE
2762    - IMFS_HARD_LINK
2763    - IMFS_SYM_LINK
2764    - IMFS_DEVICE
2765
2766*info*
2767    is this contains a structure that is unique to file type (See IMFS_typs_union
2768    in imfs.h).
2769    - IMFS_DIRECTORY
2770      An IMFS directory contains a dynamic chain structure that
2771      records all files and directories that are subordinate to the directory node.
2772    - IMFS_MEMORY_FILE
2773      Under the in memory filesystem regular files hold data. Data is dynamically
2774      allocated to the file in 128 byte chunks of memory.  The individual chunks of
2775      memory are tracked by arrays of pointers that record the address of the
2776      allocated chunk of memory. Single, double, and triple indirection pointers
2777      are used to record the locations of all segments of the file.  The
2778      memory organization of an IMFS file are discussed elsewhere in this manual.
2779    - IMFS_HARD_LINK
2780      The IMFS filesystem supports the concept of hard links to other nodes in the
2781      IMFS filesystem.  These hard links are actual pointers to other nodes in the
2782      same filesystem. This type of link cannot cross-filesystem boundaries.
2783    - IMFS_SYM_LINK
2784      The IMFS filesystem supports the concept of symbolic links to other nodes in
2785      any filesystem. A symbolic link consists of a pointer to a character string
2786      that represents the pathname to the target node. This type of link can
2787      cross-filesystem boundaries.  Just as with most versions of UNIX supporting
2788      symbolic links, a symbolic link can point to a non-existent file.
2789    - IMFS_DEVICE
2790      All RTEMS devices now appear as files under the in memory filesystem. On
2791      system initialization, all devices are registered as nodes under the file
2792      system.
2793
2794Miscellaneous IMFS Information
2795==============================
2796
2797Memory associated with the IMFS
2798===============================
2799
2800A memory based filesystem draws its resources for files and directories
2801from the memory resources of the system. When it is time to un-mount the
2802filesystem, the memory resources that supported filesystem are set free.
2803In order to free these resources, a recursive walk of the filesystems
2804tree structure will be performed. As the leaf nodes under the filesystem
2805are encountered their resources are freed. When directories are made empty
2806by this process, their resources are freed.
2807
2808Node removal constraints for the IMFS
2809-------------------------------------
2810
2811The IMFS conforms to the general filesystem requirements for node
2812removal.  See :ref:`File and Directory Removal Constraints <File-and-Directory-Removal-Constraints>`.
2813
2814IMFS General Housekeeping Notes
2815-------------------------------
2816
2817The following is a list of odd housekeeping notes for the IMFS.
2818
2819- If the global variable rtems_filesystem_current refers to the node that
2820  we are trying to remove, the node_access element of this structure must be
2821  set to NULL to invalidate it.
2822
2823- If the node was of IMFS_MEMORY_FILE type, free the memory associated
2824  with the memory file before freeing the node. Use the IMFS_memfile_remove()
2825  function.
2826
2827IMFS Operation Tables
2828=====================
2829
2830IMFS Filesystem Handler Table Functions
2831---------------------------------------
2832
2833OPS table functions are defined in a rtems_filesystem_operations_table
2834structure.  It defines functions that are specific to a given filesystem.
2835One table exists for each filesystem that is supported in the RTEMS
2836configuration. The structure definition appears below and is followed by
2837general developmental information on each of the functions contained in this
2838function management structure.
2839.. code:: c
2840
2841    rtems_filesystem_operations_table  IMFS_ops = {
2842    IMFS_eval_path,
2843    IMFS_evaluate_for_make,
2844    IMFS_link,
2845    IMFS_unlink,
2846    IMFS_node_type,
2847    IMFS_mknod,
2848    IMFS_rmnod,
2849    IMFS_chown,
2850    IMFS_freenodinfo,
2851    IMFS_mount,
2852    IMFS_initialize,
2853    IMFS_unmount,
2854    IMFS_fsunmount,
2855    IMFS_utime,
2856    IMFS_evaluate_link,
2857    IMFS_symlink,
2858    IMFS_readlink
2859    };
2860
2861.. COMMENT: @page
2862
2863IMFS_evalpath()
2864~~~~~~~~~~~~~~~
2865
2866**Corresponding Structure Element:**
2867
2868XXX
2869
2870**Arguments:**
2871
2872XXX
2873
2874**File:**
2875
2876XXX
2877
2878**Description:**
2879
2880XXX
2881
2882.. COMMENT: @page
2883
2884IMFS_evalformake()
2885~~~~~~~~~~~~~~~~~~
2886
2887**Corresponding Structure Element:**
2888
2889XXX
2890
2891**Arguments:**
2892
2893XXX
2894
2895**File:**
2896
2897XXX
2898
2899**Description:**
2900
2901XXX
2902
2903.. COMMENT: @page
2904
2905IMFS_link()
2906~~~~~~~~~~~
2907
2908**Corresponding Structure Element:**
2909
2910link
2911
2912**Arguments:**
2913
2914.. code:: c
2915
2916    rtems_filesystem_location_info_t    \*to_loc,      /* IN \*/
2917    rtems_filesystem_location_info_t    \*parent_loc,  /* IN \*/
2918    const char                          \*token        /* IN \*/
2919
2920**File:**
2921
2922imfs_link.c
2923
2924**Description:**
2925
2926This routine is used in the IMFS filesystem to create a hard-link.
2927
2928It will first examine the st_nlink count of the node that we are trying to.
2929If the link count exceeds LINK_MAX an error will be returned.
2930
2931The name of the link will be normalized to remove extraneous separators from
2932the end of the name.
2933
2934IMFS_create_node will be used to create a filesystem node that will have the
2935following characteristics:
2936
2937- parent that was determined in the link() function in file link.c
2938
2939- Type will be set to IMFS_HARD_LINK
2940
2941- name will be set to the normalized name
2942
2943- mode of the hard-link will be set to the mode of the target node
2944
2945If there was trouble allocating memory for the new node an error will be
2946returned.
2947
2948The st_nlink count of the target node will be incremented to reflect the new
2949link.
2950
2951The time fields of the link will be set to reflect the creation time of the
2952hard-link.
2953
2954.. COMMENT: @page
2955
2956IMFS_unlink()
2957~~~~~~~~~~~~~
2958
2959**Corresponding Structure Element:**
2960
2961XXX
2962
2963**Arguments:**
2964
2965XXX
2966
2967**File:**
2968
2969XXX
2970
2971**Description:**
2972
2973XXX
2974
2975.. COMMENT: @page
2976
2977IMFS_node_type()
2978~~~~~~~~~~~~~~~~
2979
2980**Corresponding Structure Element:**
2981
2982IMFS_node_type()
2983
2984**Arguments:**
2985
2986.. code:: c
2987
2988    rtems_filesystem_location_info_t    \*pathloc        /* IN \*/
2989
2990**File:**
2991
2992imfs_ntype.c
2993
2994**Description:**
2995
2996This routine will locate the IMFS_jnode_t structure that holds ownership
2997information for the selected node in the filesystem.
2998
2999This structure is pointed to by pathloc->node_access.
3000
3001The IMFS_jnode_t type element indicates one of the node types listed below:
3002
3003- RTEMS_FILESYSTEM_DIRECTORY
3004
3005- RTEMS_FILESYSTEM_DEVICE
3006
3007- RTEMS_FILESYSTEM_HARD_LINK
3008
3009- RTEMS_FILESYSTEM_MEMORY_FILE
3010
3011.. COMMENT: @page
3012
3013IMFS_mknod()
3014~~~~~~~~~~~~
3015
3016**Corresponding Structure Element:**
3017
3018IMFS_mknod()
3019
3020**Arguments:**
3021
3022.. code:: c
3023
3024    const char                          \*token,        /* IN \*/
3025    mode_t                               mode,         /* IN \*/
3026    dev_t                                dev,          /* IN \*/
3027    rtems_filesystem_location_info_t    \*pathloc       /* IN/OUT \*/
3028
3029**File:**
3030
3031imfs_mknod.c
3032
3033**Description:**
3034
3035This routine will examine the mode argument to determine is we are trying to
3036create a directory, regular file and a device node. The creation of other
3037node types is not permitted and will cause an assert.
3038
3039Memory space will be allocated for a ``jnode`` and the node will be set up
3040according to the nodal type that was specified. The IMFS_create_node()
3041function performs the allocation and setup of the node.
3042
3043The only problem that is currently reported is the lack of memory when we
3044attempt to allocate space for the ``jnode`` (ENOMEN).
3045
3046.. COMMENT: @page
3047
3048IMFS_rmnod()
3049~~~~~~~~~~~~
3050
3051**Corresponding Structure Element:**
3052
3053XXX
3054
3055**Arguments:**
3056
3057XXX
3058
3059**File:**
3060
3061XXX
3062
3063**Description:**
3064
3065XXX
3066
3067.. COMMENT: @page
3068
3069IMFS_chown()
3070~~~~~~~~~~~~
3071
3072**Corresponding Structure Element:**
3073
3074IMFS_chown()
3075
3076**Arguments:**
3077
3078.. code:: c
3079
3080    rtems_filesystem_location_info_t    \*pathloc        /* IN \*/
3081    uid_t                                owner          /* IN \*/
3082    gid_t                                group          /* IN \*/
3083
3084**File:**
3085
3086imfs_chown.c
3087
3088**Description:**
3089
3090This routine will locate the IMFS_jnode_t structure that holds ownership
3091information for the selected node in the filesystem.
3092
3093This structure is pointed to by pathloc->node_access.
3094
3095The st_uid and st_gid fields of the node are then modified. Since this is a
3096memory based filesystem, no further action is required to alter the
3097ownership of the IMFS_jnode_t structure.
3098
3099.. COMMENT: @page
3100
3101IMFS_freenod()
3102~~~~~~~~~~~~~~
3103
3104**Corresponding Structure Element:**
3105
3106IMFS_freenod()
3107
3108**Arguments:**
3109
3110.. code:: c
3111
3112    rtems_filesystem_location_info_t      \*pathloc       /* IN \*/
3113
3114**File:**
3115
3116imfs_free.c
3117
3118**Description:**
3119
3120This method is a private function to the IMFS.  It is called by IMFS routines
3121to free nodes that have been allocated.  Examples of where this routine
3122may be called from are unlink and rmnod.
3123
3124Note:  This routine should not be confused with the filesystem callback
3125freenod.  The IMFS allocates memory until the node no longer exists.
3126
3127.. COMMENT: @page
3128
3129IMFS_freenodinfo()
3130~~~~~~~~~~~~~~~~~~
3131
3132**Corresponding Structure Element:**
3133
3134IMFS_freenodinfo()
3135
3136**Arguments:**
3137
3138.. code:: c
3139
3140    rtems_filesystem_location_info_t      \*pathloc       /* IN \*/
3141
3142**File:**
3143
3144imfs_free.c
3145
3146**Description:**
3147
3148The In-Memory File System does not need to allocate memory during the
3149evaluate routines. Therefore, this routine simply routines PASS.
3150
3151.. COMMENT: @page
3152
3153IMFS_mount()
3154~~~~~~~~~~~~
3155
3156**Corresponding Structure Element:**
3157
3158IMFS_mount()
3159
3160**Arguments:**
3161
3162.. code:: c
3163
3164    rtems_filesystem_mount_table_entry_t   \*mt_entry
3165
3166**File:**
3167
3168imfs_mount.c
3169
3170**Description:**
3171
3172This routine provides the filesystem specific processing required to mount a
3173filesystem for the system that contains the mount point. It will determine
3174if the point that we are trying to mount onto is a node of IMFS_DIRECTORY
3175type.
3176
3177If it is the node’s info element is altered so that the info.directory.mt_fs
3178element points to the mount table chain entry that is associated with the
3179mounted filesystem at this point. The info.directory.mt_fs element can be
3180examined to determine if a filesystem is mounted at a directory. If it is
3181NULL, the directory does not serve as a mount point. A non-NULL entry
3182indicates that the directory does serve as a mount point and the value of
3183info.directory.mt_fs can be used to locate the mount table chain entry that
3184describes the filesystem mounted at this point.
3185
3186.. COMMENT: @page
3187
3188IMFS_fsmount_me()
3189~~~~~~~~~~~~~~~~~
3190
3191**Corresponding Structure Element:**
3192
3193IMFS_initialize()
3194
3195**Arguments:**
3196
3197.. code:: c
3198
3199    rtems_filesystem_mount_table_entry_t   \*mt_entry
3200
3201**File:**
3202
3203imfs_init.c
3204
3205**Description:**
3206
3207This function is provided with a filesystem to take care of the internal
3208filesystem management details associated with mounting that filesystem
3209under the RTEMS environment.
3210
3211It is not responsible for the mounting details associated the filesystem
3212containing the mount point.
3213
3214The rtems_filesystem_mount_table_entry_t structure contains the key elements
3215below:
3216
3217rtems_filesystem_location_info_t         \*mt_point_node,
3218
3219This structure contains information about the mount point. This
3220allows us to find the ops-table and the handling functions
3221associated with the filesystem containing the mount point.
3222
3223rtems_filesystem_location_info_t         \*fs_root_node,
3224
3225This structure contains information about the root node in the file
3226system to be mounted. It allows us to find the ops-table and the
3227handling functions associated with the filesystem to be mounted.
3228
3229rtems_filesystem_options_t                 options,
3230
3231Read only or read/write access
3232
3233void                                         \*fs_info,
3234
3235This points to an allocated block of memory the will be used to
3236hold any filesystem specific information of a global nature. This
3237allocated region if important because it allows us to mount the
3238same filesystem type more than once under the RTEMS system.
3239Each instance of the mounted filesystem has its own set of global
3240management information that is separate from the global
3241management information associated with the other instances of the
3242mounted filesystem type.
3243
3244rtems_filesystem_limits_and_options_t    pathconf_info,
3245
3246The table contains the following set of values associated with the
3247mounted filesystem:
3248
3249- link_max
3250
3251- max_canon
3252
3253- max_input
3254
3255- name_max
3256
3257- path_max
3258
3259- pipe_buf
3260
3261- posix_async_io
3262
3263- posix_chown_restrictions
3264
3265- posix_no_trunc
3266
3267- posix_prio_io
3268
3269- posix_sync_io
3270
3271- posix_vdisable
3272
3273These values are accessed with the pathconf() and the fpathconf ()
3274functions.
3275
3276const char                                   \*dev
3277
3278The is intended to contain a string that identifies the device that contains
3279the filesystem information. The filesystems that are currently implemented
3280are memory based and don’t require a device specification.
3281
3282If the mt_point_node.node_access is NULL then we are mounting the base file
3283system.
3284
3285The routine will create a directory node for the root of the IMFS file
3286system.
3287
3288The node will have read, write and execute permissions for owner, group and
3289others.
3290
3291The node’s name will be a null string.
3292
3293A filesystem information structure(fs_info) will be allocated and
3294initialized for the IMFS filesystem. The fs_info pointer in the mount table
3295entry will be set to point the filesystem information structure.
3296
3297The pathconf_info element of the mount table will be set to the appropriate
3298table of path configuration constants ( IMFS_LIMITS_AND_OPTIONS ).
3299
3300The fs_root_node structure will be filled in with the following:
3301
3302- pointer to the allocated root node of the filesystem
3303
3304- directory handlers for a directory node under the IMFS filesystem
3305
3306- OPS table functions for the IMFS
3307
3308A 0 will be returned to the calling routine if the process succeeded,
3309otherwise a 1 will be returned.
3310
3311.. COMMENT: @page
3312
3313IMFS_unmount()
3314~~~~~~~~~~~~~~
3315
3316**Corresponding Structure Element:**
3317
3318IMFS_unmount()
3319
3320**Arguments:**
3321
3322.. code:: c
3323
3324    rtems_filesystem_mount_table_entry_t   \*mt_entry
3325
3326**File:**
3327
3328imfs_unmount.c
3329
3330**Description:**
3331
3332This routine allows the IMFS to unmount a filesystem that has been
3333mounted onto a IMFS directory.
3334
3335The mount entry mount point node access is verified to be a mounted
3336directory.  It’s mt_fs is set to NULL.  This identifies to future
3337calles into the IMFS that this directory node is no longer a mount
3338point.  Additionally, it will allow any directories that were hidden
3339by the mounted system to again become visible.
3340
3341.. COMMENT: @page
3342
3343IMFS_fsunmount()
3344~~~~~~~~~~~~~~~~
3345
3346**Corresponding Structure Element:**
3347
3348imfs_fsunmount()
3349
3350**Arguments:**
3351
3352.. code:: c
3353
3354    rtems_filesystem_mount_table_entry_t   \*mt_entry
3355
3356**File:**
3357
3358imfs_init.c
3359
3360**Description:**
3361
3362This method unmounts this instance of the IMFS file system.  It is the
3363counterpart to the IMFS_initialize routine.  It is called by the generic
3364code under the fsunmount_me callback.
3365
3366All method loops finding the first encountered node with no children and
3367removing the node from the tree, thus returning allocated resources.  This
3368is done until all allocated nodes are returned.
3369
3370.. COMMENT: @page
3371
3372IMFS_utime()
3373~~~~~~~~~~~~
3374
3375**Corresponding Structure Element:**
3376
3377XXX
3378
3379**Arguments:**
3380
3381XXX
3382
3383**File:**
3384
3385XXX
3386
3387**Description:**
3388
3389XXX
3390
3391.. COMMENT: @page
3392
3393IMFS_eval_link()
3394~~~~~~~~~~~~~~~~
3395
3396**Corresponding Structure Element:**
3397
3398XXX
3399
3400**Arguments:**
3401
3402XXX
3403
3404**File:**
3405
3406XXX
3407
3408**Description:**
3409
3410XXX
3411
3412.. COMMENT: @page
3413
3414Regular File Handler Table Functions
3415------------------------------------
3416
3417Handler table functions are defined in a rtems_filesystem_file_handlers_r
3418structure. It defines functions that are specific to a node type in a given
3419filesystem. One table exists for each of the filesystem’s node types. The
3420structure definition appears below. It is followed by general developmental
3421information on each of the functions associated with regular files contained
3422in this function management structure.
3423.. code:: c
3424
3425    rtems_filesystem_file_handlers_r IMFS_memfile_handlers = {
3426    memfile_open,
3427    memfile_close,
3428    memfile_read,
3429    memfile_write,
3430    memfile_ioctl,
3431    memfile_lseek,
3432    IMFS_stat,
3433    IMFS_fchmod,
3434    memfile_ftruncate,
3435    NULL,                /* fpathconf \*/
3436    NULL,                /* fsync \*/
3437    IMFS_fdatasync,
3438    IMFS_fcntl
3439    };
3440
3441.. COMMENT: @page
3442
3443memfile_open() for Regular Files
3444~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3445
3446**Corresponding Structure Element:**
3447
3448memfile_open()
3449
3450**Arguments:**
3451
3452.. code:: c
3453
3454    rtems_libio_t   \*iop,
3455    const char      \*pathname,
3456    unsigned32       flag,
3457    unsigned32       mode
3458
3459**File:**
3460
3461memfile.c
3462
3463**Description:**
3464
3465Currently this function is a shell. No meaningful processing is performed and
3466a success code is always returned.
3467
3468.. COMMENT: @page
3469
3470memfile_close() for Regular Files
3471~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3472
3473**Corresponding Structure Element:**
3474
3475memfile_close()
3476
3477**Arguments:**
3478
3479.. code:: c
3480
3481    rtems_libio_t     \*iop
3482
3483**File:**
3484
3485memfile.c
3486
3487**Description:**
3488
3489This routine is a dummy for regular files under the base filesystem. It
3490performs a capture of the IMFS_jnode_t pointer from the file control block
3491and then immediately returns a success status.
3492
3493.. COMMENT: @page
3494
3495memfile_read() for Regular Files
3496~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3497
3498**Corresponding Structure Element:**
3499
3500memfile_read()
3501
3502**Arguments:**
3503
3504.. code:: c
3505
3506    rtems_libio_t     \*iop,
3507    void              \*buffer,
3508    unsigned32         count
3509
3510**File:**
3511
3512memfile.c
3513
3514**Description:**
3515
3516This routine will determine the ``jnode`` that is associated with this file.
3517
3518It will then call IMFS_memfile_read() with the ``jnode``, file position index,
3519buffer and transfer count as arguments.
3520
3521IMFS_memfile_read() will do the following:
3522
3523- Verify that the ``jnode`` is associated with a memory file
3524
3525- Verify that the destination of the read is valid
3526
3527- Adjust the length of the read if it is too long
3528
3529- Acquire data from the memory blocks associated with the file
3530
3531- Update the access time for the data in the file
3532
3533.. COMMENT: @page
3534
3535memfile_write() for Regular Files
3536~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3537
3538**Corresponding Structure Element:**
3539
3540XXX
3541
3542**Arguments:**
3543
3544XXX
3545
3546**File:**
3547
3548XXX
3549
3550**Description:**
3551
3552XXX
3553
3554.. COMMENT: @page
3555
3556memfile_ioctl() for Regular Files
3557~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3558
3559**Corresponding Structure Element:**
3560
3561XXX
3562
3563**Arguments:**
3564
3565.. code:: c
3566
3567    rtems_libio_t     \*iop,
3568    unsigned32       command,
3569    void              \*buffer
3570
3571**File:**
3572
3573memfile.c
3574
3575**Description:**
3576
3577The current code is a placeholder for future development. The routine returns
3578a successful completion status.
3579
3580.. COMMENT: @page
3581
3582memfile_lseek() for Regular Files
3583~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3584
3585**Corresponding Structure Element:**
3586
3587Memfile_lseek()
3588
3589**Arguments:**
3590
3591.. code:: c
3592
3593    rtems_libio_t     \*iop,
3594    off_t              offset,
3595    int                whence
3596
3597**File:**
3598
3599memfile.c
3600
3601**Description:**
3602
3603This routine make sure that the memory based file is sufficiently large to
3604allow for the new file position index.
3605
3606The IMFS_memfile_extend() function is used to evaluate the current size of
3607the memory file and allocate additional memory blocks if required by the new
3608file position index. A success code is always returned from this routine.
3609
3610.. COMMENT: @page
3611
3612IMFS_stat() for Regular Files
3613~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3614
3615**Corresponding Structure Element:**
3616
3617IMFS_stat()
3618
3619**Arguments:**
3620
3621.. code:: c
3622
3623    rtems_filesystem_location_info_t   \*loc,
3624    struct stat                        \*buf
3625
3626**File:**
3627
3628imfs_stat.c
3629
3630**Description:**
3631
3632This routine actually performs status processing for both devices and regular
3633files.
3634
3635The IMFS_jnode_t structure is referenced to determine the type of node under
3636the filesystem.
3637
3638If the node is associated with a device, node information is extracted and
3639transformed to set the st_dev element of the stat structure.
3640
3641If the node is a regular file, the size of the regular file is extracted from
3642the node.
3643
3644This routine rejects other node types.
3645
3646The following information is extracted from the node and placed in the stat
3647structure:
3648
3649- st_mode
3650
3651- st_nlink
3652
3653- st_ino
3654
3655- st_uid
3656
3657- st_gid
3658
3659- st_atime
3660
3661- st_mtime
3662
3663- st_ctime
3664
3665.. COMMENT: @page
3666
3667IMFS_fchmod() for Regular Files
3668~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3669
3670**Corresponding Structure Element:**
3671
3672IMFS_fchmod()
3673
3674**Arguments:**
3675
3676.. code:: c
3677
3678    rtems_libio_t     \*iop
3679    mode_t              mode
3680
3681**File:**
3682
3683imfs_fchmod.c
3684
3685**Description:**
3686
3687This routine will obtain the pointer to the IMFS_jnode_t structure from the
3688information currently in the file control block.
3689
3690Based on configuration the routine will acquire the user ID from a call to
3691getuid()  or from the IMFS_jnode_t structure.
3692
3693It then checks to see if we have the ownership rights to alter the mode of
3694the file.  If the caller does not, an error code is returned.
3695
3696An additional test is performed to verify that the caller is not trying to
3697alter the nature of the node. If the caller is attempting to alter more than
3698the permissions associated with user group and other, an error is returned.
3699
3700If all the preconditions are met, the user, group and other fields are set
3701based on the mode calling parameter.
3702
3703.. COMMENT: @page
3704
3705memfile_ftruncate() for Regular Files
3706~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3707
3708**Corresponding Structure Element:**
3709
3710XXX
3711
3712**Arguments:**
3713
3714XXX
3715
3716**File:**
3717
3718XXX
3719
3720**Description:**
3721
3722XXX
3723
3724No pathconf() for Regular Files
3725~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3726
3727**Corresponding Structure Element:**
3728
3729NULL
3730
3731**Arguments:**
3732
3733Not Implemented
3734
3735**File:**
3736
3737Not Implemented
3738
3739**Description:**
3740
3741Not Implemented
3742
3743.. COMMENT: @page
3744
3745No fsync() for Regular Files
3746~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3747
3748**Corresponding Structure Element:**
3749
3750XXX
3751
3752**Arguments:**
3753
3754XXX
3755
3756**File:**
3757
3758XXX
3759
3760**Description:**
3761
3762XXX
3763
3764.. COMMENT: @page
3765
3766IMFS_fdatasync() for Regular Files
3767~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3768
3769**Corresponding Structure Element:**
3770
3771XXX
3772
3773**Arguments:**
3774
3775XXX
3776
3777**File:**
3778
3779XXX
3780
3781**Description:**
3782
3783XXX
3784
3785.. COMMENT: @page
3786
3787Directory Handler Table Functions
3788---------------------------------
3789
3790Handler table functions are defined in a rtems_filesystem_file_handlers_r
3791structure. It defines functions that are specific to a node type in a given
3792filesystem. One table exists for each of the filesystem’s node types. The
3793structure definition appears below. It is followed by general developmental
3794information on each of the functions associated with directories contained in
3795this function management structure.
3796.. code:: c
3797
3798    rtems_filesystem_file_handlers_r IMFS_directory_handlers = {
3799    IMFS_dir_open,
3800    IMFS_dir_close,
3801    IMFS_dir_read,
3802    NULL,             /* write \*/
3803    NULL,             /* ioctl \*/
3804    IMFS_dir_lseek,
3805    IMFS_dir_fstat,
3806    IMFS_fchmod,
3807    NULL,             /* ftruncate \*/
3808    NULL,             /* fpathconf \*/
3809    NULL,             /* fsync \*/
3810    IMFS_fdatasync,
3811    IMFS_fcntl
3812    };
3813
3814.. COMMENT: @page
3815
3816IMFS_dir_open() for Directories
3817~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3818
3819**Corresponding Structure Element:**
3820
3821imfs_dir_open()
3822
3823**Arguments:**
3824
3825.. code:: c
3826
3827    rtems_libio_t  \*iop,
3828    const char     \*pathname,
3829    unsigned32      flag,
3830    unsigned32      mode
3831
3832**File:**
3833
3834imfs_directory.c
3835
3836**Description:**
3837
3838This routine will look into the file control block to find the ``jnode`` that
3839is associated with the directory.
3840
3841The routine will verify that the node is a directory. If its not a directory
3842an error code will be returned.
3843
3844If it is a directory, the offset in the file control block will be set to 0.
3845This allows us to start reading at the beginning of the directory.
3846
3847.. COMMENT: @page
3848
3849IMFS_dir_close() for Directories
3850~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3851
3852**Corresponding Structure Element:**
3853
3854imfs_dir_close()
3855
3856**Arguments:**
3857
3858.. code:: c
3859
3860    rtems_libio_t     \*iop
3861
3862**File:**
3863
3864imfs_directory.c
3865
3866**Description:**
3867
3868This routine is a dummy for directories under the base filesystem. It
3869immediately returns a success status.
3870
3871.. COMMENT: @page
3872
3873IMFS_dir_read() for Directories
3874~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3875
3876**Corresponding Structure Element:**
3877
3878imfs_dir_read
3879
3880**Arguments:**
3881
3882.. code:: c
3883
3884    rtems_libio_t  \*iop,
3885    void           \*buffer,
3886    unsigned32      count
3887
3888**File:**
3889
3890imfs_directory.c
3891
3892**Description:**
3893
3894This routine will read a fixed number of directory entries from the current
3895directory offset. The number of directory bytes read will be returned from
3896this routine.
3897
3898.. COMMENT: @page
3899
3900No write() for Directories
3901~~~~~~~~~~~~~~~~~~~~~~~~~~
3902
3903**Corresponding Structure Element:**
3904
3905XXX
3906
3907**Arguments:**
3908
3909XXX
3910
3911**File:**
3912
3913XXX
3914
3915**Description:**
3916
3917XXX
3918
3919.. COMMENT: @page
3920
3921No ioctl() for Directories
3922~~~~~~~~~~~~~~~~~~~~~~~~~~
3923
3924**Corresponding Structure Element:**
3925
3926ioctl
3927
3928**Arguments:**
3929
3930**File:**
3931
3932Not supported
3933
3934**Description:**
3935
3936XXX
3937
3938.. COMMENT: @page
3939
3940IMFS_dir_lseek() for Directories
3941~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3942
3943**Corresponding Structure Element:**
3944
3945imfs_dir_lseek()
3946
3947**Arguments:**
3948
3949.. code:: c
3950
3951    rtems_libio_t      \*iop,
3952    off_t               offset,
3953    int                 whence
3954
3955**File:**
3956
3957imfs_directory.c
3958
3959**Description:**
3960
3961This routine alters the offset in the file control block.
3962
3963No test is performed on the number of children under the current open
3964directory.  The imfs_dir_read() function protects against reads beyond the
3965current size to the directory by returning a 0 bytes transfered to the
3966calling programs whenever the file position index exceeds the last entry in
3967the open directory.
3968
3969.. COMMENT: @page
3970
3971IMFS_dir_fstat() for Directories
3972~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3973
3974**Corresponding Structure Element:**
3975
3976imfs_dir_fstat()
3977
3978**Arguments:**
3979
3980.. code:: c
3981
3982    rtems_filesystem_location_info_t   \*loc,
3983    struct stat                        \*buf
3984
3985**File:**
3986
3987imfs_directory.c
3988
3989**Description:**
3990
3991The node access information in the rtems_filesystem_location_info_t structure
3992is used to locate the appropriate IMFS_jnode_t structure. The following
3993information is taken from the IMFS_jnode_t structure and placed in the stat
3994structure:
3995
3996- st_ino
3997
3998- st_mode
3999
4000- st_nlink
4001
4002- st_uid
4003
4004- st_gid
4005
4006- st_atime
4007
4008- st_mtime
4009
4010- st_ctime
4011
4012The st_size field is obtained by running through the chain of directory
4013entries and summing the sizes of the dirent structures associated with each
4014of the children of the directory.
4015
4016.. COMMENT: @page
4017
4018IMFS_fchmod() for Directories
4019~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4020
4021**Corresponding Structure Element:**
4022
4023IMFS_fchmod()
4024
4025**Arguments:**
4026
4027.. code:: c
4028
4029    rtems_libio_t     \*iop
4030    mode_t             mode
4031
4032**File:**
4033
4034imfs_fchmod.c
4035
4036**Description:**
4037
4038This routine will obtain the pointer to the IMFS_jnode_t structure from the
4039information currently in the file control block.
4040
4041Based on configuration the routine will acquire the user ID from a call to
4042getuid()  or from the IMFS_jnode_t structure.
4043
4044It then checks to see if we have the ownership rights to alter the mode of
4045the file.  If the caller does not, an error code is returned.
4046
4047An additional test is performed to verify that the caller is not trying to
4048alter the nature of the node. If the caller is attempting to alter more than
4049the permissions associated with user group and other, an error is returned.
4050
4051If all the preconditions are met, the user, group and other fields are set
4052based on the mode calling parameter.
4053
4054.. COMMENT: @page
4055
4056No ftruncate() for Directories
4057~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4058
4059**Corresponding Structure Element:**
4060
4061XXX
4062
4063**Arguments:**
4064
4065XXX
4066
4067**File:**
4068
4069XXX
4070
4071**Description:**
4072
4073XXX
4074
4075.. COMMENT: @page
4076
4077No fpathconf() for Directories
4078~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4079
4080**Corresponding Structure Element:**
4081
4082fpathconf
4083
4084**Arguments:**
4085
4086Not Implemented
4087
4088**File:**
4089
4090Not Implemented
4091
4092**Description:**
4093
4094Not Implemented
4095
4096.. COMMENT: @page
4097
4098No fsync() for Directories
4099~~~~~~~~~~~~~~~~~~~~~~~~~~
4100
4101**Corresponding Structure Element:**
4102
4103XXX
4104
4105**Arguments:**
4106
4107XXX
4108
4109**File:**
4110
4111XXX
4112
4113**Description:**
4114
4115XXX
4116
4117.. COMMENT: @page
4118
4119IMFS_fdatasync() for Directories
4120~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4121
4122**Corresponding Structure Element:**
4123
4124XXX
4125
4126**Arguments:**
4127
4128XXX
4129
4130**File:**
4131
4132XXX
4133
4134**Description:**
4135
4136XXX
4137
4138.. COMMENT: @page
4139
4140Device Handler Table Functions
4141------------------------------
4142
4143Handler table functions are defined in a rtems_filesystem_file_handlers_r
4144structure. It defines functions that are specific to a node type in a given
4145filesystem. One table exists for each of the filesystem’s node types. The
4146structure definition appears below. It is followed by general developmental
4147information on each of the functions associated with devices contained in
4148this function management structure.
4149.. code:: c
4150
4151    typedef struct {
4152    rtems_filesystem_open_t           open;
4153    rtems_filesystem_close_t          close;
4154    rtems_filesystem_read_t           read;
4155    rtems_filesystem_write_t          write;
4156    rtems_filesystem_ioctl_t          ioctl;
4157    rtems_filesystem_lseek_t          lseek;
4158    rtems_filesystem_fstat_t          fstat;
4159    rtems_filesystem_fchmod_t         fchmod;
4160    rtems_filesystem_ftruncate_t      ftruncate;
4161    rtems_filesystem_fpathconf_t      fpathconf;
4162    rtems_filesystem_fsync_t          fsync;
4163    rtems_filesystem_fdatasync_t      fdatasync;
4164    } rtems_filesystem_file_handlers_r;
4165
4166.. COMMENT: @page
4167
4168device_open() for Devices
4169~~~~~~~~~~~~~~~~~~~~~~~~~
4170
4171**Corresponding Structure Element:**
4172
4173device_open()
4174
4175**Arguments:**
4176
4177.. code:: c
4178
4179    rtems_libio_t     \*iop,
4180    const char        \*pathname,
4181    unsigned32         flag,
4182    unsigned32         mode
4183
4184**File:**
4185
4186deviceio.c
4187
4188**Description:**
4189
4190This routine will use the file control block to locate the node structure for
4191the device.
4192
4193It will extract the major and minor device numbers from the ``jnode``.
4194
4195The major and minor device numbers will be used to make a rtems_io_open()
4196function call to open the device driver. An argument list is sent to the
4197driver that contains the file control block, flags and mode information.
4198
4199.. COMMENT: @page
4200
4201device_close() for Devices
4202~~~~~~~~~~~~~~~~~~~~~~~~~~
4203
4204**Corresponding Structure Element:**
4205
4206device_close()
4207
4208**Arguments:**
4209
4210.. code:: c
4211
4212    rtems_libio_t     \*iop
4213
4214**File:**
4215
4216deviceio.c
4217
4218**Description:**
4219
4220This routine extracts the major and minor device driver numbers from the
4221IMFS_jnode_t that is referenced in the file control block.
4222
4223It also forms an argument list that contains the file control block.
4224
4225A rtems_io_close() function call is made to close the device specified by the
4226major and minor device numbers.
4227
4228.. COMMENT: @page
4229
4230device_read() for Devices
4231~~~~~~~~~~~~~~~~~~~~~~~~~
4232
4233**Corresponding Structure Element:**
4234
4235device_read()
4236
4237**Arguments:**
4238
4239.. code:: c
4240
4241    rtems_libio_t     \*iop,
4242    void              \*buffer,
4243    unsigned32         count
4244
4245**File:**
4246
4247deviceio.c
4248
4249**Description:**
4250
4251This routine will extract the major and minor numbers for the device from the -
4252jnode- associated with the file descriptor.
4253
4254A rtems_io_read() call will be made to the device driver associated with the file
4255descriptor. The major and minor device number will be sent as arguments as well
4256as an argument list consisting of:
4257
4258- file control block
4259
4260- file position index
4261
4262- buffer pointer where the data read is to be placed
4263
4264- count indicating the number of bytes that the program wishes to read
4265  from the device
4266
4267- flags from the file control block
4268
4269On return from the rtems_io_read() the number of bytes that were actually
4270read will be returned to the calling program.
4271
4272.. COMMENT: @page
4273
4274device_write() for Devices
4275~~~~~~~~~~~~~~~~~~~~~~~~~~
4276
4277**Corresponding Structure Element:**
4278
4279XXX
4280
4281**Arguments:**
4282
4283XXX
4284
4285**File:**
4286
4287XXX
4288
4289**Description:**
4290
4291XXX
4292
4293.. COMMENT: @page
4294
4295device_ioctl() for Devices
4296~~~~~~~~~~~~~~~~~~~~~~~~~~
4297
4298**Corresponding Structure Element:**
4299
4300ioctl
4301
4302**Arguments:**
4303
4304.. code:: c
4305
4306    rtems_libio_t     \*iop,
4307    unsigned32         command,
4308    void              \*buffer
4309
4310**File:**
4311
4312deviceio.c
4313
4314**Description:**
4315
4316This handler will obtain status information about a device.
4317
4318The form of status is device dependent.
4319
4320The rtems_io_control() function uses the major and minor number of the device
4321to obtain the status information.
4322
4323rtems_io_control() requires an rtems_libio_ioctl_args_t argument list which
4324contains the file control block, device specific command and a buffer pointer
4325to return the device status information.
4326
4327The device specific command should indicate the nature of the information
4328that is desired from the device.
4329
4330After the rtems_io_control() is processed, the buffer should contain the
4331requested device information.
4332
4333If the device information is not obtained properly a -1 will be returned to
4334the calling program, otherwise the ioctl_return value is returned.
4335
4336.. COMMENT: @page
4337
4338device_lseek() for Devices
4339~~~~~~~~~~~~~~~~~~~~~~~~~~
4340
4341**Corresponding Structure Element:**
4342
4343device_lseek()
4344
4345**Arguments:**
4346
4347.. code:: c
4348
4349    rtems_libio_t     \*iop,
4350    off_t              offset,
4351    int                whence
4352
4353**File:**
4354
4355deviceio.c
4356
4357**Description:**
4358
4359At the present time this is a placeholder function. It always returns a
4360successful status.
4361
4362.. COMMENT: @page
4363
4364IMFS_stat() for Devices
4365~~~~~~~~~~~~~~~~~~~~~~~
4366
4367**Corresponding Structure Element:**
4368
4369IMFS_stat()
4370
4371**Arguments:**
4372
4373.. code:: c
4374
4375    rtems_filesystem_location_info_t   \*loc,
4376    struct stat                        \*buf
4377
4378**File:**
4379
4380imfs_stat.c
4381
4382**Description:**
4383
4384This routine actually performs status processing for both devices and regular files.
4385
4386The IMFS_jnode_t structure is referenced to determine the type of node under the
4387filesystem.
4388
4389If the node is associated with a device, node information is extracted and
4390transformed to set the st_dev element of the stat structure.
4391
4392If the node is a regular file, the size of the regular file is extracted from the node.
4393
4394This routine rejects other node types.
4395
4396The following information is extracted from the node and placed in the stat
4397structure:
4398
4399- st_mode
4400
4401- st_nlink
4402
4403- st_ino
4404
4405- st_uid
4406
4407- st_gid
4408
4409- st_atime
4410
4411- st_mtime
4412
4413- st_ctime
4414
4415.. COMMENT: @page
4416
4417IMFS_fchmod() for Devices
4418~~~~~~~~~~~~~~~~~~~~~~~~~
4419
4420**Corresponding Structure Element:**
4421
4422IMFS_fchmod()
4423
4424**Arguments:**
4425
4426.. code:: c
4427
4428    rtems_libio_t     \*iop
4429    mode_t             mode
4430
4431**File:**
4432
4433imfs_fchmod.c
4434
4435**Description:**
4436
4437This routine will obtain the pointer to the IMFS_jnode_t structure from the
4438information currently in the file control block.
4439
4440Based on configuration the routine will acquire the user ID from a call to
4441getuid()  or from the IMFS_jnode_t structure.
4442
4443It then checks to see if we have the ownership rights to alter the mode of
4444the file.  If the caller does not, an error code is returned.
4445
4446An additional test is performed to verify that the caller is not trying to
4447alter the nature of the node. If the caller is attempting to alter more than
4448the permissions associated with user group and other, an error is returned.
4449
4450If all the preconditions are met, the user, group and other fields are set
4451based on the mode calling parameter.
4452
4453.. COMMENT: @page
4454
4455No ftruncate() for Devices
4456~~~~~~~~~~~~~~~~~~~~~~~~~~
4457
4458**Corresponding Structure Element:**
4459
4460XXX
4461
4462**Arguments:**
4463
4464XXX
4465
4466**File:**
4467
4468XXX
4469
4470**Description:**
4471
4472XXX
4473
4474.. COMMENT: @page
4475
4476No fpathconf() for Devices
4477~~~~~~~~~~~~~~~~~~~~~~~~~~
4478
4479**Corresponding Structure Element:**
4480
4481fpathconf
4482
4483**Arguments:**
4484
4485Not Implemented
4486
4487**File:**
4488
4489Not Implemented
4490
4491**Description:**
4492
4493Not Implemented
4494
4495.. COMMENT: @page
4496
4497No fsync() for Devices
4498~~~~~~~~~~~~~~~~~~~~~~
4499
4500**Corresponding Structure Element:**
4501
4502XXX
4503
4504**Arguments:**
4505
4506XXX
4507
4508**File:**
4509
4510XXX
4511
4512**Description:**
4513
4514XXX
4515
4516.. COMMENT: @page
4517
4518No fdatasync() for Devices
4519~~~~~~~~~~~~~~~~~~~~~~~~~~
4520
4521Not Implemented
4522
4523**Corresponding Structure Element:**
4524
4525XXX
4526
4527**Arguments:**
4528
4529XXX
4530
4531**File:**
4532
4533XXX
4534
4535**Description:**
4536
4537XXX
4538
4539.. COMMENT: COPYRIGHT (c) 1988-2002.
4540
4541.. COMMENT: On-Line Applications Research Corporation (OAR).
4542
4543.. COMMENT: All rights reserved.
4544
4545Miniature In-Memory Filesystem
4546##############################
4547
4548This chapter describes the Miniature In-Memory FileSystem (miniIMFS).
4549The miniIMFS is a reduced feature version of the IMFS designed to
4550provide minimal functionality and have a low memory footprint.
4551
4552This chapter should be written after the IMFS chapter is completed
4553and describe the implementation of the mini-IMFS.
4554
4555.. COMMENT: COPYRIGHT (c) 1988-2002.
4556
4557.. COMMENT: On-Line Applications Research Corporation (OAR).
4558
4559.. COMMENT: All rights reserved.
4560
4561Trivial FTP Client Filesystem
4562#############################
4563
4564This chapter describes the Trivial FTP (TFTP) Client Filesystem.
4565
4566This chapter should be written after the IMFS chapter is completed
4567and describe the implementation of the TFTP.
4568
4569Command and Variable Index
4570##########################
4571
4572There are currently no Command and Variable Index entries.
4573
4574.. COMMENT: @printindex fn
4575
4576Concept Index
4577#############
4578
4579There are currently no Concept Index entries.
4580
4581.. COMMENT: @printindex cp
Note: See TracBrowser for help on using the repository browser.