1 | @c |
---|
2 | |
---|
3 | @c COPYRIGHT (c) 1988-1998. |
---|
4 | @c On-Line Applications Research Corporation (OAR). |
---|
5 | @c All rights reserved. |
---|
6 | @c |
---|
7 | @c $Id$ |
---|
8 | @c |
---|
9 | |
---|
10 | |
---|
11 | @chapter Applications and Functional Layering |
---|
12 | |
---|
13 | @section General |
---|
14 | |
---|
15 | The RTEMS file system framework was intended to be compliant with the POSIX |
---|
16 | Files and Directories interface standard. The following file system characteristics |
---|
17 | resulted in a functional switching layer (See figures 6 and 7). |
---|
18 | |
---|
19 | |
---|
20 | @example |
---|
21 | Figure 6 |
---|
22 | @end example |
---|
23 | |
---|
24 | @enumerate |
---|
25 | |
---|
26 | @item Application programs are presented with a standard set of POSIX compliant |
---|
27 | functions that allow them to interface with the files, devices and directories in the |
---|
28 | file system. The interfaces to these routines do not reflect the type of subordinate |
---|
29 | file system implementation in which the file will be found. |
---|
30 | |
---|
31 | @item The file system framework developed under RTEMS allows for mounting file |
---|
32 | systems of different types under the base file system.( Figure 3 ) |
---|
33 | |
---|
34 | @item The mechanics of locating file information may be quite different between file |
---|
35 | system types. |
---|
36 | |
---|
37 | @item The process of locating a file may require crossing file system boundaries. |
---|
38 | |
---|
39 | @item The transitions between file systems and the processing required to access |
---|
40 | information in different file systems is not visible at the level of the POSIX |
---|
41 | function call. |
---|
42 | |
---|
43 | @item The POSIX interface standard provides file access by character pathname to the |
---|
44 | file in some functions and through an integer file descriptor (Figure 8) in other |
---|
45 | functions. |
---|
46 | |
---|
47 | @item The nature of the integer file descriptor and its associated processing is operating |
---|
48 | system and file system specific. |
---|
49 | |
---|
50 | @item Directory and device information must be processed with some of the same |
---|
51 | routines that apply to files. |
---|
52 | |
---|
53 | @item The form and content of directory and device information differs greatly from that |
---|
54 | of a regular file. |
---|
55 | |
---|
56 | @item Files, directories and devices represent elements (nodes) of a tree hierarchy. |
---|
57 | |
---|
58 | @item The rules for processing each of the node types that exist under the file system are |
---|
59 | node specific but are still not reflected in the POSIX interface routines. |
---|
60 | |
---|
61 | @end enumerate |
---|
62 | |
---|
63 | |
---|
64 | @example |
---|
65 | Figure 7 |
---|
66 | @end example |
---|
67 | |
---|
68 | |
---|
69 | |
---|
70 | |
---|
71 | |
---|
72 | @example |
---|
73 | Figure 8 |
---|
74 | @end example |
---|
75 | |
---|
76 | |
---|
77 | |
---|
78 | |
---|
79 | |
---|
80 | |
---|
81 | @section Mapping of Generic System Calls to File System Specific OP Table or Handler Functions |
---|
82 | |
---|
83 | @subsection Generic routines (open (), read (), write (), close (), . ) |
---|
84 | |
---|
85 | The Files and Directories section of the POSIX Application Programs Interface |
---|
86 | specifies a set of functions with calling arguments that are used to gain access to the |
---|
87 | information in a file system. To the application program, these functions allow access |
---|
88 | to information in any mounted file system without explicit knowledge of the file |
---|
89 | system type or the file system mount configuration. The following are functions that |
---|
90 | are provided to the application: |
---|
91 | |
---|
92 | @enumerate |
---|
93 | @item access() |
---|
94 | @item chdir() |
---|
95 | @item chmod() |
---|
96 | @item chown() |
---|
97 | @item close() |
---|
98 | @item closedir() |
---|
99 | @item fchmod() |
---|
100 | @item fcntl() |
---|
101 | @item fdatasync() |
---|
102 | @item fpathconf() |
---|
103 | @item fstat() |
---|
104 | @item fsync() |
---|
105 | @item ftruncate() |
---|
106 | @item link() |
---|
107 | @item lseek() |
---|
108 | @item mkdir() |
---|
109 | @item mknod() |
---|
110 | @item mount() |
---|
111 | @item open() |
---|
112 | @item opendir() |
---|
113 | @item pathconf() |
---|
114 | @item read() |
---|
115 | @item readdir() |
---|
116 | @item rewinddir() |
---|
117 | @item rmdir() |
---|
118 | @item rmnod() |
---|
119 | @item scandir() |
---|
120 | @item seekdir() |
---|
121 | @item stat() |
---|
122 | @item telldir() |
---|
123 | @item umask() |
---|
124 | @item unlink() |
---|
125 | @item unmount() |
---|
126 | @item utime() |
---|
127 | @item write() |
---|
128 | @end enumerate |
---|
129 | |
---|
130 | The file system's type as well as the node type within the file system determine the |
---|
131 | nature of the processing that must be performed for each of the functions above. The |
---|
132 | RTEMS file system provides a framework that allows new file systems to be |
---|
133 | developed and integrated without alteration to the basic framework. |
---|
134 | |
---|
135 | ? Use of function pointers for functional redirection |
---|
136 | To provide the functional switching that is required, each of the POSIX file and |
---|
137 | directory functions have been implemented as a shell function. The shell function |
---|
138 | adheres to the POSIX interface standard. Within this functional shell, file system and |
---|
139 | node type information is accessed which is then used to invoke the appropriate file |
---|
140 | system and node type specific routine to process the POSIX function call. |
---|
141 | |
---|
142 | ? File/Device/Directory function access via file control block - rtems_libio_t |
---|
143 | structure |
---|
144 | The POSIX open() function returns an integer file descriptor that is used as a |
---|
145 | reference to file control block information for a specific file. The file control block |
---|
146 | contains information that is used to locate node, file system, mount table and |
---|
147 | functional handler information. The diagram in Figure 8 depicts the relationship |
---|
148 | between and among the following components. |
---|
149 | |
---|
150 | 1. File Descriptor Table - This is an internal RTEMS structure that tracks all |
---|
151 | currently defined file descriptors in the system. The index that is returned by |
---|
152 | the file open() operation references a slot in this table. The slot contains a |
---|
153 | pointer to the file descriptor table entry for this file. The rtems_libio_t |
---|
154 | structure represents the file control block. |
---|
155 | 2. Allocation of entry in the File Descriptor Table - Access to the file descriptor |
---|
156 | table is controlled through a semaphore that is implemented using the |
---|
157 | rtems_libio_allocate() function. This routine will grab a semaphore and then |
---|
158 | scan the file control blocks to determine which slot is free for use. The first |
---|
159 | free slot is marked as used and the index to this slot is returned as the file |
---|
160 | descriptor for the open () request. After the alterations have been made to the |
---|
161 | file control block table, the semaphore is released to allow further operations |
---|
162 | on the table. |
---|
163 | 3. Maximum number of entries in the file descriptor table is configurable |
---|
164 | through the src/exec/sapi/headers/confdefs.h file. If the |
---|
165 | CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS constant is |
---|
166 | defined its value will represent the maximum number of file descriptors that |
---|
167 | are allowed. |
---|
168 | If CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS is not |
---|
169 | specified a default value of 20 will be used as the maximum number of file |
---|
170 | descriptors allowed. |
---|
171 | 4. File control block - rtems_libio_t structure |
---|
172 | struct rtems_libio_tt @{ |
---|
173 | rtems_driver_name_t *driver; |
---|
174 | off_t size; /* size of file */ |
---|
175 | off_t offset; /* current offset into file */ |
---|
176 | unsigned32 flags; |
---|
177 | rtems_filesystem_location_info_t pathinfo; |
---|
178 | Objects_Id sem; |
---|
179 | unsigned32 data0; /* private to "driver" */ |
---|
180 | void data1; / . */ |
---|
181 | void file_info; /used by file handlers/ |
---|
182 | rtems_filesystem_file_handlers_r handlers; /type specific handlers/ |
---|
183 | @}; |
---|
184 | |
---|
185 | A file control block can exist for regular files, devices and directories. The |
---|
186 | following fields are important for regular file and directory access: |
---|
187 | ? Size - For a file this represents the number of bytes currently stored in |
---|
188 | a file. For a directory this field is not filled in. |
---|
189 | ? Offset - For a file this is the byte file position index relative to the start |
---|
190 | of the file. For a directory this is the byte offset into a sequence of |
---|
191 | dirent structures. |
---|
192 | ? Pathinfo - This is a structure that provides a pointer to node |
---|
193 | information, OPS table functions, Handler functions and the mount |
---|
194 | table entry associated with this node. |
---|
195 | ? file_info - A pointer to node information that is used by Handler |
---|
196 | functions |
---|
197 | ? handlers - A pointer to a table of handler functions that operate on a |
---|
198 | file, device or directory through a file descriptor index |
---|
199 | |
---|
200 | ? File/Directory function access via rtems_filesystem_location_info_t structure |
---|
201 | |
---|
202 | The rtems_filesystem_location_info_tt structure below provides sufficient |
---|
203 | information to process nodes under a mounted file system. |
---|
204 | |
---|
205 | struct rtems_filesystem_location_info_tt |
---|
206 | @{ |
---|
207 | void *node_access; |
---|
208 | rtems_filesystem_file_handlers_r *handlers; |
---|
209 | rtems_filesystem_operations_table *ops; |
---|
210 | rtems_filesystem_mount_table_entry_t *mt_entry; |
---|
211 | @}; |
---|
212 | |
---|
213 | It contains a void pointer to file system specific nodal structure, pointers to the |
---|
214 | OPS table for the file system that contains the node, the node type specific |
---|
215 | handlers for the node and a reference pointer to the mount table entry associated |
---|
216 | with the file system containing the node |
---|
217 | |
---|
218 | ? File System Functional Interface to Files and Directories |
---|
219 | ? Access using relative or absolute path names to file |
---|
220 | ? OP Table for File System - rtems_filesystem_operations_table |
---|
221 | 1. evalpath () |
---|
222 | 2. evalformake () |
---|
223 | 3. link () |
---|
224 | 4. unlink () |
---|
225 | 5. node_type () |
---|
226 | 6. mknod () |
---|
227 | 7. rmnod () |
---|
228 | 8. chown () |
---|
229 | 9. freenod () |
---|
230 | 10. mount () |
---|
231 | 11. fsmount_me () |
---|
232 | 12. unmount () |
---|
233 | 13. fsunmount_me () |
---|
234 | 14. utime () |
---|
235 | 15. eval_link () |
---|
236 | 16. symlink () |
---|
237 | 17. readlink () |
---|
238 | |
---|
239 | ? Access using file handle |
---|
240 | ? Handlers for file system node types ( regular file, directories, and devices ) - |
---|
241 | rtems_filesystem_file_handlers_r |
---|
242 | 1. open () |
---|
243 | 2. close () |
---|
244 | 3. read () |
---|
245 | 4. write () |
---|
246 | 5. ioctl () |
---|
247 | 6. lseek () |
---|
248 | 7. fstat () |
---|
249 | 8. fchmod () |
---|
250 | 9. ftruncate () |
---|
251 | 10. fpathconf () |
---|
252 | 11. fsync () |
---|
253 | 12. fdatasync () |
---|
254 | |
---|
255 | |
---|
256 | |
---|
257 | ? POSIX Directory Access Functions |
---|
258 | |
---|
259 | BSD/newlib has provided a set of POSIX directory access routines. These routines |
---|
260 | allow directories to be open and the entries under the directory read. The getdents |
---|
261 | routine allows for customization of the BSD routines to a particular file system |
---|
262 | implementation. Some of the original BSD routines were modified, but maintain the |
---|
263 | same calling interface as the original BSD/newlib routine. |
---|
264 | The following directory access routines are included in the BSD set: |
---|
265 | |
---|
266 | ? opendir ()closedir () |
---|
267 | ? readdir () |
---|
268 | ? getdents () |
---|
269 | ? closedir () |
---|
270 | ? *** rewinddir () |
---|
271 | ? scandir () (built on fstat () ) |
---|
272 | ? *** seekdir () |
---|
273 | ? telldir () |
---|
274 | |
---|
275 | *** Not the original BSD stuff |
---|
276 | |
---|
277 | |
---|
278 | Jennifer will fill this section in. |
---|
279 | |
---|
280 | |
---|