source: rtems-docs/filesystem/fileystem_implmentation.rst

Last change on this file was e52906b, checked in by Sebastian Huber <sebastian.huber@…>, on 01/09/19 at 15:14:06

Simplify SPDX-License-Identifier comment

  • Property mode set to 100644
File size: 23.8 KB
Line 
1.. SPDX-License-Identifier: CC-BY-SA-4.0
2
3.. Copyright (C) 1988, 2002 On-Line Applications Research Corporation (OAR)
4
5Filesystem Implementation Requirements
6**************************************
7
8This chapter details the behavioral requirements that all filesystem
9implementations must adhere to.
10
11General
12=======
13
14The RTEMS filesystem framework was intended to be compliant with the POSIX
15Files and Directories interface standard. The following filesystem
16characteristics resulted in a functional switching layer.
17
18.. code-block:: shell
19
20    Figure of the Filesystem Functional Layering goes here.
21    This figure includes networking and disk caching layering.
22
23# Application programs are presented with a standard set of POSIX compliant
24  functions that allow them to interface with the files, devices and
25  directories in the filesystem. The interfaces to these routines do not
26  reflect the type of subordinate filesystem implementation in which the file
27  will be found.
28
29# The filesystem framework developed under RTEMS allows for mounting filesystem
30  of different types under the base filesystem.
31
32# The mechanics of locating file information may be quite different between
33  filesystem types.
34
35# The process of locating a file may require crossing filesystem boundaries.
36
37# The transitions between filesystem and the processing required to access
38  information in different filesystem is not visible at the level of the POSIX
39  function call.
40
41# The POSIX interface standard provides file access by character pathname to
42  the file in some functions and through an integer file descriptor in other
43  functions.
44
45# The nature of the integer file descriptor and its associated processing is
46  operating system and filesystem specific.
47
48# Directory and device information must be processed with some of the same
49  routines that apply to files.
50
51# The form and content of directory and device information differs greatly from
52  that of a regular file.
53
54# Files, directories and devices represent elements (nodes) of a tree
55  hierarchy.
56
57# The rules for processing each of the node types that exist under the
58  filesystem are node specific but are still not reflected in the POSIX
59  interface routines.
60
61.. code-block:: shell
62
63    Figure of the Filesystem Functional Layering goes here.
64    This figure focuses on the Base Filesystem and IMFS.
65
66.. code-block:: shell
67
68    Figure of the IMFS Memfile control blocks
69
70.. _file-and-directory-removal-constraints:
71
72File and Directory Removal Constraints
73======================================
74
75The following POSIX constraints must be honored by all filesystems.
76
77- If a node is a directory with children it cannot be removed.
78
79- The root node of any filesystem, whether the base filesystem or a mounted
80  filesystem, cannot be removed.
81
82- A node that is a directory that is acting as the mount point of a file system
83  cannot be removed.
84
85- On filesystems supporting hard links, a link count is maintained.  Prior to
86  node removal, the node's link count is decremented by one.  The link count
87  must be less than one to allow for removal of the node.
88
89API Layering
90============
91
92Mapping of Generic System Calls to Filesystem Specific Functions
93----------------------------------------------------------------
94
95The list of generic system calls includes the routines open(), read(), write(),
96close(), etc..
97
98The Files and Directories section of the POSIX Application Programs Interface
99specifies a set of functions with calling arguments that are used to gain
100access to the information in a filesystem. To the application program, these
101functions allow access to information in any mounted filesystem without
102explicit knowledge of the filesystem type or the filesystem mount
103configuration. The following are functions that are provided to the
104application:
105
106#. access()
107
108#. chdir()
109
110#. chmod()
111
112#. chown()
113
114#. close()
115
116#. closedir()
117
118#. fchmod()
119
120#. fcntl()
121
122#. fdatasync()
123
124#. fpathconf()
125
126#. fstat()
127
128#. fsync()
129
130#. ftruncate()
131
132#. link()
133
134#. lseek()
135
136#. mkdir()
137
138#. mknod()
139
140#. mount()
141
142#. open()
143
144#. opendir()
145
146#. pathconf()
147
148#. read()
149
150#. readdir()
151
152#. rewinddir()
153
154#. rmdir()
155
156#. rmnod()
157
158#. scandir()
159
160#. seekdir()
161
162#. stat()
163
164#. telldir()
165
166#. umask()
167
168#. unlink()
169
170#. unmount()
171
172#. utime()
173
174#. write()
175
176The filesystem's type as well as the node type within the filesystem determine
177the nature of the processing that must be performed for each of the functions
178above. The RTEMS filesystem provides a framework that allows new filesystem to
179be developed and integrated without alteration to the basic framework.
180
181To provide the functional switching that is required, each of the POSIX file
182and directory functions have been implemented as a shell function.  The shell
183function adheres to the POSIX interface standard. Within this functional shell,
184filesystem and node type information is accessed which is then used to invoke
185the appropriate filesystem and node type specific routine to process the POSIX
186function call.
187
188File/Device/Directory function access via file control block - rtems_libio_t structure
189--------------------------------------------------------------------------------------
190
191The POSIX open() function returns an integer file descriptor that is used as a
192reference to file control block information for a specific file. The file
193control block contains information that is used to locate node, file system,
194mount table and functional handler information. The diagram in Figure 8 depicts
195the relationship between and among the following components.
196
197File Descriptor Table:
198  This is an internal RTEMS structure that tracks all currently defined file
199  descriptors in the system. The index that is returned by the file open()
200  operation references a slot in this table. The slot contains a pointer to the
201  file descriptor table entry for this file. The rtems_libio_t structure
202  represents the file control block.
203
204Allocation of entry in the File Descriptor Table:
205  Access to the file descriptor table is controlled through a semaphore that is
206  implemented using the rtems_libio_allocate() function. This routine will grab
207  a semaphore and then scan the file control blocks to determine which slot is
208  free for use. The first free slot is marked as used and the index to this
209  slot is returned as the file descriptor for the open() request. After the
210  alterations have been made to the file control block table, the semaphore is
211  released to allow further operations on the table.
212
213  Maximum number of entries in the file descriptor table is configurable
214  through the src/exec/sapi/headers/confdefs.h file. If the
215  ``CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS`` constant is defined its value
216  will represent the maximum number of file descriptors that are allowed.  If
217  ``CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS`` is not specified a default value
218  of 20 will be used as the maximum number of file descriptors allowed.
219
220File control block - rtems_libio_t structure:
221  .. code-block:: c
222
223      struct rtems_libio_tt {
224          rtems_driver_name_t              *driver;
225          off_t                             size;
226          off_t                             offset;
227          unsigned32                        flags;
228          rtems_filesystem_location_info_t  pathinfo;
229          Objects_Id                        sem;
230          unsigned32                        data0;
231          void                              data1;
232          void                              file_info;
233          rtems_filesystem_file_handlers_r  handlers;
234      };
235
236  A file control block can exist for regular files, devices and directories.
237  The following fields are important for regular file and directory access:
238
239  - Size - For a file this represents the number of bytes currently stored in a
240    file. For a directory this field is not filled in.
241
242  - Offset - For a file this is the byte file position index relative to the
243    start of the file. For a directory this is the byte offset into a sequence
244    of dirent structures.
245
246  - Pathinfo - This is a structure that provides a pointer to node information,
247    OPS table functions, Handler functions and the mount table entry associated
248    with this node.
249
250  - file_info - A pointer to node information that is used by Handler functions
251
252  - handlers - A pointer to a table of handler functions that operate on a
253    file, device or directory through a file descriptor index
254
255File/Directory function access via rtems_filesystem_location_info_t structure
256-----------------------------------------------------------------------------
257
258The ``rtems_filesystem_location_info_tt`` structure below provides sufficient
259information to process nodes under a mounted filesystem.
260
261.. code-block:: c
262
263    struct rtems_filesystem_location_info_tt {
264        void                                     *node_access;
265        rtems_filesystem_file_handlers_r         *handlers;
266        rtems_filesystem_operations_table        *ops;
267        rtems_filesystem_mount_table_entry_t     *mt_entry;
268    };
269
270It contains a void pointer to filesystem specific nodal structure, pointers to
271the OPS table for the filesystem that contains the node, the node type specific
272handlers for the node and a reference pointer to the mount table entry
273associated with the filesystem containing the node
274
275Operation Tables
276================
277
278Filesystem specific operations are invoked indirectly.  The set of routines
279that implement the filesystem are configured into two tables.  The Filesystem
280Handler Table has routines that are specific to a filesystem but remain
281constant regardless of the actual file type.  The File Handler Table has
282routines that are both filesystem and file type specific.
283
284Filesystem Handler Table Functions
285----------------------------------
286
287OPS table functions are defined in a ``rtems_filesystem_operations_table``
288structure.  It defines functions that are specific to a given filesystem.  One
289table exists for each filesystem that is supported in the RTEMS
290configuration. The structure definition appears below and is followed by
291general developmental information on each of the functions contained in this
292function management structure.
293
294.. code-block:: c
295
296    typedef struct {
297        rtems_filesystem_evalpath_t        evalpath;
298        rtems_filesystem_evalmake_t        evalformake;
299        rtems_filesystem_link_t            link;
300        rtems_filesystem_unlink_t          unlink;
301        rtems_filesystem_node_type_t       node_type;
302        rtems_filesystem_mknod_t           mknod;
303        rtems_filesystem_rmnod_t           rmnod;
304        rtems_filesystem_chown_t           chown;
305        rtems_filesystem_freenode_t        freenod;
306        rtems_filesystem_mount_t           mount;
307        rtems_filesystem_fsmount_me_t      fsmount_me;
308        rtems_filesystem_unmount_t         unmount;
309        rtems_filesystem_fsunmount_me_t    fsunmount_me;
310        rtems_filesystem_utime_t           utime;
311        rtems_filesystem_evaluate_link_t   eval_link;
312        rtems_filesystem_symlink_t         symlink;
313    } rtems_filesystem_operations_table;
314
315evalpath Handler
316^^^^^^^^^^^^^^^^
317
318Corresponding Structure Element:
319    ``evalpath``
320
321Arguments:
322    .. code-block:: c
323
324        const char                        *pathname,      /* IN     */
325        int                                flags,         /* IN     */
326        rtems_filesystem_location_info_t  *pathloc        /* IN/OUT */
327
328Description:
329    This routine is responsible for evaluating the pathname passed in based
330    upon the flags and the valid ``rthems_filesystem_location_info_t``.
331    Additionally, it must make any changes to pathloc necessary to identify the
332    pathname node.  This should include calling the evalpath for a mounted
333    filesystem, if the given filesystem supports the mount command.
334
335    This routine returns a 0 if the evaluation was successful.  Otherwise, it
336    returns a -1 and sets errno to the correct error.
337
338    This routine is required and should NOT be set to NULL.
339
340evalformake Handler
341^^^^^^^^^^^^^^^^^^^
342
343Corresponding Structure Element:
344    ``evalformake``
345
346Arguments:
347    .. code-block:: c
348
349        const char                       *path,       /* IN */
350        rtems_filesystem_location_info_t *pathloc,    /* IN/OUT */
351        const char                      **name        /* OUT */
352
353Description:
354    This method is given a path to evaluate and a valid start location.  It is
355    responsible for finding the parent node for a requested make command,
356    setting pathloc information to identify the parent node, and setting the
357    name pointer to the first character of the name of the new node.
358    Additionally, if the filesystem supports the mount command, this method
359    should call the evalformake routine for the mounted filesystem.
360
361    This routine returns a 0 if the evaluation was successful.  Otherwise, it
362    returns a -1 and sets errno to the correct error.
363
364    This routine is required and should NOT be set to NULL.  However, if the
365    filesystem does not support user creation of a new node, it may set errno
366    to ENOSYS and return -1.
367
368link Handler
369^^^^^^^^^^^^
370
371Corresponding Structure Element:
372    ``link``
373
374Arguments:
375    .. code-block:: c
376
377        rtems_filesystem_location_info_t    *to_loc,      /* IN */
378        rtems_filesystem_location_info_t    *parent_loc,  /* IN */
379        const char                          *token        /* IN */
380
381Description:
382    This routine is used to create a hard-link.
383
384    It will first examine the st_nlink count of the node that we are trying to.
385    If the link count exceeds LINK_MAX an error will be returned.
386
387    The name of the link will be normalized to remove extraneous separators
388    from the end of the name.
389
390    This routine is not required and may be set to NULL.
391
392unlink Handler
393^^^^^^^^^^^^^^
394
395Corresponding Structure Element:
396    ``unlink``
397
398Arguments:
399    XXX
400
401Description:
402    XXX
403
404node_type Handler
405^^^^^^^^^^^^^^^^^
406
407Corresponding Structure Element:
408    ``node_type()``
409
410Arguments:
411    .. code-block:: c
412
413        rtems_filesystem_location_info_t    *pathloc        /* IN */
414
415Description:
416    XXX
417
418mknod Handler
419^^^^^^^^^^^^^
420
421Corresponding Structure Element:
422    ``mknod()``
423
424Arguments:
425    .. code-block:: c
426
427        const char                          *token,        /* IN */
428        mode_t                               mode,         /* IN */
429        dev_t                                dev,          /* IN */
430        rtems_filesystem_location_info_t    *pathloc       /* IN/OUT */
431
432Description:
433    XXX
434
435rmnod Handler
436^^^^^^^^^^^^^
437
438Corresponding Structure Element:
439    ``rmnod()``
440
441Arguments:
442    XXX
443
444Description:
445    XXX
446
447chown Handler
448^^^^^^^^^^^^^
449
450Corresponding Structure Element:
451    ``chown()``
452
453Arguments:
454    .. code-block:: c
455
456        rtems_filesystem_location_info_t    *pathloc        /* IN */
457        uid_t                                owner          /* IN */
458        gid_t                                group          /* IN */
459
460Description:
461    XXX
462
463freenod Handler
464^^^^^^^^^^^^^^^
465
466Corresponding Structure Element:
467    ``freenod()``
468
469Arguments:
470    .. code-block:: c
471
472        rtems_filesystem_location_info_t      *pathloc       /* IN */
473
474Description:
475    This routine is used by the generic code to allow memory to be allocated
476    during the evaluate routines, and set free when the generic code is
477    finished accessing a node.  If the evaluate routines allocate memory to
478    identify a node this routine should be utilized to free that memory.
479
480    This routine is not required and may be set to NULL.
481
482mount Handler
483^^^^^^^^^^^^^
484
485Corresponding Structure Element:
486    ``mount()``
487
488Arguments:
489    .. code-block:: c
490
491        rtems_filesystem_mount_table_entry_t   *mt_entry
492
493Description:
494    XXX
495
496fsmount_me Handler
497^^^^^^^^^^^^^^^^^^
498
499Corresponding Structure Element:
500    ``imfs_fsmount_me``
501
502Arguments:
503    .. code-block:: c
504
505        rtems_filesystem_mount_table_entry_t   *mt_entry
506
507Description:
508    This function is provided with a filesystem to take care of the internal
509    filesystem management details associated with mounting that filesystem
510    under the RTEMS environment.
511
512    It is not responsible for the mounting details associated the filesystem
513    containing the mount point.
514
515    The rtems_filesystem_mount_table_entry_t structure contains the key
516    elements below:
517
518    .. code-block:: c
519
520        rtems_filesystem_location_info_t         *mt_point_node,
521
522    This structure contains information about the mount point. This allows us
523    to find the ops-table and the handling functions associated with the
524    filesystem containing the mount point.
525
526    .. code-block:: c
527
528        rtems_filesystem_location_info_t         *fs_root_node,
529
530    This structure contains information about the root node in the file system
531    to be mounted. It allows us to find the ops-table and the handling
532    functions associated with the filesystem to be mounted.
533
534    .. code-block:: c
535
536    rtems_filesystem_options_t                 options,
537
538    Read only or read/write access
539
540    .. code-block:: c
541
542        void                                         *fs_info,
543
544    This points to an allocated block of memory the will be used to hold any
545    filesystem specific information of a global nature. This allocated region
546    if important because it allows us to mount the same filesystem type more
547    than once under the RTEMS system.  Each instance of the mounted filesystem
548    has its own set of global management information that is separate from the
549    global management information associated with the other instances of the
550    mounted filesystem type.
551
552    .. code-block:: c
553
554        rtems_filesystem_limits_and_options_t    pathconf_info,
555
556    The table contains the following set of values associated with the mounted
557    filesystem:
558
559    - link_max
560
561    - max_canon
562
563    - max_input
564
565    - name_max
566
567    - path_max
568
569    - pipe_buf
570
571    - posix_async_io
572
573    - posix_chown_restrictions
574
575    - posix_no_trunc
576
577    - posix_prio_io
578
579    - posix_sync_io
580
581    - posix_vdisable
582
583    These values are accessed with the pathconf() and the fpathconf () functions.
584
585    .. code-block:: c
586
587        const char                                   *dev
588
589    The is intended to contain a string that identifies the device that
590    contains the filesystem information. The filesystems that are currently
591    implemented are memory based and don't require a device specification.
592
593    If the mt_point_node.node_access is NULL then we are mounting the base file
594    system.
595
596    The routine will create a directory node for the root of the IMFS file
597    system.
598
599    The node will have read, write and execute permissions for owner, group and
600    others.
601
602    The node's name will be a null string.
603
604    A filesystem information structure(fs_info) will be allocated and
605    initialized for the IMFS filesystem. The fs_info pointer in the mount table
606    entry will be set to point the filesystem information structure.
607
608    The pathconf_info element of the mount table will be set to the appropriate
609    table of path configuration constants (LIMITS_AND_OPTIONS).
610
611    The fs_root_node structure will be filled in with the following:
612
613    - pointer to the allocated root node of the filesystem
614
615    - directory handlers for a directory node under the IMFS filesystem
616
617    - OPS table functions for the IMFS
618
619    A 0 will be returned to the calling routine if the process succeeded,
620    otherwise a 1 will be returned.
621
622unmount Handler
623^^^^^^^^^^^^^^^
624
625Corresponding Structure Element:
626    XXX
627
628Arguments:
629    XXX
630
631Description:
632    XXX
633
634fsunmount_me Handler
635^^^^^^^^^^^^^^^^^^^^
636
637Corresponding Structure Element:
638    ``imfs_fsunmount_me()``
639
640Arguments:
641    .. code-block:: c
642
643        rtems_filesystem_mount_table_entry_t   *mt_entry
644
645Description:
646    XXX
647
648utime Handler
649^^^^^^^^^^^^^
650
651Corresponding Structure Element:
652    XXX
653
654Arguments:
655    XXX
656
657Description:
658    XXX
659
660eval_link Handler
661^^^^^^^^^^^^^^^^^
662
663Corresponding Structure Element:
664    XXX
665
666Arguments:
667    XXX
668
669Description:
670    XXX
671
672symlink Handler
673^^^^^^^^^^^^^^^
674
675Corresponding Structure Element:
676    XXX
677
678Arguments:
679    XXX
680
681Description:
682    XXX
683
684File Handler Table Functions
685----------------------------
686
687Handler table functions are defined in a ``rtems_filesystem_file_handlers_r``
688structure. It defines functions that are specific to a node type in a given
689filesystem. One table exists for each of the filesystem's node types. The
690structure definition appears below. It is followed by general developmental
691information on each of the functions associated with regular files contained in
692this function management structure.
693
694.. code-block:: c
695
696    typedef struct {
697        rtems_filesystem_open_t           open;
698        rtems_filesystem_close_t          close;
699        rtems_filesystem_read_t           read;
700        rtems_filesystem_write_t          write;
701        rtems_filesystem_ioctl_t          ioctl;
702        rtems_filesystem_lseek_t          lseek;
703        rtems_filesystem_fstat_t          fstat;
704        rtems_filesystem_fchmod_t         fchmod;
705        rtems_filesystem_ftruncate_t      ftruncate;
706        rtems_filesystem_fpathconf_t      fpathconf;
707        rtems_filesystem_fsync_t          fsync;
708        rtems_filesystem_fdatasync_t      fdatasync;
709        rtems_filesystem_fcntl_t          fcntl;
710    } rtems_filesystem_file_handlers_r;
711
712open Handler
713^^^^^^^^^^^^
714
715Corresponding Structure Element:
716    ``open()``
717
718Arguments:
719    .. code-block:: c
720
721        rtems_libio_t   *iop,
722        const char      *pathname,
723        unsigned32       flag,
724        unsigned32       mode
725
726Description:
727    XXX
728
729close Handler
730~~~~~~~~~~~~~
731
732Corresponding Structure Element:
733    ``close()``
734
735Arguments:
736    .. code-block:: c
737
738        rtems_libio_t     *iop
739
740Description:
741    XXX
742
743NOTES:
744    XXX
745
746read Handler
747~~~~~~~~~~~~
748
749Corresponding Structure Element:
750    ``read()``
751
752Arguments:
753    .. code-block:: c
754
755        rtems_libio_t     *iop,
756        void              *buffer,
757        unsigned32         count
758
759Description:
760    XXX
761
762NOTES:
763    XXX
764
765write Handler
766~~~~~~~~~~~~~
767
768Corresponding Structure Element:
769    XXX
770
771Arguments:
772    XXX
773
774Description:
775    XXX
776
777NOTES:
778    XXX
779
780ioctl Handler
781~~~~~~~~~~~~~
782
783Corresponding Structure Element:
784    XXX
785
786Arguments:
787    .. code-block:: c
788
789        rtems_libio_t     *iop,
790        unsigned32       command,
791        void              *buffer
792
793Description:
794    XXX
795
796NOTES:
797    XXX
798
799lseek Handler
800~~~~~~~~~~~~~
801
802Corresponding Structure Element:
803    ``lseek()``
804
805Arguments:
806    .. code-block:: c
807
808        rtems_libio_t     *iop,
809        off_t              offset,
810        int                whence
811
812Description:
813    XXX
814
815NOTES:
816    XXX
817
818fstat Handler
819~~~~~~~~~~~~~
820
821Corresponding Structure Element:
822    ``fstat()``
823
824Arguments:
825    .. code-block:: c
826
827        rtems_filesystem_location_info_t   *loc,
828        struct stat                        *buf
829
830Description:
831    The following information is extracted from the filesystem specific node
832    and placed in the ``stat`` structure:
833
834    - st_mode
835
836    - st_nlink
837
838    - st_ino
839
840    - st_uid
841
842    - st_gid
843
844    - st_atime
845
846    - st_mtime
847
848    - st_ctime
849
850NOTES:
851    Both the ``stat()`` and ``lstat()`` services are implemented directly using
852    the ``fstat()`` handler.  The difference in behavior is determined by how
853    the path is evaluated prior to this handler being called on a particular
854    file entity.
855
856    The ``fstat()`` system call is implemented directly on top of this
857    filesystem handler.
858
859fchmod Handler
860~~~~~~~~~~~~~~
861
862Corresponding Structure Element:
863    ``fchmod()``
864
865Arguments:
866    .. code-block:: c
867
868        rtems_libio_t     *iop
869        mode_t             mode
870
871Description:
872    XXX
873
874NOTES:
875    XXX
876
877ftruncate Handler
878~~~~~~~~~~~~~~~~~
879
880Corresponding Structure Element:
881    XXX
882
883Arguments:
884    XXX
885
886Description:
887    XXX
888
889NOTES:
890    XXX
891
892fpathconf Handler
893~~~~~~~~~~~~~~~~~
894
895Corresponding Structure Element:
896    XXX
897
898Arguments:
899    XXX
900
901Description:
902    XXX
903
904NOTES:
905    XXX
906
907fsync Handler
908~~~~~~~~~~~~~
909
910Corresponding Structure Element:
911    XXX
912
913Arguments:
914    XXX
915
916Description:
917    XXX
918
919NOTES:
920    XXX
921
922fdatasync Handler
923~~~~~~~~~~~~~~~~~
924
925Corresponding Structure Element:
926    XXX
927
928Arguments:
929    XXX
930
931Description:
932    XXX
933
934NOTES:
935    XXX
936
937fcntl Handler
938~~~~~~~~~~~~~
939
940Corresponding Structure Element:
941    XXX
942
943Arguments:
944    XXX
945
946Description:
947    XXX
948
949NOTES:
950    XXX
Note: See TracBrowser for help on using the repository browser.