source: rtems/cpukit/include/rtems/libio.h @ ea41722c

Last change on this file since ea41722c was ea41722c, checked in by Ryan Long <ryan.long@…>, on 04/30/21 at 17:14:48

Change filesystem utime_h handler to utimens_h

Also updated licenses.

Closes #4400
Updates #3899

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