source: rtems/cpukit/libcsupport/include/rtems/libio.h @ 03e54614

4.11
Last change on this file since 03e54614 was 03e54614, checked in by Joel Sherrill <joel.sherrill@…>, on Nov 27, 2013 at 7:06:16 PM

statvfs filesystem handlers: Remove restrict

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