source: rtems/cpukit/libcsupport/include/rtems/libio.h @ 7666afc

4.11
Last change on this file since 7666afc was 7666afc, checked in by Sebastian Huber <sebastian.huber@…>, on May 14, 2012 at 2:53:49 PM

Filesystem: Add const qualifier to lock/unlock

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