1 | /* SPDX-License-Identifier: BSD-2-Clause */ |
---|
2 | |
---|
3 | /** |
---|
4 | * @file |
---|
5 | * |
---|
6 | * @ingroup LibIO |
---|
7 | * |
---|
8 | * @brief Basic IO API |
---|
9 | * |
---|
10 | * This file contains the support infrastructure used to manage the |
---|
11 | * table of integer style file descriptors used by the low level |
---|
12 | * POSIX system calls like open(), read, fstat(), etc. |
---|
13 | */ |
---|
14 | |
---|
15 | /* |
---|
16 | * COPYRIGHT (C) 1989, 2021 On-Line Applications Research Corporation (OAR). |
---|
17 | * |
---|
18 | * Modifications to support reference counting in the file system are |
---|
19 | * Copyright (C) 2012 embedded brains GmbH & Co. KG |
---|
20 | * |
---|
21 | * Redistribution and use in source and binary forms, with or without |
---|
22 | * modification, are permitted provided that the following conditions |
---|
23 | * are met: |
---|
24 | * 1. Redistributions of source code must retain the above copyright |
---|
25 | * notice, this list of conditions and the following disclaimer. |
---|
26 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
27 | * notice, this list of conditions and the following disclaimer in the |
---|
28 | * documentation and/or other materials provided with the distribution. |
---|
29 | * |
---|
30 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
31 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
32 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
33 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
---|
34 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
35 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
36 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
37 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
38 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
39 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
40 | * POSSIBILITY OF SUCH DAMAGE. |
---|
41 | */ |
---|
42 | |
---|
43 | #ifndef _RTEMS_RTEMS_LIBIO_H |
---|
44 | #define _RTEMS_RTEMS_LIBIO_H |
---|
45 | |
---|
46 | #include <sys/types.h> |
---|
47 | #include <sys/stat.h> |
---|
48 | #include <sys/ioccom.h> |
---|
49 | #include <sys/statvfs.h> |
---|
50 | #include <sys/uio.h> |
---|
51 | |
---|
52 | #include <unistd.h> |
---|
53 | #include <termios.h> |
---|
54 | |
---|
55 | #include <rtems.h> |
---|
56 | #include <rtems/fs.h> |
---|
57 | #include <rtems/chain.h> |
---|
58 | #include <rtems/score/atomic.h> |
---|
59 | #include <rtems/termiosdevice.h> |
---|
60 | |
---|
61 | #ifdef __cplusplus |
---|
62 | extern "C" { |
---|
63 | #endif |
---|
64 | |
---|
65 | struct knote; |
---|
66 | |
---|
67 | /** |
---|
68 | * @defgroup LibIOFSOps File System Operations |
---|
69 | * |
---|
70 | * @ingroup LibIO |
---|
71 | * |
---|
72 | * @brief File system operations. |
---|
73 | */ |
---|
74 | /**@{**/ |
---|
75 | |
---|
76 | /** |
---|
77 | * @brief Locks a file system instance. |
---|
78 | * |
---|
79 | * This lock must allow nesting. |
---|
80 | * |
---|
81 | * @param[in, out] mt_entry The mount table entry of the file system instance. |
---|
82 | * |
---|
83 | * @see rtems_filesystem_default_lock(). |
---|
84 | */ |
---|
85 | typedef void (*rtems_filesystem_mt_entry_lock_t)( |
---|
86 | const rtems_filesystem_mount_table_entry_t *mt_entry |
---|
87 | ); |
---|
88 | |
---|
89 | /** |
---|
90 | * @brief Unlocks a file system instance. |
---|
91 | * |
---|
92 | * @param[in, out] mt_entry The mount table entry of the file system instance. |
---|
93 | * |
---|
94 | * @see rtems_filesystem_default_unlock(). |
---|
95 | */ |
---|
96 | typedef void (*rtems_filesystem_mt_entry_unlock_t)( |
---|
97 | const rtems_filesystem_mount_table_entry_t *mt_entry |
---|
98 | ); |
---|
99 | |
---|
100 | /** |
---|
101 | * @brief Path evaluation context. |
---|
102 | */ |
---|
103 | typedef struct { |
---|
104 | /** |
---|
105 | * The contents of the remaining path to be evaluated. |
---|
106 | */ |
---|
107 | const char *path; |
---|
108 | |
---|
109 | /** |
---|
110 | * The length of the remaining path to be evaluated. |
---|
111 | */ |
---|
112 | size_t pathlen; |
---|
113 | |
---|
114 | /** |
---|
115 | * The contents of the token to be evaluated with respect to the current |
---|
116 | * location. |
---|
117 | */ |
---|
118 | const char *token; |
---|
119 | |
---|
120 | /** |
---|
121 | * The length of the token to be evaluated with respect to the current |
---|
122 | * location. |
---|
123 | */ |
---|
124 | size_t tokenlen; |
---|
125 | |
---|
126 | /** |
---|
127 | * The path evaluation is controlled by the following flags |
---|
128 | * - RTEMS_FS_PERMS_READ, |
---|
129 | * - RTEMS_FS_PERMS_WRITE, |
---|
130 | * - RTEMS_FS_PERMS_EXEC, |
---|
131 | * - RTEMS_FS_FOLLOW_HARD_LINK, |
---|
132 | * - RTEMS_FS_FOLLOW_SYM_LINK, |
---|
133 | * - RTEMS_FS_MAKE, |
---|
134 | * - RTEMS_FS_EXCLUSIVE, |
---|
135 | * - RTEMS_FS_ACCEPT_RESIDUAL_DELIMITERS, and |
---|
136 | * - RTEMS_FS_REJECT_TERMINAL_DOT. |
---|
137 | */ |
---|
138 | int flags; |
---|
139 | |
---|
140 | /** |
---|
141 | * Symbolic link evaluation is a recursive operation. This field helps to |
---|
142 | * limit the recursion level and thus prevents a stack overflow. The |
---|
143 | * recursion level is limited by RTEMS_FILESYSTEM_SYMLOOP_MAX. |
---|
144 | */ |
---|
145 | int recursionlevel; |
---|
146 | |
---|
147 | /** |
---|
148 | * This is the current file system location of the evaluation process. |
---|
149 | * Tokens are evaluated with respect to the current location. The token |
---|
150 | * interpretation may change the current location. The purpose of the path |
---|
151 | * evaluation is to change the start location into a final current location |
---|
152 | * according to the path. |
---|
153 | */ |
---|
154 | rtems_filesystem_location_info_t currentloc; |
---|
155 | |
---|
156 | /** |
---|
157 | * The location of the root directory of the user environment during the |
---|
158 | * evaluation start. |
---|
159 | */ |
---|
160 | rtems_filesystem_global_location_t *rootloc; |
---|
161 | |
---|
162 | /** |
---|
163 | * The start location of the evaluation process. The start location my |
---|
164 | * change during symbolic link evaluation. |
---|
165 | */ |
---|
166 | rtems_filesystem_global_location_t *startloc; |
---|
167 | } rtems_filesystem_eval_path_context_t; |
---|
168 | |
---|
169 | /** |
---|
170 | * @brief Path evaluation. |
---|
171 | * |
---|
172 | * @param[in, out] ctx The path evaluation context. |
---|
173 | * |
---|
174 | * @see rtems_filesystem_default_eval_path(). |
---|
175 | */ |
---|
176 | typedef void (*rtems_filesystem_eval_path_t)( |
---|
177 | rtems_filesystem_eval_path_context_t *ctx |
---|
178 | ); |
---|
179 | |
---|
180 | /** |
---|
181 | * @brief Creates a new link for the existing file. |
---|
182 | * |
---|
183 | * @param[in] parentloc The location of the parent of the new link. |
---|
184 | * @param[in] targetloc The location of the target file. |
---|
185 | * @param[in] name Name for the new link. |
---|
186 | * @param[in] namelen Length of the name for the new link in characters. |
---|
187 | * |
---|
188 | * @retval 0 Successful operation. |
---|
189 | * @retval -1 An error occurred. The errno is set to indicate the error. |
---|
190 | * |
---|
191 | * @see rtems_filesystem_default_link(). |
---|
192 | */ |
---|
193 | typedef int (*rtems_filesystem_link_t)( |
---|
194 | const rtems_filesystem_location_info_t *parentloc, |
---|
195 | const rtems_filesystem_location_info_t *targetloc, |
---|
196 | const char *name, |
---|
197 | size_t namelen |
---|
198 | ); |
---|
199 | |
---|
200 | /** |
---|
201 | * @brief Changes the mode of a node. |
---|
202 | * |
---|
203 | * @param[in] loc The location of the node. |
---|
204 | * @param[in] mode The new mode of the node |
---|
205 | * |
---|
206 | * @retval 0 Successful operation. |
---|
207 | * @retval -1 An error occurred. The errno is set to indicate the error. |
---|
208 | * |
---|
209 | * @see rtems_filesystem_default_fchmod(). |
---|
210 | */ |
---|
211 | typedef int (*rtems_filesystem_fchmod_t)( |
---|
212 | const rtems_filesystem_location_info_t *loc, |
---|
213 | mode_t mode |
---|
214 | ); |
---|
215 | |
---|
216 | /** |
---|
217 | * @brief Changes owner and group of a node. |
---|
218 | * |
---|
219 | * @param[in] loc The location of the node. |
---|
220 | * @param[in] owner User ID for the node. |
---|
221 | * @param[in] group Group ID for the node. |
---|
222 | * |
---|
223 | * @retval 0 Successful operation. |
---|
224 | * @retval -1 An error occurred. The errno is set to indicate the error. |
---|
225 | * |
---|
226 | * @see rtems_filesystem_default_chown(). |
---|
227 | */ |
---|
228 | typedef int (*rtems_filesystem_chown_t)( |
---|
229 | const rtems_filesystem_location_info_t *loc, |
---|
230 | uid_t owner, |
---|
231 | gid_t group |
---|
232 | ); |
---|
233 | |
---|
234 | /** |
---|
235 | * @brief Clones a location. |
---|
236 | * |
---|
237 | * The location is initialized with a bitwise copy of an existing location. |
---|
238 | * The caller must ensure that this location is protected from a release during |
---|
239 | * the clone operation. After a successful clone operation the clone will be |
---|
240 | * added to the location chain of the corresponding mount table entry. |
---|
241 | * |
---|
242 | * @param[in, out] loc Location to clone. |
---|
243 | * |
---|
244 | * @retval 0 Successful operation. |
---|
245 | * @retval -1 An error occurred. The errno is set to indicate the error. |
---|
246 | * |
---|
247 | * @see rtems_filesystem_default_clonenode(). |
---|
248 | */ |
---|
249 | typedef int (*rtems_filesystem_clonenode_t)( |
---|
250 | rtems_filesystem_location_info_t *loc |
---|
251 | ); |
---|
252 | |
---|
253 | /** |
---|
254 | * @brief Frees the location of a node. |
---|
255 | * |
---|
256 | * @param[in] loc The location of the node. |
---|
257 | * |
---|
258 | * @see rtems_filesystem_default_freenode(). |
---|
259 | */ |
---|
260 | typedef void (*rtems_filesystem_freenode_t)( |
---|
261 | const rtems_filesystem_location_info_t *loc |
---|
262 | ); |
---|
263 | |
---|
264 | /** |
---|
265 | * @brief Mounts a file system instance in a mount point (directory). |
---|
266 | * |
---|
267 | * The mount point belongs to the file system instance of the handler and is |
---|
268 | * specified by a field of the mount table entry. The handler must check that |
---|
269 | * the mount point is capable of mounting a file system instance. This is the |
---|
270 | * last step during the mount process. The file system instance is fully |
---|
271 | * initialized at this point. |
---|
272 | * |
---|
273 | * @param[in] mt_entry The mount table entry. |
---|
274 | * |
---|
275 | * @retval 0 Successful operation. |
---|
276 | * @retval -1 An error occurred. The errno is set to indicate the error. |
---|
277 | * |
---|
278 | * @see rtems_filesystem_default_mount(). |
---|
279 | */ |
---|
280 | typedef int (*rtems_filesystem_mount_t) ( |
---|
281 | rtems_filesystem_mount_table_entry_t *mt_entry |
---|
282 | ); |
---|
283 | |
---|
284 | /** |
---|
285 | * @brief Initializes a file system instance. |
---|
286 | * |
---|
287 | * This function must initialize the file system root node in the mount table |
---|
288 | * entry. |
---|
289 | * |
---|
290 | * @param[in] mt_entry The mount table entry. |
---|
291 | * @param[in] data The data provided by the user. |
---|
292 | * |
---|
293 | * @retval 0 Successful operation. |
---|
294 | * @retval -1 An error occurred. The errno is set to indicate the error. |
---|
295 | */ |
---|
296 | typedef int (*rtems_filesystem_fsmount_me_t)( |
---|
297 | rtems_filesystem_mount_table_entry_t *mt_entry, |
---|
298 | const void *data |
---|
299 | ); |
---|
300 | |
---|
301 | /** |
---|
302 | * @brief Unmounts a file system instance in a mount point (directory). |
---|
303 | * |
---|
304 | * In case this function is successful the file system instance will be marked |
---|
305 | * as unmounted. The file system instance will be destroyed when the last |
---|
306 | * reference to it vanishes. |
---|
307 | * |
---|
308 | * @param[in] mt_entry The mount table entry. |
---|
309 | * |
---|
310 | * @retval 0 Successful operation. |
---|
311 | * @retval -1 An error occurred. The errno is set to indicate the error. |
---|
312 | * |
---|
313 | * @see rtems_filesystem_default_unmount(). |
---|
314 | */ |
---|
315 | typedef int (*rtems_filesystem_unmount_t) ( |
---|
316 | rtems_filesystem_mount_table_entry_t *mt_entry |
---|
317 | ); |
---|
318 | |
---|
319 | /** |
---|
320 | * @brief Destroys a file system instance. |
---|
321 | * |
---|
322 | * The mount point node location of the mount table entry is invalid. This |
---|
323 | * handler must free the file system root location and all remaining resources |
---|
324 | * of the file system instance. |
---|
325 | * |
---|
326 | * @param[in] mt_entry The mount table entry. |
---|
327 | * |
---|
328 | * @see rtems_filesystem_default_fsunmount(). |
---|
329 | */ |
---|
330 | typedef void (*rtems_filesystem_fsunmount_me_t)( |
---|
331 | rtems_filesystem_mount_table_entry_t *mt_entry |
---|
332 | ); |
---|
333 | |
---|
334 | /** |
---|
335 | * @brief Tests if the node of one location is equal to the node of the other |
---|
336 | * location. |
---|
337 | * |
---|
338 | * The caller ensures that both nodes are within the same file system instance. |
---|
339 | * |
---|
340 | * @param[in] a The one location. |
---|
341 | * @param[in] b The other location. |
---|
342 | * |
---|
343 | * @retval true The nodes of the locations are equal. |
---|
344 | * @retval false Otherwise. |
---|
345 | * |
---|
346 | * @see rtems_filesystem_default_are_nodes_equal(). |
---|
347 | */ |
---|
348 | typedef bool (*rtems_filesystem_are_nodes_equal_t)( |
---|
349 | const rtems_filesystem_location_info_t *a, |
---|
350 | const rtems_filesystem_location_info_t *b |
---|
351 | ); |
---|
352 | |
---|
353 | /** |
---|
354 | * @brief Creates a new node. |
---|
355 | * |
---|
356 | * This handler should create a new node according to the parameters. |
---|
357 | * |
---|
358 | * @param[in] parentloc The location of the parent of the new node. |
---|
359 | * @param[in] name Name for the new node. |
---|
360 | * @param[in] namelen Length of the name for the new node in characters. |
---|
361 | * @param[in] mode Mode for the new node. |
---|
362 | * @param[in] dev Optional device identifier for the new node. |
---|
363 | * |
---|
364 | * @retval 0 Successful operation. |
---|
365 | * @retval -1 An error occurred. The errno is set to indicate the error. |
---|
366 | * |
---|
367 | * @see rtems_filesystem_default_mknod(). |
---|
368 | */ |
---|
369 | typedef int (*rtems_filesystem_mknod_t)( |
---|
370 | const rtems_filesystem_location_info_t *parentloc, |
---|
371 | const char *name, |
---|
372 | size_t namelen, |
---|
373 | mode_t mode, |
---|
374 | dev_t dev |
---|
375 | ); |
---|
376 | |
---|
377 | /** |
---|
378 | * @brief Removes a node. |
---|
379 | * |
---|
380 | * @param[in] parentloc The location of the parent of the node. |
---|
381 | * @param[in] loc The location of the node. |
---|
382 | * |
---|
383 | * @retval 0 Successful operation. |
---|
384 | * @retval -1 An error occurred. The errno is set to indicate the error. |
---|
385 | * |
---|
386 | * @see rtems_filesystem_default_rmnod(). |
---|
387 | */ |
---|
388 | typedef int (*rtems_filesystem_rmnod_t)( |
---|
389 | const rtems_filesystem_location_info_t *parentloc, |
---|
390 | const rtems_filesystem_location_info_t *loc |
---|
391 | ); |
---|
392 | |
---|
393 | /** |
---|
394 | * @brief Set node access and modification times. |
---|
395 | * |
---|
396 | * @param[in] loc The location of the node. |
---|
397 | * @param[in] times Access and modification times for the node |
---|
398 | * |
---|
399 | * @retval 0 Successful operation. |
---|
400 | * @retval -1 An error occurred. The errno is set to indicate the error. |
---|
401 | * |
---|
402 | * @see rtems_filesystem_default_utimens(). |
---|
403 | */ |
---|
404 | typedef int (*rtems_filesystem_utimens_t)( |
---|
405 | const rtems_filesystem_location_info_t *loc, |
---|
406 | struct timespec times[2] |
---|
407 | ); |
---|
408 | |
---|
409 | /** |
---|
410 | * @brief Makes a symbolic link to a node. |
---|
411 | * |
---|
412 | * @param[in] parentloc The location of the parent of the new symbolic link. |
---|
413 | * @param[in] name Name for the new symbolic link. |
---|
414 | * @param[in] namelen Length of the name for the new symbolic link in |
---|
415 | * characters. |
---|
416 | * @param[in] target Contents for the symbolic link. |
---|
417 | * |
---|
418 | * @retval 0 Successful operation. |
---|
419 | * @retval -1 An error occurred. The errno is set to indicate the error. |
---|
420 | * |
---|
421 | * @see rtems_filesystem_default_symlink(). |
---|
422 | */ |
---|
423 | typedef int (*rtems_filesystem_symlink_t)( |
---|
424 | const rtems_filesystem_location_info_t *parentloc, |
---|
425 | const char *name, |
---|
426 | size_t namelen, |
---|
427 | const char *target |
---|
428 | ); |
---|
429 | |
---|
430 | /** |
---|
431 | * @brief Reads the contents of a symbolic link. |
---|
432 | * |
---|
433 | * @param[in] loc The location of the symbolic link. |
---|
434 | * @param[out] buf The buffer for the contents. |
---|
435 | * @param[in] bufsize The size of the buffer in characters. |
---|
436 | * |
---|
437 | * @retval non-negative Size of the actual contents in characters. |
---|
438 | * @retval -1 An error occurred. The errno is set to indicate the error. |
---|
439 | * |
---|
440 | * @see rtems_filesystem_default_readlink(). |
---|
441 | */ |
---|
442 | typedef ssize_t (*rtems_filesystem_readlink_t)( |
---|
443 | const rtems_filesystem_location_info_t *loc, |
---|
444 | char *buf, |
---|
445 | size_t bufsize |
---|
446 | ); |
---|
447 | |
---|
448 | /** |
---|
449 | * @brief Renames a node. |
---|
450 | * |
---|
451 | * @param[in] oldparentloc The location of the parent of the old node. |
---|
452 | * @param[in] oldloc The location of the old node. |
---|
453 | * @param[in] newparentloc The location of the parent of the new node. |
---|
454 | * @param[in] name Name for the new node. |
---|
455 | * @param[in] namelen Length of the name for the new node in characters. |
---|
456 | * |
---|
457 | * @retval 0 Successful operation. |
---|
458 | * @retval -1 An error occurred. The errno is set to indicate the error. |
---|
459 | * |
---|
460 | * @see rtems_filesystem_default_rename(). |
---|
461 | */ |
---|
462 | typedef int (*rtems_filesystem_rename_t)( |
---|
463 | const rtems_filesystem_location_info_t *oldparentloc, |
---|
464 | const rtems_filesystem_location_info_t *oldloc, |
---|
465 | const rtems_filesystem_location_info_t *newparentloc, |
---|
466 | const char *name, |
---|
467 | size_t namelen |
---|
468 | ); |
---|
469 | |
---|
470 | /** |
---|
471 | * @brief Gets file system information. |
---|
472 | * |
---|
473 | * @param[in] loc The location of a node. |
---|
474 | * @param[out] buf Buffer for file system information. |
---|
475 | * |
---|
476 | * @retval 0 Successful operation. |
---|
477 | * @retval -1 An error occurred. The errno is set to indicate the error. |
---|
478 | * |
---|
479 | * @see rtems_filesystem_default_statvfs(). |
---|
480 | */ |
---|
481 | typedef int (*rtems_filesystem_statvfs_t)( |
---|
482 | const rtems_filesystem_location_info_t *loc, |
---|
483 | struct statvfs *buf |
---|
484 | ); |
---|
485 | |
---|
486 | /** |
---|
487 | * @brief File system operations table. |
---|
488 | */ |
---|
489 | struct _rtems_filesystem_operations_table { |
---|
490 | rtems_filesystem_mt_entry_lock_t lock_h; |
---|
491 | rtems_filesystem_mt_entry_unlock_t unlock_h; |
---|
492 | rtems_filesystem_eval_path_t eval_path_h; |
---|
493 | rtems_filesystem_link_t link_h; |
---|
494 | rtems_filesystem_are_nodes_equal_t are_nodes_equal_h; |
---|
495 | rtems_filesystem_mknod_t mknod_h; |
---|
496 | rtems_filesystem_rmnod_t rmnod_h; |
---|
497 | rtems_filesystem_fchmod_t fchmod_h; |
---|
498 | rtems_filesystem_chown_t chown_h; |
---|
499 | rtems_filesystem_clonenode_t clonenod_h; |
---|
500 | rtems_filesystem_freenode_t freenod_h; |
---|
501 | rtems_filesystem_mount_t mount_h; |
---|
502 | rtems_filesystem_unmount_t unmount_h; |
---|
503 | rtems_filesystem_fsunmount_me_t fsunmount_me_h; |
---|
504 | rtems_filesystem_utimens_t utimens_h; |
---|
505 | rtems_filesystem_symlink_t symlink_h; |
---|
506 | rtems_filesystem_readlink_t readlink_h; |
---|
507 | rtems_filesystem_rename_t rename_h; |
---|
508 | rtems_filesystem_statvfs_t statvfs_h; |
---|
509 | }; |
---|
510 | |
---|
511 | /** |
---|
512 | * @brief File system operations table with default operations. |
---|
513 | */ |
---|
514 | extern const rtems_filesystem_operations_table |
---|
515 | rtems_filesystem_operations_default; |
---|
516 | |
---|
517 | /** |
---|
518 | * @brief Obtains the IO library mutex. |
---|
519 | * |
---|
520 | * @see rtems_filesystem_mt_entry_lock_t. |
---|
521 | */ |
---|
522 | void rtems_filesystem_default_lock( |
---|
523 | const rtems_filesystem_mount_table_entry_t *mt_entry |
---|
524 | ); |
---|
525 | |
---|
526 | /** |
---|
527 | * @brief Releases the IO library mutex. |
---|
528 | * |
---|
529 | * @see rtems_filesystem_mt_entry_unlock_t. |
---|
530 | */ |
---|
531 | void rtems_filesystem_default_unlock( |
---|
532 | const rtems_filesystem_mount_table_entry_t *mt_entry |
---|
533 | ); |
---|
534 | |
---|
535 | /** |
---|
536 | * @brief Terminates the path evaluation and replaces the current location with |
---|
537 | * the null location. |
---|
538 | * |
---|
539 | * @see rtems_filesystem_eval_path_t. |
---|
540 | */ |
---|
541 | void rtems_filesystem_default_eval_path( |
---|
542 | rtems_filesystem_eval_path_context_t *ctx |
---|
543 | ); |
---|
544 | |
---|
545 | /** |
---|
546 | * @retval -1 Always. The errno is set to ENOTSUP. |
---|
547 | * |
---|
548 | * @see rtems_filesystem_link_t. |
---|
549 | */ |
---|
550 | int rtems_filesystem_default_link( |
---|
551 | const rtems_filesystem_location_info_t *parentloc, |
---|
552 | const rtems_filesystem_location_info_t *targetloc, |
---|
553 | const char *name, |
---|
554 | size_t namelen |
---|
555 | ); |
---|
556 | |
---|
557 | /** |
---|
558 | * @brief Tests if the node access pointer of one location is equal to |
---|
559 | * the node access pointer of the other location. |
---|
560 | * |
---|
561 | * @param[in] a The one location. |
---|
562 | * @param[in] b The other location. |
---|
563 | * |
---|
564 | * @retval true The node access pointers of the locations are equal. |
---|
565 | * @retval false Otherwise. |
---|
566 | * |
---|
567 | * @see rtems_filesystem_are_nodes_equal_t. |
---|
568 | */ |
---|
569 | bool rtems_filesystem_default_are_nodes_equal( |
---|
570 | const rtems_filesystem_location_info_t *a, |
---|
571 | const rtems_filesystem_location_info_t *b |
---|
572 | ); |
---|
573 | |
---|
574 | /** |
---|
575 | * @retval -1 Always. The errno is set to ENOTSUP. |
---|
576 | * |
---|
577 | * @see rtems_filesystem_mknod_t. |
---|
578 | */ |
---|
579 | int rtems_filesystem_default_mknod( |
---|
580 | const rtems_filesystem_location_info_t *parentloc, |
---|
581 | const char *name, |
---|
582 | size_t namelen, |
---|
583 | mode_t mode, |
---|
584 | dev_t dev |
---|
585 | ); |
---|
586 | |
---|
587 | /** |
---|
588 | * @retval -1 Always. The errno is set to ENOTSUP. |
---|
589 | * |
---|
590 | * @see rtems_filesystem_rmnod_t. |
---|
591 | */ |
---|
592 | int rtems_filesystem_default_rmnod( |
---|
593 | const rtems_filesystem_location_info_t *parentloc, |
---|
594 | const rtems_filesystem_location_info_t *loc |
---|
595 | ); |
---|
596 | |
---|
597 | /** |
---|
598 | * @retval -1 Always. The errno is set to ENOTSUP. |
---|
599 | * |
---|
600 | * @see rtems_filesystem_fchmod_t. |
---|
601 | */ |
---|
602 | int rtems_filesystem_default_fchmod( |
---|
603 | const rtems_filesystem_location_info_t *loc, |
---|
604 | mode_t mode |
---|
605 | ); |
---|
606 | |
---|
607 | /** |
---|
608 | * @retval -1 Always. The errno is set to ENOTSUP. |
---|
609 | * |
---|
610 | * @see rtems_filesystem_chown_t. |
---|
611 | */ |
---|
612 | int rtems_filesystem_default_chown( |
---|
613 | const rtems_filesystem_location_info_t *loc, |
---|
614 | uid_t owner, |
---|
615 | gid_t group |
---|
616 | ); |
---|
617 | |
---|
618 | /** |
---|
619 | * @retval 0 Always. |
---|
620 | * |
---|
621 | * @see rtems_filesystem_clonenode_t. |
---|
622 | */ |
---|
623 | int rtems_filesystem_default_clonenode( |
---|
624 | rtems_filesystem_location_info_t *loc |
---|
625 | ); |
---|
626 | |
---|
627 | /** |
---|
628 | * @see rtems_filesystem_freenode_t. |
---|
629 | */ |
---|
630 | void rtems_filesystem_default_freenode( |
---|
631 | const rtems_filesystem_location_info_t *loc |
---|
632 | ); |
---|
633 | |
---|
634 | /** |
---|
635 | * @retval -1 Always. The errno is set to ENOTSUP. |
---|
636 | * |
---|
637 | * @see rtems_filesystem_mount_t. |
---|
638 | */ |
---|
639 | int rtems_filesystem_default_mount ( |
---|
640 | rtems_filesystem_mount_table_entry_t *mt_entry /* IN */ |
---|
641 | ); |
---|
642 | |
---|
643 | /** |
---|
644 | * @retval -1 Always. The errno is set to ENOTSUP. |
---|
645 | * |
---|
646 | * @see rtems_filesystem_unmount_t. |
---|
647 | */ |
---|
648 | int rtems_filesystem_default_unmount( |
---|
649 | rtems_filesystem_mount_table_entry_t *mt_entry /* IN */ |
---|
650 | ); |
---|
651 | |
---|
652 | /** |
---|
653 | * @retval -1 Always. The errno is set to ENOTSUP. |
---|
654 | * |
---|
655 | * @see rtems_filesystem_fsunmount_me_t. |
---|
656 | */ |
---|
657 | void rtems_filesystem_default_fsunmount( |
---|
658 | rtems_filesystem_mount_table_entry_t *mt_entry /* IN */ |
---|
659 | ); |
---|
660 | |
---|
661 | /** |
---|
662 | * @retval -1 Always. The errno is set to ENOTSUP. |
---|
663 | * |
---|
664 | * @see rtems_filesystem_utimens_t. |
---|
665 | */ |
---|
666 | int rtems_filesystem_default_utimens( |
---|
667 | const rtems_filesystem_location_info_t *loc, |
---|
668 | struct timespec times[2] |
---|
669 | ); |
---|
670 | |
---|
671 | /** |
---|
672 | * @retval -1 Always. The errno is set to ENOTSUP. |
---|
673 | * |
---|
674 | * @see rtems_filesystem_symlink_t. |
---|
675 | */ |
---|
676 | int rtems_filesystem_default_symlink( |
---|
677 | const rtems_filesystem_location_info_t *parentloc, |
---|
678 | const char *name, |
---|
679 | size_t namelen, |
---|
680 | const char *target |
---|
681 | ); |
---|
682 | |
---|
683 | /** |
---|
684 | * @retval -1 Always. The errno is set to ENOTSUP. |
---|
685 | * |
---|
686 | * @see rtems_filesystem_readlink_t. |
---|
687 | */ |
---|
688 | ssize_t rtems_filesystem_default_readlink( |
---|
689 | const rtems_filesystem_location_info_t *loc, |
---|
690 | char *buf, |
---|
691 | size_t bufsize |
---|
692 | ); |
---|
693 | |
---|
694 | /** |
---|
695 | * @retval -1 Always. The errno is set to ENOTSUP. |
---|
696 | * |
---|
697 | * @see rtems_filesystem_rename_t. |
---|
698 | */ |
---|
699 | int rtems_filesystem_default_rename( |
---|
700 | const rtems_filesystem_location_info_t *oldparentloc, |
---|
701 | const rtems_filesystem_location_info_t *oldloc, |
---|
702 | const rtems_filesystem_location_info_t *newparentloc, |
---|
703 | const char *name, |
---|
704 | size_t namelen |
---|
705 | ); |
---|
706 | |
---|
707 | /** |
---|
708 | * @retval -1 Always. The errno is set to ENOTSUP. |
---|
709 | * |
---|
710 | * @see rtems_filesystem_statvfs_t. |
---|
711 | */ |
---|
712 | int rtems_filesystem_default_statvfs( |
---|
713 | const rtems_filesystem_location_info_t *loc, |
---|
714 | struct statvfs *buf |
---|
715 | ); |
---|
716 | |
---|
717 | /** @} */ |
---|
718 | |
---|
719 | /** |
---|
720 | * @defgroup LibIOFSHandler File System Node Handler |
---|
721 | * |
---|
722 | * @ingroup LibIO |
---|
723 | * |
---|
724 | * @brief File system node handler. |
---|
725 | */ |
---|
726 | /**@{**/ |
---|
727 | |
---|
728 | /** |
---|
729 | * @brief Opens a node. |
---|
730 | * |
---|
731 | * @param[in, out] iop The IO pointer. |
---|
732 | * @param[in] path The path. |
---|
733 | * @param[in] oflag The open flags. |
---|
734 | * @param[in] mode Optional mode for node creation. |
---|
735 | * |
---|
736 | * @retval 0 Successful operation. |
---|
737 | * @retval -1 An error occurred. The errno is set to indicate the error. |
---|
738 | * |
---|
739 | * @see rtems_filesystem_default_open(). |
---|
740 | */ |
---|
741 | typedef int (*rtems_filesystem_open_t)( |
---|
742 | rtems_libio_t *iop, |
---|
743 | const char *path, |
---|
744 | int oflag, |
---|
745 | mode_t mode |
---|
746 | ); |
---|
747 | |
---|
748 | /** |
---|
749 | * @brief Closes a node. |
---|
750 | * |
---|
751 | * @param[in, out] iop The IO pointer. |
---|
752 | * |
---|
753 | * @retval 0 Successful operation. |
---|
754 | * @retval -1 An error occurred. The errno is set to indicate the error. |
---|
755 | * |
---|
756 | * @see rtems_filesystem_default_close(). |
---|
757 | */ |
---|
758 | typedef int (*rtems_filesystem_close_t)( |
---|
759 | rtems_libio_t *iop |
---|
760 | ); |
---|
761 | |
---|
762 | /** |
---|
763 | * @brief Reads from a node. |
---|
764 | * |
---|
765 | * This handler is responsible to update the offset field of the IO descriptor. |
---|
766 | * |
---|
767 | * @param[in, out] iop The IO pointer. |
---|
768 | * @param[out] buffer The buffer for read data. |
---|
769 | * @param[in] count The size of the buffer in characters. |
---|
770 | * |
---|
771 | * @retval non-negative Count of read characters. |
---|
772 | * @retval -1 An error occurred. The errno is set to indicate the error. |
---|
773 | * |
---|
774 | * @see rtems_filesystem_default_read(). |
---|
775 | */ |
---|
776 | typedef ssize_t (*rtems_filesystem_read_t)( |
---|
777 | rtems_libio_t *iop, |
---|
778 | void *buffer, |
---|
779 | size_t count |
---|
780 | ); |
---|
781 | |
---|
782 | /** |
---|
783 | * @brief Reads an IO vector from a node. |
---|
784 | * |
---|
785 | * This handler is responsible to update the offset field of the IO descriptor. |
---|
786 | * |
---|
787 | * @param[in, out] iop The IO pointer. |
---|
788 | * @param[in] iov The IO vector with buffer for read data. The caller must |
---|
789 | * ensure that the IO vector values are valid. |
---|
790 | * @param[in] iovcnt The count of buffers in the IO vector. |
---|
791 | * @param[in] total The total count of bytes in the buffers in the IO vector. |
---|
792 | * |
---|
793 | * @retval non-negative Count of read characters. |
---|
794 | * @retval -1 An error occurred. The errno is set to indicate the error. |
---|
795 | * |
---|
796 | * @see rtems_filesystem_default_readv(). |
---|
797 | */ |
---|
798 | typedef ssize_t (*rtems_filesystem_readv_t)( |
---|
799 | rtems_libio_t *iop, |
---|
800 | const struct iovec *iov, |
---|
801 | int iovcnt, |
---|
802 | ssize_t total |
---|
803 | ); |
---|
804 | |
---|
805 | /** |
---|
806 | * @brief Writes to a node. |
---|
807 | * |
---|
808 | * This handler is responsible to update the offset field of the IO descriptor. |
---|
809 | * |
---|
810 | * @param[in, out] iop The IO pointer. |
---|
811 | * @param[out] buffer The buffer for write data. |
---|
812 | * @param[in] count The size of the buffer in characters. |
---|
813 | * |
---|
814 | * @retval non-negative Count of written characters. |
---|
815 | * @retval -1 An error occurred. The errno is set to indicate the error. |
---|
816 | * |
---|
817 | * @see rtems_filesystem_default_write(). |
---|
818 | */ |
---|
819 | typedef ssize_t (*rtems_filesystem_write_t)( |
---|
820 | rtems_libio_t *iop, |
---|
821 | const void *buffer, |
---|
822 | size_t count |
---|
823 | ); |
---|
824 | |
---|
825 | /** |
---|
826 | * @brief Writes an IO vector to a node. |
---|
827 | * |
---|
828 | * This handler is responsible to update the offset field of the IO descriptor. |
---|
829 | * |
---|
830 | * @param[in, out] iop The IO pointer. |
---|
831 | * @param[in] iov The IO vector with buffer for write data. The caller must |
---|
832 | * ensure that the IO vector values are valid. |
---|
833 | * @param[in] iovcnt The count of buffers in the IO vector. |
---|
834 | * @param[in] total The total count of bytes in the buffers in the IO vector. |
---|
835 | * |
---|
836 | * @retval non-negative Count of written characters. |
---|
837 | * @retval -1 An error occurred. The errno is set to indicate the error. |
---|
838 | * |
---|
839 | * @see rtems_filesystem_default_writev(). |
---|
840 | */ |
---|
841 | typedef ssize_t (*rtems_filesystem_writev_t)( |
---|
842 | rtems_libio_t *iop, |
---|
843 | const struct iovec *iov, |
---|
844 | int iovcnt, |
---|
845 | ssize_t total |
---|
846 | ); |
---|
847 | |
---|
848 | /** |
---|
849 | * @brief IO control of a node. |
---|
850 | * |
---|
851 | * @param[in, out] iop The IO pointer. |
---|
852 | * @param[in] request The IO control request. |
---|
853 | * @param[in, out] buffer The buffer for IO control request data. |
---|
854 | * |
---|
855 | * @retval 0 Successful operation. |
---|
856 | * @retval -1 An error occurred. The errno is set to indicate the error. |
---|
857 | * |
---|
858 | * @see rtems_filesystem_default_ioctl(). |
---|
859 | */ |
---|
860 | typedef int (*rtems_filesystem_ioctl_t)( |
---|
861 | rtems_libio_t *iop, |
---|
862 | ioctl_command_t request, |
---|
863 | void *buffer |
---|
864 | ); |
---|
865 | |
---|
866 | /** |
---|
867 | * @brief Moves the read/write file offset. |
---|
868 | * |
---|
869 | * @param[in, out] iop The IO pointer. |
---|
870 | * @param[in] offset The offset. |
---|
871 | * @param[in] whence The reference position for the offset. |
---|
872 | * |
---|
873 | * @retval non-negative The new offset from the beginning of the file. |
---|
874 | * @retval -1 An error occurred. The errno is set to indicate the error. |
---|
875 | * |
---|
876 | * @see rtems_filesystem_default_lseek(), |
---|
877 | * rtems_filesystem_default_lseek_file(), and |
---|
878 | * rtems_filesystem_default_lseek_directory(). |
---|
879 | */ |
---|
880 | typedef off_t (*rtems_filesystem_lseek_t)( |
---|
881 | rtems_libio_t *iop, |
---|
882 | off_t offset, |
---|
883 | int whence |
---|
884 | ); |
---|
885 | |
---|
886 | /** |
---|
887 | * @brief Gets a node status. |
---|
888 | * |
---|
889 | * @param[in, out] iop The IO pointer. |
---|
890 | * @param[out] stat The buffer to status information. |
---|
891 | * |
---|
892 | * @retval 0 Successful operation. |
---|
893 | * @retval -1 An error occurred. The errno is set to indicate the error. |
---|
894 | * |
---|
895 | * @see rtems_filesystem_default_fstat(). |
---|
896 | */ |
---|
897 | typedef int (*rtems_filesystem_fstat_t)( |
---|
898 | const rtems_filesystem_location_info_t *loc, |
---|
899 | struct stat *buf |
---|
900 | ); |
---|
901 | |
---|
902 | /** |
---|
903 | * @brief Truncates a file to a specified length. |
---|
904 | * |
---|
905 | * @param[in, out] iop The IO pointer. |
---|
906 | * @param[in] length The new length in characters. |
---|
907 | * |
---|
908 | * @retval 0 Successful operation. |
---|
909 | * @retval -1 An error occurred. The errno is set to indicate the error. |
---|
910 | * |
---|
911 | * @see rtems_filesystem_default_ftruncate() and |
---|
912 | * rtems_filesystem_default_ftruncate_directory(). |
---|
913 | */ |
---|
914 | typedef int (*rtems_filesystem_ftruncate_t)( |
---|
915 | rtems_libio_t *iop, |
---|
916 | off_t length |
---|
917 | ); |
---|
918 | |
---|
919 | /** |
---|
920 | * @brief Synchronizes changes to a file. |
---|
921 | * |
---|
922 | * @param[in, out] iop The IO pointer. |
---|
923 | * |
---|
924 | * @retval 0 Successful operation. |
---|
925 | * @retval -1 An error occurred. The errno is set to indicate the error. |
---|
926 | * |
---|
927 | * @see rtems_filesystem_default_fsync_or_fdatasync() and |
---|
928 | * rtems_filesystem_default_fsync_or_fdatasync_success(). |
---|
929 | */ |
---|
930 | typedef int (*rtems_filesystem_fsync_t)( |
---|
931 | rtems_libio_t *iop |
---|
932 | ); |
---|
933 | |
---|
934 | /** |
---|
935 | * @brief Synchronizes the data of a file. |
---|
936 | * |
---|
937 | * @param[in, out] iop The IO pointer. |
---|
938 | * |
---|
939 | * @retval 0 Successful operation. |
---|
940 | * @retval -1 An error occurred. The errno is set to indicate the error. |
---|
941 | * |
---|
942 | * @see rtems_filesystem_default_fsync_or_fdatasync() and |
---|
943 | * rtems_filesystem_default_fsync_or_fdatasync_success(). |
---|
944 | */ |
---|
945 | typedef int (*rtems_filesystem_fdatasync_t)( |
---|
946 | rtems_libio_t *iop |
---|
947 | ); |
---|
948 | |
---|
949 | /** |
---|
950 | * @brief File control. |
---|
951 | * |
---|
952 | * @param[in, out] iop The IO pointer. |
---|
953 | * @param[in] cmd Control command. |
---|
954 | * |
---|
955 | * @retval 0 Successful operation. |
---|
956 | * @retval errno An error occurred. This value is assigned to errno. |
---|
957 | * |
---|
958 | * @see rtems_filesystem_default_fcntl(). |
---|
959 | */ |
---|
960 | typedef int (*rtems_filesystem_fcntl_t)( |
---|
961 | rtems_libio_t *iop, |
---|
962 | int cmd |
---|
963 | ); |
---|
964 | |
---|
965 | /** |
---|
966 | * @brief Poll and select support. |
---|
967 | * |
---|
968 | * @param[in, out] iop The IO pointer. |
---|
969 | * @param[in] events The poll events. |
---|
970 | * |
---|
971 | * @return The poll return events. |
---|
972 | * |
---|
973 | * @see rtems_filesystem_default_poll(). |
---|
974 | */ |
---|
975 | typedef int (*rtems_filesystem_poll_t)( |
---|
976 | rtems_libio_t *iop, |
---|
977 | int events |
---|
978 | ); |
---|
979 | |
---|
980 | /** |
---|
981 | * @brief Kernel event filter support. |
---|
982 | * |
---|
983 | * @param[in, out] iop The IO pointer. |
---|
984 | * @param[in] kn The kernel event note. |
---|
985 | * |
---|
986 | * @retval 0 Successful operation. |
---|
987 | * @retval error An error occurred. This is usually EINVAL. |
---|
988 | * |
---|
989 | * @see rtems_filesystem_default_kqfilter(). |
---|
990 | */ |
---|
991 | typedef int (*rtems_filesystem_kqfilter_t)( |
---|
992 | rtems_libio_t *iop, |
---|
993 | struct knote *kn |
---|
994 | ); |
---|
995 | |
---|
996 | /** |
---|
997 | * @brief MMAP support. |
---|
998 | * |
---|
999 | * @param[in, out] iop The IO pointer. |
---|
1000 | * @param[in, out] addr The starting address of the mapped memory. |
---|
1001 | * @param[in] len The maximum number of bytes to map. |
---|
1002 | * @param[in] prot The desired memory protection. |
---|
1003 | * @param[in] off The offset within the file descriptor to map. |
---|
1004 | * |
---|
1005 | * @retval 0 Successful operation. |
---|
1006 | * @retval error An error occurred. This is usually EINVAL. |
---|
1007 | * |
---|
1008 | * @see rtems_filesystem_default_mmap(). |
---|
1009 | */ |
---|
1010 | typedef int (*rtems_filesystem_mmap_t)( |
---|
1011 | rtems_libio_t *iop, |
---|
1012 | void **addr, |
---|
1013 | size_t len, |
---|
1014 | int prot, |
---|
1015 | off_t off |
---|
1016 | ); |
---|
1017 | |
---|
1018 | /** |
---|
1019 | * @brief File system node operations table. |
---|
1020 | */ |
---|
1021 | struct _rtems_filesystem_file_handlers_r { |
---|
1022 | rtems_filesystem_open_t open_h; |
---|
1023 | rtems_filesystem_close_t close_h; |
---|
1024 | rtems_filesystem_read_t read_h; |
---|
1025 | rtems_filesystem_write_t write_h; |
---|
1026 | rtems_filesystem_ioctl_t ioctl_h; |
---|
1027 | rtems_filesystem_lseek_t lseek_h; |
---|
1028 | rtems_filesystem_fstat_t fstat_h; |
---|
1029 | rtems_filesystem_ftruncate_t ftruncate_h; |
---|
1030 | rtems_filesystem_fsync_t fsync_h; |
---|
1031 | rtems_filesystem_fdatasync_t fdatasync_h; |
---|
1032 | rtems_filesystem_fcntl_t fcntl_h; |
---|
1033 | rtems_filesystem_poll_t poll_h; |
---|
1034 | rtems_filesystem_kqfilter_t kqfilter_h; |
---|
1035 | rtems_filesystem_readv_t readv_h; |
---|
1036 | rtems_filesystem_writev_t writev_h; |
---|
1037 | rtems_filesystem_mmap_t mmap_h; |
---|
1038 | }; |
---|
1039 | |
---|
1040 | /** |
---|
1041 | * @brief File system node handler table with default node handlers. |
---|
1042 | */ |
---|
1043 | extern const rtems_filesystem_file_handlers_r |
---|
1044 | rtems_filesystem_handlers_default; |
---|
1045 | |
---|
1046 | /** |
---|
1047 | * @retval 0 Always. |
---|
1048 | * |
---|
1049 | * @see rtems_filesystem_open_t. |
---|
1050 | */ |
---|
1051 | int rtems_filesystem_default_open( |
---|
1052 | rtems_libio_t *iop, |
---|
1053 | const char *path, |
---|
1054 | int oflag, |
---|
1055 | mode_t mode |
---|
1056 | ); |
---|
1057 | |
---|
1058 | /** |
---|
1059 | * @retval 0 Always. |
---|
1060 | * |
---|
1061 | * @see rtems_filesystem_close_t. |
---|
1062 | */ |
---|
1063 | int rtems_filesystem_default_close( |
---|
1064 | rtems_libio_t *iop |
---|
1065 | ); |
---|
1066 | |
---|
1067 | /** |
---|
1068 | * @retval -1 Always. The errno is set to ENOTSUP. |
---|
1069 | * |
---|
1070 | * @see rtems_filesystem_read_t. |
---|
1071 | */ |
---|
1072 | ssize_t rtems_filesystem_default_read( |
---|
1073 | rtems_libio_t *iop, |
---|
1074 | void *buffer, |
---|
1075 | size_t count |
---|
1076 | ); |
---|
1077 | |
---|
1078 | /** |
---|
1079 | * @brief Calls the read handler for each IO vector entry. |
---|
1080 | * |
---|
1081 | * @see rtems_filesystem_readv_t. |
---|
1082 | */ |
---|
1083 | ssize_t rtems_filesystem_default_readv( |
---|
1084 | rtems_libio_t *iop, |
---|
1085 | const struct iovec *iov, |
---|
1086 | int iovcnt, |
---|
1087 | ssize_t total |
---|
1088 | ); |
---|
1089 | |
---|
1090 | /** |
---|
1091 | * @retval -1 Always. The errno is set to ENOTSUP. |
---|
1092 | * |
---|
1093 | * @see rtems_filesystem_write_t. |
---|
1094 | */ |
---|
1095 | ssize_t rtems_filesystem_default_write( |
---|
1096 | rtems_libio_t *iop, |
---|
1097 | const void *buffer, |
---|
1098 | size_t count |
---|
1099 | ); |
---|
1100 | |
---|
1101 | /** |
---|
1102 | * @brief Calls the write handler for each IO vector entry. |
---|
1103 | * |
---|
1104 | * @see rtems_filesystem_write_t. |
---|
1105 | */ |
---|
1106 | ssize_t rtems_filesystem_default_writev( |
---|
1107 | rtems_libio_t *iop, |
---|
1108 | const struct iovec *iov, |
---|
1109 | int iovcnt, |
---|
1110 | ssize_t total |
---|
1111 | ); |
---|
1112 | |
---|
1113 | /** |
---|
1114 | * @retval -1 Always. The errno is set to ENOTTY. |
---|
1115 | * |
---|
1116 | * @see rtems_filesystem_ioctl_t. |
---|
1117 | */ |
---|
1118 | int rtems_filesystem_default_ioctl( |
---|
1119 | rtems_libio_t *iop, |
---|
1120 | ioctl_command_t request, |
---|
1121 | void *buffer |
---|
1122 | ); |
---|
1123 | |
---|
1124 | /** |
---|
1125 | * @retval -1 Always. The errno is set to ESPIPE. |
---|
1126 | * |
---|
1127 | * @see rtems_filesystem_lseek_t. |
---|
1128 | */ |
---|
1129 | off_t rtems_filesystem_default_lseek( |
---|
1130 | rtems_libio_t *iop, |
---|
1131 | off_t offset, |
---|
1132 | int whence |
---|
1133 | ); |
---|
1134 | |
---|
1135 | /** |
---|
1136 | * @brief An offset 0 with a whence of SEEK_SET will perform a directory rewind |
---|
1137 | * operation. |
---|
1138 | * |
---|
1139 | * This function has no protection against concurrent access. |
---|
1140 | * |
---|
1141 | * @retval -1 The offset is not zero or the whence is not SEEK_SET. |
---|
1142 | * @retval 0 Successful rewind operation. |
---|
1143 | * |
---|
1144 | * @see rtems_filesystem_lseek_t. |
---|
1145 | */ |
---|
1146 | off_t rtems_filesystem_default_lseek_directory( |
---|
1147 | rtems_libio_t *iop, |
---|
1148 | off_t offset, |
---|
1149 | int whence |
---|
1150 | ); |
---|
1151 | |
---|
1152 | /** |
---|
1153 | * @brief Default lseek() handler for files. |
---|
1154 | * |
---|
1155 | * The fstat() handler will be used to obtain the file size in case whence is |
---|
1156 | * SEEK_END. |
---|
1157 | * |
---|
1158 | * This function has no protection against concurrent access. |
---|
1159 | * |
---|
1160 | * @retval -1 An error occurred. In case an integer overflow occurred, then the |
---|
1161 | * errno will be set to EOVERFLOW. In case the new offset is negative, then |
---|
1162 | * the errno will be set to EINVAL. In case the whence is SEEK_END and the |
---|
1163 | * fstat() handler to obtain the current file size returned an error status, |
---|
1164 | * then the errno will be set by the fstat() handler. |
---|
1165 | * @retval offset The new offset. |
---|
1166 | * |
---|
1167 | * @see rtems_filesystem_lseek_t. |
---|
1168 | */ |
---|
1169 | off_t rtems_filesystem_default_lseek_file( |
---|
1170 | rtems_libio_t *iop, |
---|
1171 | off_t offset, |
---|
1172 | int whence |
---|
1173 | ); |
---|
1174 | |
---|
1175 | /** |
---|
1176 | * @brief Sets the mode to S_IRWXU | S_IRWXG | S_IRWXO. |
---|
1177 | * |
---|
1178 | * @retval 0 Always. |
---|
1179 | * |
---|
1180 | * @see rtems_filesystem_fstat_t. |
---|
1181 | */ |
---|
1182 | int rtems_filesystem_default_fstat( |
---|
1183 | const rtems_filesystem_location_info_t *loc, |
---|
1184 | struct stat *buf |
---|
1185 | ); |
---|
1186 | |
---|
1187 | /** |
---|
1188 | * @retval -1 Always. The errno is set to EINVAL. |
---|
1189 | * |
---|
1190 | * @see rtems_filesystem_ftruncate_t. |
---|
1191 | */ |
---|
1192 | int rtems_filesystem_default_ftruncate( |
---|
1193 | rtems_libio_t *iop, |
---|
1194 | off_t length |
---|
1195 | ); |
---|
1196 | |
---|
1197 | /** |
---|
1198 | * @retval -1 Always. The errno is set to EISDIR. |
---|
1199 | * |
---|
1200 | * @see rtems_filesystem_ftruncate_t. |
---|
1201 | */ |
---|
1202 | int rtems_filesystem_default_ftruncate_directory( |
---|
1203 | rtems_libio_t *iop, |
---|
1204 | off_t length |
---|
1205 | ); |
---|
1206 | |
---|
1207 | /** |
---|
1208 | * @retval -1 Always. The errno is set to EINVAL. |
---|
1209 | * |
---|
1210 | * @see rtems_filesystem_fsync_t and rtems_filesystem_fdatasync_t. |
---|
1211 | */ |
---|
1212 | int rtems_filesystem_default_fsync_or_fdatasync( |
---|
1213 | rtems_libio_t *iop |
---|
1214 | ); |
---|
1215 | |
---|
1216 | /** |
---|
1217 | * @retval 0 Always. |
---|
1218 | * |
---|
1219 | * @see rtems_filesystem_fsync_t and rtems_filesystem_fdatasync_t. |
---|
1220 | */ |
---|
1221 | int rtems_filesystem_default_fsync_or_fdatasync_success( |
---|
1222 | rtems_libio_t *iop |
---|
1223 | ); |
---|
1224 | |
---|
1225 | /** |
---|
1226 | * @retval 0 Always. |
---|
1227 | * |
---|
1228 | * @see rtems_filesystem_fcntl_t. |
---|
1229 | */ |
---|
1230 | int rtems_filesystem_default_fcntl( |
---|
1231 | rtems_libio_t *iop, |
---|
1232 | int cmd |
---|
1233 | ); |
---|
1234 | |
---|
1235 | /** |
---|
1236 | * @brief Default poll handler. |
---|
1237 | * |
---|
1238 | * @retval POLLERR Always. |
---|
1239 | * |
---|
1240 | * @see rtems_filesystem_poll_t. |
---|
1241 | */ |
---|
1242 | int rtems_filesystem_default_poll( |
---|
1243 | rtems_libio_t *iop, |
---|
1244 | int events |
---|
1245 | ); |
---|
1246 | |
---|
1247 | /** |
---|
1248 | * @brief Default kernel event filter handler. |
---|
1249 | * |
---|
1250 | * @retval EINVAL Always. |
---|
1251 | * |
---|
1252 | * @see rtems_filesystem_kqfilter_t. |
---|
1253 | */ |
---|
1254 | int rtems_filesystem_default_kqfilter( |
---|
1255 | rtems_libio_t *iop, |
---|
1256 | struct knote *kn |
---|
1257 | ); |
---|
1258 | |
---|
1259 | /** |
---|
1260 | * @brief Default MMAP handler. |
---|
1261 | * |
---|
1262 | * @retval ENOTSUP Always. |
---|
1263 | * |
---|
1264 | * @see rtems_filesystem_mmap_t. |
---|
1265 | */ |
---|
1266 | int rtems_filesystem_default_mmap( |
---|
1267 | rtems_libio_t *iop, |
---|
1268 | void **addr, |
---|
1269 | size_t len, |
---|
1270 | int prot, |
---|
1271 | off_t off |
---|
1272 | ); |
---|
1273 | |
---|
1274 | /** @} */ |
---|
1275 | |
---|
1276 | /** |
---|
1277 | * @defgroup LibIO IO Library |
---|
1278 | * |
---|
1279 | * @ingroup RTEMSImpl |
---|
1280 | * |
---|
1281 | * @brief Provides system call and file system interface definitions. |
---|
1282 | * |
---|
1283 | * General purpose communication channel for RTEMS to allow UNIX/POSIX |
---|
1284 | * system call behavior under RTEMS. Initially this supported only |
---|
1285 | * IO to devices but has since been enhanced to support networking |
---|
1286 | * and support for mounted file systems. |
---|
1287 | */ |
---|
1288 | /**@{**/ |
---|
1289 | |
---|
1290 | typedef off_t rtems_off64_t __attribute__((deprecated)); |
---|
1291 | |
---|
1292 | /** |
---|
1293 | * @brief Gets the mount handler for the file system @a type. |
---|
1294 | * |
---|
1295 | * @return The file system mount handler associated with the @a type, or |
---|
1296 | * @c NULL if no such association exists. |
---|
1297 | */ |
---|
1298 | rtems_filesystem_fsmount_me_t |
---|
1299 | rtems_filesystem_get_mount_handler( |
---|
1300 | const char *type |
---|
1301 | ); |
---|
1302 | |
---|
1303 | /** |
---|
1304 | * @brief Contain file system specific information which is required to support |
---|
1305 | * fpathconf(). |
---|
1306 | */ |
---|
1307 | typedef struct { |
---|
1308 | int link_max; /* count */ |
---|
1309 | int max_canon; /* max formatted input line size */ |
---|
1310 | int max_input; /* max input line size */ |
---|
1311 | int name_max; /* max name length */ |
---|
1312 | int path_max; /* max path */ |
---|
1313 | int pipe_buf; /* pipe buffer size */ |
---|
1314 | int posix_async_io; /* async IO supported on fs, 0=no, 1=yes */ |
---|
1315 | int posix_chown_restrictions; /* can chown: 0=no, 1=yes */ |
---|
1316 | int posix_no_trunc; /* error on names > max name, 0=no, 1=yes */ |
---|
1317 | int posix_prio_io; /* priority IO, 0=no, 1=yes */ |
---|
1318 | int posix_sync_io; /* file can be sync'ed, 0=no, 1=yes */ |
---|
1319 | int posix_vdisable; /* special char processing, 0=no, 1=yes */ |
---|
1320 | } rtems_filesystem_limits_and_options_t; |
---|
1321 | |
---|
1322 | /** |
---|
1323 | * @brief Default pathconf settings. |
---|
1324 | * |
---|
1325 | * Override in a filesystem. |
---|
1326 | */ |
---|
1327 | extern const rtems_filesystem_limits_and_options_t |
---|
1328 | rtems_filesystem_default_pathconf; |
---|
1329 | |
---|
1330 | /** |
---|
1331 | * @brief An open file data structure. |
---|
1332 | * |
---|
1333 | * It will be indexed by 'fd'. |
---|
1334 | * |
---|
1335 | * @todo Should really have a separate per/file data structure that this points |
---|
1336 | * to (eg: offset, driver, pathname should be in that) |
---|
1337 | */ |
---|
1338 | struct rtems_libio_tt { |
---|
1339 | Atomic_Uint flags; |
---|
1340 | off_t offset; /* current offset into file */ |
---|
1341 | rtems_filesystem_location_info_t pathinfo; |
---|
1342 | uint32_t data0; /* private to "driver" */ |
---|
1343 | void *data1; /* ... */ |
---|
1344 | }; |
---|
1345 | |
---|
1346 | /** |
---|
1347 | * @brief Paramameter block for read/write. |
---|
1348 | * |
---|
1349 | * It must include 'offset' instead of using iop's offset since we can have |
---|
1350 | * multiple outstanding i/o's on a device. |
---|
1351 | */ |
---|
1352 | typedef struct { |
---|
1353 | rtems_libio_t *iop; |
---|
1354 | off_t offset; |
---|
1355 | char *buffer; |
---|
1356 | uint32_t count; |
---|
1357 | uint32_t flags; |
---|
1358 | uint32_t bytes_moved; |
---|
1359 | } rtems_libio_rw_args_t; |
---|
1360 | |
---|
1361 | /** |
---|
1362 | * @brief Parameter block for open/close. |
---|
1363 | */ |
---|
1364 | typedef struct rtems_libio_open_close_args { |
---|
1365 | rtems_libio_t *iop; |
---|
1366 | uint32_t flags; |
---|
1367 | uint32_t mode; |
---|
1368 | } rtems_libio_open_close_args_t; |
---|
1369 | |
---|
1370 | /** |
---|
1371 | * @brief Parameter block for ioctl. |
---|
1372 | */ |
---|
1373 | typedef struct { |
---|
1374 | rtems_libio_t *iop; |
---|
1375 | ioctl_command_t command; |
---|
1376 | void *buffer; |
---|
1377 | int ioctl_return; |
---|
1378 | } rtems_libio_ioctl_args_t; |
---|
1379 | |
---|
1380 | /** |
---|
1381 | * @name Flag Values |
---|
1382 | */ |
---|
1383 | /**@{**/ |
---|
1384 | |
---|
1385 | #define LIBIO_FLAGS_NO_DELAY 0x0001U /* return immediately if no data */ |
---|
1386 | #define LIBIO_FLAGS_READ 0x0002U /* reading */ |
---|
1387 | #define LIBIO_FLAGS_WRITE 0x0004U /* writing */ |
---|
1388 | #define LIBIO_FLAGS_OPEN 0x0100U /* device is open */ |
---|
1389 | #define LIBIO_FLAGS_APPEND 0x0200U /* all writes append */ |
---|
1390 | #define LIBIO_FLAGS_CLOSE_ON_EXEC 0x0800U /* close on process exec() */ |
---|
1391 | #define LIBIO_FLAGS_READ_WRITE (LIBIO_FLAGS_READ | LIBIO_FLAGS_WRITE) |
---|
1392 | #define LIBIO_FLAGS_REFERENCE_INC 0x1000U |
---|
1393 | |
---|
1394 | /** @} */ |
---|
1395 | |
---|
1396 | static inline unsigned int rtems_libio_iop_flags( const rtems_libio_t *iop ) |
---|
1397 | { |
---|
1398 | return _Atomic_Load_uint( &iop->flags, ATOMIC_ORDER_RELAXED ); |
---|
1399 | } |
---|
1400 | |
---|
1401 | /** |
---|
1402 | * @brief Returns true if this is a no delay iop, otherwise returns false. |
---|
1403 | * |
---|
1404 | * @param[in] iop The iop. |
---|
1405 | */ |
---|
1406 | static inline bool rtems_libio_iop_is_no_delay( const rtems_libio_t *iop ) |
---|
1407 | { |
---|
1408 | return ( rtems_libio_iop_flags( iop ) & LIBIO_FLAGS_NO_DELAY ) != 0; |
---|
1409 | } |
---|
1410 | |
---|
1411 | /** |
---|
1412 | * @brief Returns true if this is a readable iop, otherwise returns false. |
---|
1413 | * |
---|
1414 | * @param[in] iop The iop. |
---|
1415 | */ |
---|
1416 | static inline bool rtems_libio_iop_is_readable( const rtems_libio_t *iop ) |
---|
1417 | { |
---|
1418 | return ( rtems_libio_iop_flags( iop ) & LIBIO_FLAGS_READ ) != 0; |
---|
1419 | } |
---|
1420 | |
---|
1421 | /** |
---|
1422 | * @brief Returns true if this is a writeable iop, otherwise returns false. |
---|
1423 | * |
---|
1424 | * @param[in] iop The iop. |
---|
1425 | */ |
---|
1426 | static inline bool rtems_libio_iop_is_writeable( const rtems_libio_t *iop ) |
---|
1427 | { |
---|
1428 | return ( rtems_libio_iop_flags( iop ) & LIBIO_FLAGS_WRITE ) != 0; |
---|
1429 | } |
---|
1430 | |
---|
1431 | /** |
---|
1432 | * @brief Returns true if this is an append iop, otherwise returns false. |
---|
1433 | * |
---|
1434 | * @param[in] iop The iop. |
---|
1435 | */ |
---|
1436 | static inline bool rtems_libio_iop_is_append( const rtems_libio_t *iop ) |
---|
1437 | { |
---|
1438 | return ( rtems_libio_iop_flags( iop ) & LIBIO_FLAGS_APPEND ) != 0; |
---|
1439 | } |
---|
1440 | |
---|
1441 | /** |
---|
1442 | * @name External I/O Handlers |
---|
1443 | */ |
---|
1444 | /**@{**/ |
---|
1445 | |
---|
1446 | typedef int (*rtems_libio_open_t)( |
---|
1447 | const char *pathname, |
---|
1448 | uint32_t flag, |
---|
1449 | uint32_t mode |
---|
1450 | ); |
---|
1451 | |
---|
1452 | typedef int (*rtems_libio_close_t)( |
---|
1453 | int fd |
---|
1454 | ); |
---|
1455 | |
---|
1456 | typedef ssize_t (*rtems_libio_read_t)( |
---|
1457 | int fd, |
---|
1458 | void *buffer, |
---|
1459 | size_t count |
---|
1460 | ); |
---|
1461 | |
---|
1462 | typedef ssize_t (*rtems_libio_write_t)( |
---|
1463 | int fd, |
---|
1464 | const void *buffer, |
---|
1465 | size_t count |
---|
1466 | ); |
---|
1467 | |
---|
1468 | typedef int (*rtems_libio_ioctl_t)( |
---|
1469 | int fd, |
---|
1470 | uint32_t command, |
---|
1471 | void *buffer |
---|
1472 | ); |
---|
1473 | |
---|
1474 | typedef off_t (*rtems_libio_lseek_t)( |
---|
1475 | int fd, |
---|
1476 | off_t offset, |
---|
1477 | int whence |
---|
1478 | ); |
---|
1479 | |
---|
1480 | /** @} */ |
---|
1481 | |
---|
1482 | /** |
---|
1483 | * @name Permission Macros |
---|
1484 | */ |
---|
1485 | /**@{**/ |
---|
1486 | |
---|
1487 | /* |
---|
1488 | * The following macros are used to build up the permissions sets |
---|
1489 | * used to check permissions. These are similar in style to the |
---|
1490 | * mode_t bits and should stay compatible with them. |
---|
1491 | */ |
---|
1492 | #define RTEMS_FS_PERMS_READ 0x4 |
---|
1493 | #define RTEMS_FS_PERMS_WRITE 0x2 |
---|
1494 | #define RTEMS_FS_PERMS_EXEC 0x1 |
---|
1495 | #define RTEMS_FS_PERMS_RWX \ |
---|
1496 | (RTEMS_FS_PERMS_READ | RTEMS_FS_PERMS_WRITE | RTEMS_FS_PERMS_EXEC) |
---|
1497 | #define RTEMS_FS_FOLLOW_HARD_LINK 0x8 |
---|
1498 | #define RTEMS_FS_FOLLOW_SYM_LINK 0x10 |
---|
1499 | #define RTEMS_FS_FOLLOW_LINK \ |
---|
1500 | (RTEMS_FS_FOLLOW_HARD_LINK | RTEMS_FS_FOLLOW_SYM_LINK) |
---|
1501 | #define RTEMS_FS_MAKE 0x20 |
---|
1502 | #define RTEMS_FS_EXCLUSIVE 0x40 |
---|
1503 | #define RTEMS_FS_ACCEPT_RESIDUAL_DELIMITERS 0x80 |
---|
1504 | #define RTEMS_FS_REJECT_TERMINAL_DOT 0x100 |
---|
1505 | |
---|
1506 | /** @} */ |
---|
1507 | |
---|
1508 | union __rtems_dev_t { |
---|
1509 | dev_t device; |
---|
1510 | struct { |
---|
1511 | rtems_device_major_number major; |
---|
1512 | rtems_device_minor_number minor; |
---|
1513 | } __overlay; |
---|
1514 | }; |
---|
1515 | |
---|
1516 | static inline dev_t rtems_filesystem_make_dev_t( |
---|
1517 | rtems_device_major_number _major, |
---|
1518 | rtems_device_minor_number _minor |
---|
1519 | ) |
---|
1520 | { |
---|
1521 | union __rtems_dev_t temp; |
---|
1522 | |
---|
1523 | temp.__overlay.major = _major; |
---|
1524 | temp.__overlay.minor = _minor; |
---|
1525 | return temp.device; |
---|
1526 | } |
---|
1527 | |
---|
1528 | static inline dev_t rtems_filesystem_make_dev_t_from_pointer( |
---|
1529 | const void *pointer |
---|
1530 | ) |
---|
1531 | { |
---|
1532 | uint64_t temp = (((uint64_t) 1) << 63) | (((uintptr_t) pointer) >> 1); |
---|
1533 | |
---|
1534 | return rtems_filesystem_make_dev_t((uint32_t) (temp >> 32), (uint32_t) temp); |
---|
1535 | } |
---|
1536 | |
---|
1537 | static inline rtems_device_major_number rtems_filesystem_dev_major_t( |
---|
1538 | dev_t device |
---|
1539 | ) |
---|
1540 | { |
---|
1541 | union __rtems_dev_t temp; |
---|
1542 | |
---|
1543 | temp.device = device; |
---|
1544 | return temp.__overlay.major; |
---|
1545 | } |
---|
1546 | |
---|
1547 | |
---|
1548 | static inline rtems_device_minor_number rtems_filesystem_dev_minor_t( |
---|
1549 | dev_t device |
---|
1550 | ) |
---|
1551 | { |
---|
1552 | union __rtems_dev_t temp; |
---|
1553 | |
---|
1554 | temp.device = device; |
---|
1555 | return temp.__overlay.minor; |
---|
1556 | } |
---|
1557 | |
---|
1558 | #define rtems_filesystem_split_dev_t( _dev, _major, _minor ) \ |
---|
1559 | do { \ |
---|
1560 | (_major) = rtems_filesystem_dev_major_t ( _dev ); \ |
---|
1561 | (_minor) = rtems_filesystem_dev_minor_t( _dev ); \ |
---|
1562 | } while(0) |
---|
1563 | |
---|
1564 | /* |
---|
1565 | * Prototypes for filesystem |
---|
1566 | */ |
---|
1567 | |
---|
1568 | /** |
---|
1569 | * @brief Base File System Initialization |
---|
1570 | * |
---|
1571 | * Initialize the foundation of the file system. This is specified |
---|
1572 | * by the structure rtems_filesystem_mount_table. The usual |
---|
1573 | * configuration is a single instantiation of the IMFS or miniIMFS with |
---|
1574 | * a single "/dev" directory in it. |
---|
1575 | */ |
---|
1576 | void rtems_filesystem_initialize( void ); |
---|
1577 | |
---|
1578 | void rtems_libio_post_driver(void); |
---|
1579 | |
---|
1580 | void rtems_libio_exit(void); |
---|
1581 | |
---|
1582 | /** |
---|
1583 | * @brief Creates a directory and all its parent directories according to |
---|
1584 | * @a path. |
---|
1585 | * |
---|
1586 | * The @a mode value selects the access permissions of the directory. |
---|
1587 | * |
---|
1588 | * @retval 0 Successful operation. |
---|
1589 | * @retval -1 An error occurred. The @c errno indicates the error. |
---|
1590 | */ |
---|
1591 | extern int rtems_mkdir(const char *path, mode_t mode); |
---|
1592 | |
---|
1593 | /** @} */ |
---|
1594 | |
---|
1595 | /** |
---|
1596 | * @defgroup FileSystemTypesAndMount File System Types and Mount |
---|
1597 | * |
---|
1598 | * @ingroup LibIO |
---|
1599 | * |
---|
1600 | * @brief File system types and mount. |
---|
1601 | */ |
---|
1602 | /**@{**/ |
---|
1603 | |
---|
1604 | /** |
---|
1605 | * @name File System Types |
---|
1606 | */ |
---|
1607 | /**@{**/ |
---|
1608 | |
---|
1609 | #define RTEMS_FILESYSTEM_TYPE_IMFS "imfs" |
---|
1610 | #define RTEMS_FILESYSTEM_TYPE_FTPFS "ftpfs" |
---|
1611 | #define RTEMS_FILESYSTEM_TYPE_TFTPFS "tftpfs" |
---|
1612 | #define RTEMS_FILESYSTEM_TYPE_NFS "nfs" |
---|
1613 | #define RTEMS_FILESYSTEM_TYPE_DOSFS "dosfs" |
---|
1614 | #define RTEMS_FILESYSTEM_TYPE_RFS "rfs" |
---|
1615 | #define RTEMS_FILESYSTEM_TYPE_JFFS2 "jffs2" |
---|
1616 | |
---|
1617 | /** @} */ |
---|
1618 | |
---|
1619 | /** |
---|
1620 | * @brief Mount table entry. |
---|
1621 | */ |
---|
1622 | struct rtems_filesystem_mount_table_entry_tt { |
---|
1623 | rtems_chain_node mt_node; |
---|
1624 | void *fs_info; |
---|
1625 | const rtems_filesystem_operations_table *ops; |
---|
1626 | const void *immutable_fs_info; |
---|
1627 | rtems_chain_control location_chain; |
---|
1628 | rtems_filesystem_global_location_t *mt_point_node; |
---|
1629 | rtems_filesystem_global_location_t *mt_fs_root; |
---|
1630 | bool mounted; |
---|
1631 | bool writeable; |
---|
1632 | bool no_regular_file_mknod; |
---|
1633 | const rtems_filesystem_limits_and_options_t *pathconf_limits_and_options; |
---|
1634 | |
---|
1635 | /* |
---|
1636 | * The target or mount point of the file system. |
---|
1637 | */ |
---|
1638 | const char *target; |
---|
1639 | |
---|
1640 | /* |
---|
1641 | * The type of filesystem or the name of the filesystem. |
---|
1642 | */ |
---|
1643 | const char *type; |
---|
1644 | |
---|
1645 | /* |
---|
1646 | * When someone adds a mounted filesystem on a real device, |
---|
1647 | * this will need to be used. |
---|
1648 | * |
---|
1649 | * The lower layers can manage how this is managed. Leave as a |
---|
1650 | * string. |
---|
1651 | */ |
---|
1652 | char *dev; |
---|
1653 | |
---|
1654 | /** |
---|
1655 | * The task that initiated the unmount process. After unmount process |
---|
1656 | * completion this task will be notified via the transient event. |
---|
1657 | * |
---|
1658 | * @see ClassicEventTransient. |
---|
1659 | */ |
---|
1660 | rtems_id unmount_task; |
---|
1661 | }; |
---|
1662 | |
---|
1663 | /** |
---|
1664 | * @brief File system options. |
---|
1665 | */ |
---|
1666 | typedef enum { |
---|
1667 | RTEMS_FILESYSTEM_READ_ONLY, |
---|
1668 | RTEMS_FILESYSTEM_READ_WRITE, |
---|
1669 | RTEMS_FILESYSTEM_BAD_OPTIONS |
---|
1670 | } rtems_filesystem_options_t; |
---|
1671 | |
---|
1672 | /** |
---|
1673 | * @brief File system table entry. |
---|
1674 | */ |
---|
1675 | typedef struct rtems_filesystem_table_t { |
---|
1676 | const char *type; |
---|
1677 | rtems_filesystem_fsmount_me_t mount_h; |
---|
1678 | } rtems_filesystem_table_t; |
---|
1679 | |
---|
1680 | /** |
---|
1681 | * @brief Static table of file systems. |
---|
1682 | * |
---|
1683 | * Externally defined by confdefs.h or the user. |
---|
1684 | */ |
---|
1685 | extern const rtems_filesystem_table_t rtems_filesystem_table []; |
---|
1686 | |
---|
1687 | extern rtems_chain_control rtems_filesystem_mount_table; |
---|
1688 | |
---|
1689 | /** |
---|
1690 | * @brief Registers a file system @a type. |
---|
1691 | * |
---|
1692 | * The @a mount_h handler will be used to mount a file system of this @a type. |
---|
1693 | * |
---|
1694 | * @retval 0 Successful operation. |
---|
1695 | * @retval -1 An error occurred. The @c errno indicates the error. |
---|
1696 | */ |
---|
1697 | int rtems_filesystem_register( |
---|
1698 | const char *type, |
---|
1699 | rtems_filesystem_fsmount_me_t mount_h |
---|
1700 | ); |
---|
1701 | |
---|
1702 | /** |
---|
1703 | * @brief Unregisters a file system @a type. |
---|
1704 | * |
---|
1705 | * @retval 0 Successful operation. |
---|
1706 | * @retval -1 An error occurred. The @c errno indicates the error. |
---|
1707 | */ |
---|
1708 | int rtems_filesystem_unregister( |
---|
1709 | const char *type |
---|
1710 | ); |
---|
1711 | |
---|
1712 | /** |
---|
1713 | * @brief Unmounts the file system instance at the specified mount path. |
---|
1714 | * |
---|
1715 | * The function waits for the unmount process completion. In case the calling |
---|
1716 | * thread uses resources of the unmounted file system the function may never |
---|
1717 | * return. In case the calling thread has its root or current directory in the |
---|
1718 | * unmounted file system the function returns with an error status and errno is |
---|
1719 | * set to EBUSY. |
---|
1720 | * |
---|
1721 | * The unmount process completion notification uses the transient event. It is |
---|
1722 | * a fatal error to terminate the calling thread while waiting for this event. |
---|
1723 | * |
---|
1724 | * A concurrent unmount request for the same file system instance has |
---|
1725 | * unpredictable effects. |
---|
1726 | * |
---|
1727 | * @param[in] mount_path The path to the file system instance mount point. |
---|
1728 | * |
---|
1729 | * @retval 0 Successful operation. |
---|
1730 | * @retval -1 An error occurred. The @c errno indicates the error. |
---|
1731 | * |
---|
1732 | * @see ClassicEventTransient. |
---|
1733 | */ |
---|
1734 | int unmount( |
---|
1735 | const char *mount_path |
---|
1736 | ); |
---|
1737 | |
---|
1738 | /** |
---|
1739 | * @brief Mounts a file system instance at the specified target path. |
---|
1740 | * |
---|
1741 | * To mount a standard file system instance one of the following defines should |
---|
1742 | * be used to select the file system type |
---|
1743 | * - RTEMS_FILESYSTEM_TYPE_DOSFS, |
---|
1744 | * - RTEMS_FILESYSTEM_TYPE_FTPFS, |
---|
1745 | * - RTEMS_FILESYSTEM_TYPE_IMFS, |
---|
1746 | * - RTEMS_FILESYSTEM_TYPE_JFFS2, |
---|
1747 | * - RTEMS_FILESYSTEM_TYPE_NFS, |
---|
1748 | * - RTEMS_FILESYSTEM_TYPE_RFS, or |
---|
1749 | * - RTEMS_FILESYSTEM_TYPE_TFTPFS. |
---|
1750 | * |
---|
1751 | * Only configured or registered file system types are available. You can add |
---|
1752 | * file system types to your application configuration with the following |
---|
1753 | * configuration options |
---|
1754 | * - CONFIGURE_FILESYSTEM_DOSFS, |
---|
1755 | * - CONFIGURE_FILESYSTEM_FTPFS, |
---|
1756 | * - CONFIGURE_FILESYSTEM_IMFS, |
---|
1757 | * - CONFIGURE_FILESYSTEM_JFFS2, |
---|
1758 | * - CONFIGURE_FILESYSTEM_NFS, |
---|
1759 | * - CONFIGURE_FILESYSTEM_RFS, and |
---|
1760 | * - CONFIGURE_FILESYSTEM_TFTPFS. |
---|
1761 | * |
---|
1762 | * In addition to these configuration options file system types can be |
---|
1763 | * registered with rtems_filesystem_register(). |
---|
1764 | * |
---|
1765 | * @param[in] source The source parameter will be forwarded to the file system |
---|
1766 | * initialization handler. Usually the source is a path to the corresponding |
---|
1767 | * device file, or @c NULL in case the file system does not use a device file. |
---|
1768 | * @param[in] target The target path must lead to an existing directory, or |
---|
1769 | * must be @c NULL. In case the target is @c NULL, the root file system will |
---|
1770 | * be mounted. |
---|
1771 | * @param[in] filesystemtype This string selects the file system type. |
---|
1772 | * @param[in] options The options specify if the file system instance allows |
---|
1773 | * read-write or read-only access. |
---|
1774 | * @param[in] data The data parameter will be forwarded to the file system |
---|
1775 | * initialization handler. It can be used to pass file system specific mount |
---|
1776 | * options. The data structure for mount options is file system specific. See |
---|
1777 | * also in the corresponding file system documentation. |
---|
1778 | * |
---|
1779 | * @retval 0 Successful operation. |
---|
1780 | * @retval -1 An error occurred. The @c errno indicates the error. |
---|
1781 | * |
---|
1782 | * @see rtems_filesystem_register(), mount_and_make_target_path(), @ref DOSFS |
---|
1783 | * and @ref JFFS2. |
---|
1784 | */ |
---|
1785 | int mount( |
---|
1786 | const char *source, |
---|
1787 | const char *target, |
---|
1788 | const char *filesystemtype, |
---|
1789 | rtems_filesystem_options_t options, |
---|
1790 | const void *data |
---|
1791 | ); |
---|
1792 | |
---|
1793 | /** |
---|
1794 | * @brief Mounts a file system and makes the @a target path. |
---|
1795 | * |
---|
1796 | * The @a target path will be created with rtems_mkdir() and must not be |
---|
1797 | * @c NULL. |
---|
1798 | * |
---|
1799 | * @see mount(). |
---|
1800 | * |
---|
1801 | * @retval 0 Successful operation. |
---|
1802 | * @retval -1 An error occurred. The @c errno indicates the error. |
---|
1803 | */ |
---|
1804 | int mount_and_make_target_path( |
---|
1805 | const char *source, |
---|
1806 | const char *target, |
---|
1807 | const char *filesystemtype, |
---|
1808 | rtems_filesystem_options_t options, |
---|
1809 | const void *data |
---|
1810 | ); |
---|
1811 | |
---|
1812 | /** |
---|
1813 | * @brief Per file system type routine. |
---|
1814 | * |
---|
1815 | * @see rtems_filesystem_iterate(). |
---|
1816 | * |
---|
1817 | * @retval true Stop the iteration. |
---|
1818 | * @retval false Continue the iteration. |
---|
1819 | */ |
---|
1820 | typedef bool (*rtems_per_filesystem_routine)( |
---|
1821 | const rtems_filesystem_table_t *fs_entry, |
---|
1822 | void *arg |
---|
1823 | ); |
---|
1824 | |
---|
1825 | /** |
---|
1826 | * @brief Iterates over all file system types. |
---|
1827 | * |
---|
1828 | * For each file system type the @a routine will be called with the entry and |
---|
1829 | * the @a routine_arg parameter. |
---|
1830 | * |
---|
1831 | * Do not register or unregister file system types in @a routine. |
---|
1832 | * |
---|
1833 | * The iteration is protected by the IO library mutex. |
---|
1834 | * |
---|
1835 | * @retval true Iteration stopped due to @a routine return status. |
---|
1836 | * @retval false Iteration through all entries. |
---|
1837 | */ |
---|
1838 | bool rtems_filesystem_iterate( |
---|
1839 | rtems_per_filesystem_routine routine, |
---|
1840 | void *routine_arg |
---|
1841 | ); |
---|
1842 | |
---|
1843 | /** |
---|
1844 | * @brief Mount table entry visitor. |
---|
1845 | * |
---|
1846 | * @retval true Stop the iteration. |
---|
1847 | * @retval false Continue the iteration. |
---|
1848 | * |
---|
1849 | * @see rtems_filesystem_mount_iterate(). |
---|
1850 | */ |
---|
1851 | typedef bool (*rtems_filesystem_mt_entry_visitor)( |
---|
1852 | const rtems_filesystem_mount_table_entry_t *mt_entry, |
---|
1853 | void *arg |
---|
1854 | ); |
---|
1855 | |
---|
1856 | /** |
---|
1857 | * @brief Iterates over all file system mount entries. |
---|
1858 | * |
---|
1859 | * The iteration is protected by the IO library mutex. Do not mount or unmount |
---|
1860 | * file systems in the visitor function. |
---|
1861 | * |
---|
1862 | * @param[in] visitor For each file system mount entry the visitor function |
---|
1863 | * will be called with the entry and the visitor argument as parameters. |
---|
1864 | * @param[in] visitor_arg The second parameter for the visitor function. |
---|
1865 | * |
---|
1866 | * @retval true Iteration stopped due to visitor function return status. |
---|
1867 | * @retval false Iteration through all entries. |
---|
1868 | */ |
---|
1869 | bool rtems_filesystem_mount_iterate( |
---|
1870 | rtems_filesystem_mt_entry_visitor visitor, |
---|
1871 | void *visitor_arg |
---|
1872 | ); |
---|
1873 | |
---|
1874 | typedef struct { |
---|
1875 | const char *source; |
---|
1876 | const char *target; |
---|
1877 | const char *filesystemtype; |
---|
1878 | rtems_filesystem_options_t options; |
---|
1879 | const void *data; |
---|
1880 | } rtems_filesystem_mount_configuration; |
---|
1881 | |
---|
1882 | extern const rtems_filesystem_mount_configuration |
---|
1883 | rtems_filesystem_root_configuration; |
---|
1884 | |
---|
1885 | /** @} */ |
---|
1886 | |
---|
1887 | /** |
---|
1888 | * @defgroup Termios Termios |
---|
1889 | * |
---|
1890 | * @ingroup LibIO |
---|
1891 | * |
---|
1892 | * @brief Termios |
---|
1893 | */ |
---|
1894 | /**@{**/ |
---|
1895 | |
---|
1896 | struct rtems_termios_tty; |
---|
1897 | |
---|
1898 | typedef struct rtems_termios_callbacks { |
---|
1899 | int (*firstOpen)(int major, int minor, void *arg); |
---|
1900 | int (*lastClose)(int major, int minor, void *arg); |
---|
1901 | int (*pollRead)(int minor); |
---|
1902 | ssize_t (*write)(int minor, const char *buf, size_t len); |
---|
1903 | int (*setAttributes)(int minor, const struct termios *t); |
---|
1904 | int (*stopRemoteTx)(int minor); |
---|
1905 | int (*startRemoteTx)(int minor); |
---|
1906 | rtems_termios_device_mode outputUsesInterrupts; |
---|
1907 | } rtems_termios_callbacks; |
---|
1908 | |
---|
1909 | static inline void rtems_termios_initialize( void ) |
---|
1910 | { |
---|
1911 | /* Nothing to do, provided for backward compatibility */ |
---|
1912 | } |
---|
1913 | |
---|
1914 | /* |
---|
1915 | * CCJ: Change before opening a tty. Newer code from Eric is coming |
---|
1916 | * so extra work to handle an open tty is not worth it. If the tty |
---|
1917 | * is open, close then open it again. |
---|
1918 | */ |
---|
1919 | rtems_status_code rtems_termios_bufsize ( |
---|
1920 | size_t cbufsize, /* cooked buffer size */ |
---|
1921 | size_t raw_input, /* raw input buffer size */ |
---|
1922 | size_t raw_output /* raw output buffer size */ |
---|
1923 | ); |
---|
1924 | |
---|
1925 | /** |
---|
1926 | * @brief The status code returned by all Termios input processing (iproc) |
---|
1927 | * functions and input signal (isig) handlers. |
---|
1928 | */ |
---|
1929 | typedef enum { |
---|
1930 | /** |
---|
1931 | * @brief This status indicates that the input processing can continue. |
---|
1932 | * |
---|
1933 | * Input signal handlers shall return this status if no signal was raised and |
---|
1934 | * the input processing can continue. |
---|
1935 | */ |
---|
1936 | RTEMS_TERMIOS_IPROC_CONTINUE, |
---|
1937 | |
---|
1938 | /** |
---|
1939 | * @brief This status indicates that the input processing should stop due to |
---|
1940 | * a signal. |
---|
1941 | * |
---|
1942 | * This indicates that the character was processed and determined to be one |
---|
1943 | * that requires a signal to be raised (e.g. VINTR or VKILL). The tty must |
---|
1944 | * be in the right Termios mode for this to occur. There is no further |
---|
1945 | * processing of this character required and the pending read() operation |
---|
1946 | * should be interrupted. |
---|
1947 | */ |
---|
1948 | RTEMS_TERMIOS_IPROC_INTERRUPT, |
---|
1949 | |
---|
1950 | /** |
---|
1951 | * @brief This status indicates that the input processing is done. |
---|
1952 | * |
---|
1953 | * This status shall not be returned by input processing signal handlers. |
---|
1954 | */ |
---|
1955 | RTEMS_TERMIOS_IPROC_DONE |
---|
1956 | } rtems_termios_iproc_status_code; |
---|
1957 | |
---|
1958 | /** |
---|
1959 | * @brief Type for ISIG (VINTR/VKILL) handler |
---|
1960 | * |
---|
1961 | * This type defines the interface to a method which will process |
---|
1962 | * VKILL and VINTR characters. The user can register a handler to |
---|
1963 | * override the default behavior which is to take no special action |
---|
1964 | * on these characters. The POSIX required behavior is to |
---|
1965 | * generate a SIGINTR or SIGQUIT signal. This behavior is implemented if |
---|
1966 | * the user registers the @ref rtems_termios_posix_isig_handler(). |
---|
1967 | * |
---|
1968 | * @param c character that was input |
---|
1969 | * @param tty termios structure pointer for this input tty |
---|
1970 | * |
---|
1971 | * @return The value returned is according to that documented |
---|
1972 | * for @ref rtems_termios_iproc_status_code. |
---|
1973 | */ |
---|
1974 | typedef rtems_termios_iproc_status_code (*rtems_termios_isig_handler)( |
---|
1975 | unsigned char c, |
---|
1976 | struct rtems_termios_tty *tty |
---|
1977 | ); |
---|
1978 | |
---|
1979 | /** |
---|
1980 | * @brief Default handler for ISIG (VINTR/VKILL) |
---|
1981 | * |
---|
1982 | * This handler is installed by default by termios. It performs |
---|
1983 | * no actions on receiving the VINTR and VKILL characters. This is |
---|
1984 | * not POSIX conformant behavior but is the historical RTEMS behavior |
---|
1985 | * and avoid any default dependency on signal processing code. |
---|
1986 | * |
---|
1987 | * @param c character that was input |
---|
1988 | * @param tty termios structure pointer for this input tty |
---|
1989 | * |
---|
1990 | * The installed ISIG handler is only invoked if the character is |
---|
1991 | * (VKILL or VINTR) and ISIG is enabled. Thus the handler need only |
---|
1992 | * check the character and perform the appropriate action. |
---|
1993 | * |
---|
1994 | * @return The value returned is according to that documented |
---|
1995 | * for all methods adhering to @ref rtems_termios_isig_handler. |
---|
1996 | */ |
---|
1997 | rtems_termios_iproc_status_code rtems_termios_default_isig_handler( |
---|
1998 | unsigned char c, |
---|
1999 | struct rtems_termios_tty *tty |
---|
2000 | ); |
---|
2001 | |
---|
2002 | /** |
---|
2003 | * @brief POSIX handler for ISIG (VINTR/VKILL) |
---|
2004 | * |
---|
2005 | * This handler is installed by the used to obtain POSIX behavior |
---|
2006 | * upon receiving the VINTR and VKILL characters. The POSIX required |
---|
2007 | * behavior is to generate a SIGINTR or SIGQUIT signal if ISIG is enabled. |
---|
2008 | * |
---|
2009 | * @param c character that was input |
---|
2010 | * @param tty termios structure pointer for this input tty |
---|
2011 | * |
---|
2012 | * @return The value returned is according to that documented |
---|
2013 | * for all methods adhering to @ref rtems_termios_isig_handler. |
---|
2014 | */ |
---|
2015 | rtems_termios_iproc_status_code rtems_termios_posix_isig_handler( |
---|
2016 | unsigned char c, |
---|
2017 | struct rtems_termios_tty *tty |
---|
2018 | ); |
---|
2019 | |
---|
2020 | /** |
---|
2021 | * @brief Register handler for ISIG (VINTR/VKILL) |
---|
2022 | * |
---|
2023 | * This method is invoked to install an ISIG handler. This may be used |
---|
2024 | * to install @ref rtems_termios_posix_isig_handler() to obtain POSIX |
---|
2025 | * behavior or a custom handler. The handler |
---|
2026 | * @ref rtems_termios_default_isig_handler() is installed by default. |
---|
2027 | * |
---|
2028 | * @param handler entry point of the new ISIG handler |
---|
2029 | * |
---|
2030 | * @retval RTEMS_SUCCESSFUL if successful or error code if unsuccessful. |
---|
2031 | */ |
---|
2032 | rtems_status_code rtems_termios_register_isig_handler( |
---|
2033 | rtems_termios_isig_handler handler |
---|
2034 | ); |
---|
2035 | |
---|
2036 | int rtems_termios_enqueue_raw_characters( |
---|
2037 | void *ttyp, |
---|
2038 | const char *buf, |
---|
2039 | int len |
---|
2040 | ); |
---|
2041 | |
---|
2042 | rtems_status_code rtems_termios_open ( |
---|
2043 | rtems_device_major_number major, |
---|
2044 | rtems_device_minor_number minor, |
---|
2045 | void *arg, |
---|
2046 | const rtems_termios_callbacks *callbacks |
---|
2047 | ); |
---|
2048 | |
---|
2049 | rtems_status_code rtems_termios_close( |
---|
2050 | void *arg |
---|
2051 | ); |
---|
2052 | |
---|
2053 | rtems_status_code rtems_termios_read( |
---|
2054 | void *arg |
---|
2055 | ); |
---|
2056 | |
---|
2057 | rtems_status_code rtems_termios_write( |
---|
2058 | void *arg |
---|
2059 | ); |
---|
2060 | |
---|
2061 | rtems_status_code rtems_termios_ioctl( |
---|
2062 | void *arg |
---|
2063 | ); |
---|
2064 | |
---|
2065 | int rtems_termios_dequeue_characters( |
---|
2066 | void *ttyp, |
---|
2067 | int len |
---|
2068 | ); |
---|
2069 | |
---|
2070 | /** @} */ |
---|
2071 | |
---|
2072 | /** |
---|
2073 | * @brief The pathconf setting for a file system. |
---|
2074 | */ |
---|
2075 | #define rtems_filesystem_pathconf(_mte) ((_mte)->pathconf_limits_and_options) |
---|
2076 | |
---|
2077 | /** |
---|
2078 | * @brief The type of file system. Its name. |
---|
2079 | */ |
---|
2080 | #define rtems_filesystem_type(_mte) ((_mte)->type) |
---|
2081 | |
---|
2082 | /** |
---|
2083 | * @brief The mount point of a file system. |
---|
2084 | */ |
---|
2085 | #define rtems_filesystem_mount_point(_mte) ((_mte)->target) |
---|
2086 | |
---|
2087 | /** |
---|
2088 | * @brief The device entry of a file system. |
---|
2089 | */ |
---|
2090 | #define rtems_filesystem_mount_device(_mte) ((_mte)->dev) |
---|
2091 | |
---|
2092 | #ifdef __cplusplus |
---|
2093 | } |
---|
2094 | #endif |
---|
2095 | |
---|
2096 | #endif /* _RTEMS_LIBIO_H */ |
---|