source: rtems/cpukit/include/rtems/libio.h @ 7e86e00

5
Last change on this file since 7e86e00 was 2c12262, checked in by Sebastian Huber <sebastian.huber@…>, on 11/28/17 at 05:30:35

termios: Use self-contained objects

Update #2840.

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