source: rtems/cpukit/libcsupport/include/rtems/libio.h @ f9a4e80

4.11
Last change on this file since f9a4e80 was f9a4e80, checked in by Jennifer Averett <Jennifer.Averett@…>, on Jun 25, 2010 at 2:23:48 PM

2010-06-25 Jennifer Averett <Jennifer.Averett@…

  • libcsupport/include/rtems/libio.h, libfs/Makefile.am: Added default filesystem handlers.
  • libfs/src/defaults/default_chown.c, libfs/src/defaults/default_evalpath.c, libfs/src/defaults/default_fchmod.c, libfs/src/defaults/default_fcntl.c, libfs/src/defaults/default_fdatasync.c, libfs/src/defaults/default_freenode.c, libfs/src/defaults/default_fsmount.c, libfs/src/defaults/default_fstat.c, libfs/src/defaults/default_fsync.c, libfs/src/defaults/default_ftruncate.c, libfs/src/defaults/default_ioctl.c, libfs/src/defaults/default_link.c, libfs/src/defaults/default_lseek.c, libfs/src/defaults/default_mount.c, libfs/src/defaults/default_read.c, libfs/src/defaults/default_readlink.c, libfs/src/defaults/default_rename.c, libfs/src/defaults/default_rmnod.c, libfs/src/defaults/default_statvfs.c, libfs/src/defaults/default_symlink.c, libfs/src/defaults/default_unlink.c, libfs/src/defaults/default_utime.c, libfs/src/defaults/default_write.c: New files.
  • Property mode set to 100644
File size: 41.7 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 *  The license and distribution terms for this file may be
14 *  found in the file LICENSE in this distribution or at
15 *  http://www.rtems.com/license/LICENSE.
16 *
17 *  $Id$
18 */
19
20#ifndef _RTEMS_RTEMS_LIBIO_H
21#define _RTEMS_RTEMS_LIBIO_H
22
23#include <sys/types.h>
24#include <sys/stat.h>
25#include <sys/ioctl.h>
26#include <sys/statvfs.h>
27
28#include <unistd.h>
29#include <termios.h>
30
31#include <rtems.h>
32#include <rtems/fs.h>
33#include <rtems/chain.h>
34
35#ifdef __cplusplus
36extern "C" {
37#endif
38
39/**
40 * @defgroup LibIO IO Library
41 *
42 * @brief Provides system call and file system interface definitions.
43 *
44 * General purpose communication channel for RTEMS to allow UNIX/POSIX
45 * system call behavior under RTEMS.  Initially this supported only
46 * IO to devices but has since been enhanced to support networking
47 * and support for mounted file systems.
48 *
49 * @{
50 */
51
52/**
53 * A 64-bit file offset for internal use by RTEMS. Based on the Newlib
54 * type.
55 */
56typedef _off64_t rtems_off64_t;
57
58/**
59 * @name File System Node Types
60 *
61 * @{
62 */
63
64#define RTEMS_FILESYSTEM_DIRECTORY   1
65#define RTEMS_FILESYSTEM_DEVICE      2
66#define RTEMS_FILESYSTEM_HARD_LINK   3
67#define RTEMS_FILESYSTEM_SYM_LINK    4
68#define RTEMS_FILESYSTEM_MEMORY_FILE 5
69
70/** @} */
71
72typedef int rtems_filesystem_node_types_t;
73
74/**
75 * @name File System Node Operations
76 *
77 * @{
78 */
79
80/**
81 *  This type defines the interface to the open(2) system call
82 *  support which is provided by a file system implementation.
83 */
84typedef int (*rtems_filesystem_open_t)(
85  rtems_libio_t *iop,
86  const char    *pathname,
87  uint32_t       flag,
88  uint32_t       mode
89);
90
91/**
92 *  This type defines the interface to the close(2) system call
93 *  support which is provided by a file system implementation.
94 */
95typedef int (*rtems_filesystem_close_t)(
96  rtems_libio_t *iop
97);
98
99/**
100 *  This type defines the interface to the read(2) system call
101 *  support which is provided by a file system implementation.
102 */
103typedef ssize_t (*rtems_filesystem_read_t)(
104  rtems_libio_t *iop,
105  void          *buffer,
106  size_t         count
107);
108
109/**
110 *  This type defines the interface to the write(2) system call
111 *  support which is provided by a file system implementation.
112 */
113typedef ssize_t (*rtems_filesystem_write_t)(
114  rtems_libio_t *iop,
115  const void    *buffer,
116  size_t         count
117);
118
119/**
120 *  This type defines the interface to the ioctl(2) system call
121 *  support which is provided by a file system implementation.
122 */
123typedef int (*rtems_filesystem_ioctl_t)(
124  rtems_libio_t *iop,
125  uint32_t       command,
126  void          *buffer
127);
128
129/**
130 *  This type defines the interface to the lseek(2) system call
131 *  support which is provided by a file system implementation.
132 */
133typedef rtems_off64_t (*rtems_filesystem_lseek_t)(
134  rtems_libio_t *iop,
135  rtems_off64_t  length,
136  int            whence
137);
138
139/**
140 *  This type defines the interface to the fstat(2) system call
141 *  support which is provided by a file system implementation.
142 */
143typedef int (*rtems_filesystem_fstat_t)(
144  rtems_filesystem_location_info_t *loc,
145  struct stat                      *buf
146);
147
148/**
149 *  This type defines the interface to the fchmod(2) system call
150 *  support which is provided by a file system implementation.
151 */
152typedef int (*rtems_filesystem_fchmod_t)(
153  rtems_filesystem_location_info_t *loc,
154  mode_t                            mode
155);
156
157/**
158 *  This type defines the interface to the ftruncate(2) system call
159 *  support which is provided by a file system implementation.
160 */
161typedef int (*rtems_filesystem_ftruncate_t)(
162  rtems_libio_t *iop,
163  rtems_off64_t  length
164);
165
166/**
167 *  This type defines the interface to the fpathconf(2) system call
168 *  support which is provided by a file system implementation.
169 */
170typedef int (*rtems_filesystem_fpathconf_t)(
171  rtems_libio_t *iop,
172  int name
173);
174
175/**
176 *  This type defines the interface to the fsync(2) system call
177 *  support which is provided by a file system implementation.
178 */
179typedef int (*rtems_filesystem_fsync_t)(
180  rtems_libio_t *iop
181);
182
183/**
184 *  This type defines the interface to the fdatasync(2) system call
185 *  support which is provided by a file system implementation.
186 */
187typedef int (*rtems_filesystem_fdatasync_t)(
188  rtems_libio_t *iop
189);
190
191/**
192 *  This type defines the interface to the fnctl(2) system call
193 *  support which is provided by a file system implementation.
194 */
195typedef int (*rtems_filesystem_fcntl_t)(
196  int            cmd,
197  rtems_libio_t *iop
198);
199
200typedef int (*rtems_filesystem_rmnod_t)(
201 rtems_filesystem_location_info_t      *parent_loc,   /* IN */
202 rtems_filesystem_location_info_t      *pathloc       /* IN */
203);
204
205/** @} */
206
207/**
208 * @brief File system node operations table.
209 */
210struct _rtems_filesystem_file_handlers_r {
211  /**
212   *  This field points to the file system specific implementation
213   *  of the support routine for the open(2) system call
214   *
215   *  @note This method must have a filesystem specific implementation.
216   *
217   *  @note There is no default implementation.
218   */
219  rtems_filesystem_open_t         open_h;
220
221  /**
222   *  This field points to the file system specific implementation
223   *  of the support routine for the close(2) system call
224   *
225   *  @note This method is REQUIRED by all file systems.
226   *
227   *  @note There is no default implementation.
228   */
229  rtems_filesystem_close_t        close_h;
230
231  /**
232   *  This field points to the file system specific implementation
233   *  of the support routine for the read(2) system call
234   *
235   *  @note This method must have a filesystem specific implementation.
236   *
237   *  @note The default implementation returns -1 and sets
238   *  errno to ENOTSUP.
239   */
240  rtems_filesystem_read_t         read_h;
241
242  /**
243   *  This field points to the file system specific implementation
244   *  of the support routine for the write(2) system call
245   *
246   *  @note This method may use a default implementation.
247   *
248   *  @note The default implementation returns -1 and sets
249   *  errno to ENOTSUP.
250   */
251  rtems_filesystem_write_t        write_h;
252
253  /**
254   *  This field points to the file system specific implementation
255   *  of the support routine for the ioctl(2) system call
256   *
257   *  @note This method may use a default implementation.
258   *
259   *  @note The default implementation returns -1 and sets
260   *  errno to ENOTSUP.
261   */
262  rtems_filesystem_ioctl_t        ioctl_h;
263
264  /**
265   *  This field points to the file system specific implementation
266   *  of the support routine for the lseek(2) system call
267   *
268   *  @note This method may use a default implementation.
269   *
270   *  @note The default implementation returns -1 and sets
271   *  errno to ENOTSUP.
272   */
273  rtems_filesystem_lseek_t        lseek_h;
274
275  /**
276   *  This field points to the file system specific implementation
277   *  of the support routine for the fstat(2) system call
278   *
279   *  @note This method may use a default implementation.
280   *
281   *  @note The default implementation returns -1 and sets
282   *  errno to ENOTSUP.
283   */
284  rtems_filesystem_fstat_t        fstat_h;
285
286  /**
287   *  This field points to the file system specific implementation
288   *  of the support routine for the fchmod(2) system call
289   *
290   *  @note This method may use a default implementation.
291   *
292   *  @note The default implementation returns -1 and sets
293   *  errno to ENOTSUP.
294   */
295  rtems_filesystem_fchmod_t       fchmod_h;
296
297  /**
298   *  This field points to the file system specific implementation
299   *  of the support routine for the ftruncate(2) system call
300   *
301   *  @note This method may use a default implementation.
302   *
303   *  @note The default implementation returns -1 and sets
304   *  errno to ENOTSUP.
305   */
306  rtems_filesystem_ftruncate_t    ftruncate_h;
307
308  /**
309   *  This field points to the file system specific implementation
310   *  of the support routine for the fpathconf(2) system call
311   *
312   *  @note This method may use a default implementation.
313   *
314   *  @note The default implementation returns -1 and sets
315   *  errno to ENOTSUP.
316   */
317  rtems_filesystem_fpathconf_t    fpathconf_h;
318
319  /**
320   *  This field points to the file system specific implementation
321   *  of the support routine for the fsync(2) system call
322   *
323   *  @note This method may use a default implementation.
324   *
325   *  @note The default implementation returns -1 and sets
326   *  errno to ENOTSUP.
327   */
328  rtems_filesystem_fsync_t        fsync_h;
329
330  /**
331   *  This field points to the file system specific implementation
332   *  of the support routine for the fdatasync(2) system call
333   *
334   *  @note This method may use a default implementation.
335   *
336   *  @note The default implementation returns -1 and sets
337   *  errno to ENOTSUP.
338   */
339  rtems_filesystem_fdatasync_t    fdatasync_h;
340
341  /**
342   *  This field points to the file system specific implementation
343   *  of the support routine for the fcntl(2) system call
344   *
345   *  @note This method may use a default implementation.
346   *
347   *  @note The default implementation returns -1 and sets
348   *  errno to ENOTSUP.
349   */
350  rtems_filesystem_fcntl_t        fcntl_h;
351
352  /**
353   *  This field points to the file system specific implementation
354   *  of the support routine for the rmnod(2) system call
355   *
356   *  @note This method may use a default implementation.
357   *
358   *  @note The default implementation returns -1 and sets
359   *  errno to ENOTSUP.
360   */
361  rtems_filesystem_rmnod_t        rmnod_h;
362};
363
364/**
365 *  This method defines the interface to the default read(2)
366 *  system call support which is provided by a file system
367 *  implementation.
368 */
369size_t rtems_filesystem_default_read(
370  rtems_libio_t *iop,
371  void          *buffer,
372  size_t         count
373);
374
375/**
376 *  This method defines the interface to the default write(2) system call
377 *  support which is provided by a file system implementation.
378 */
379ssize_t rtems_filesystem_default_write(
380  rtems_libio_t *iop,
381  const void    *buffer,
382  size_t         count
383);
384
385/**
386 *  This method defines the interface to the default ioctl(2) system call
387 *  support which is provided by a file system implementation.
388 */
389int rtems_filesystem_default_ioctl(
390  rtems_libio_t *iop,
391  uint32_t       command,
392  void          *buffer
393);
394
395/**
396 *  This method defines the interface to the default lseek(2) system call
397 *  support which is provided by a file system implementation.
398 */
399rtems_off64_t rtems_filesystem_default_lseek(
400  rtems_libio_t *iop,
401  rtems_off64_t  length,
402  int            whence
403);
404
405/**
406 *  This method defines the interface to the default fstat(2) system call
407 *  support which is provided by a file system implementation.
408 */
409int rtems_filesystem_default_fstat(
410  rtems_filesystem_location_info_t *loc,
411  struct stat                      *buf
412);
413
414/**
415 *  This method defines the interface to the default fchmod(2) system call
416 *  support which is provided by a file system implementation.
417 */
418int rtems_filesystem_default_fchmod(
419  rtems_filesystem_location_info_t *loc,
420  mode_t                            mode
421);
422
423/**
424 *  This method defines the interface to the default ftruncate(2) system call
425 *  support which is provided by a file system implementation.
426 */
427int rtems_filesystem_default_ftruncate(
428  rtems_libio_t *iop,
429  rtems_off64_t  length
430);
431
432/**
433 *  This method defines the interface to the default fpathconf(2) system call
434 *  support which is provided by a file system implementation.
435 */
436int rtems_filesystem_default_fpathconf(
437  rtems_libio_t *iop,
438  int name
439);
440
441/**
442 *  This method defines the interface to the default fsync(2) system call
443 *  support which is provided by a file system implementation.
444 */
445int rtems_filesystem_default_fsync(
446  rtems_libio_t *iop
447);
448
449/**
450 *  This method defines the interface to the default fdatasync(2) system call
451 *  support which is provided by a file system implementation.
452 */
453int rtems_filesystem_default_fdatasync(
454  rtems_libio_t *iop
455);
456
457/**
458 *  This method defines the interface to the default fnctl(2) system call
459 *  support which is provided by a file system implementation.
460 */
461int rtems_filesystem_default_fcntl(
462  int            cmd,
463  rtems_libio_t *iop
464);
465
466/**
467 *  This method defines the interface to the default rmnod(2) system call
468 *  support which is provided by a file system implementation.
469 */
470int rtems_filesystem_default_rmnod(
471 rtems_filesystem_location_info_t      *parent_loc,   /* IN */
472 rtems_filesystem_location_info_t      *pathloc       /* IN */
473);
474
475/**
476 * @name File System Operations
477 *
478 * @{
479 */
480
481/**
482 *  This type defines the interface to the mknod(2) system call
483 *  support which is provided by a file system implementation.
484 * 
485 *  @note This routine does not allocate any space and
486 *  rtems_filesystem_freenode_t is not called by the generic
487 *  after calling this routine. ie. node_access does not have
488 *  to contain valid data when the routine returns.
489 */
490typedef int (*rtems_filesystem_mknod_t)(
491   const char                        *path,       /* IN */
492   mode_t                             mode,       /* IN */
493   dev_t                              dev,        /* IN */
494   rtems_filesystem_location_info_t  *pathloc     /* IN/OUT */
495);
496
497/**
498 *  This type defines the interface that allows the 
499 *  file system implementation to parse a path and
500 *  allocate any memory necessary for tracking purposes.
501 *
502 *  @note rtems_filesystem_freenode_t must be called by
503 *  the generic after calling this routine
504 */
505typedef int (*rtems_filesystem_evalpath_t)(
506  const char                        *pathname,      /* IN     */
507  size_t                             pathnamelen,   /* IN     */
508  int                                flags,         /* IN     */
509  rtems_filesystem_location_info_t  *pathloc        /* IN/OUT */
510);
511
512/**
513 *  This type defines the interface that allows the 
514 *  file system implementation to parse a path with the
515 *  intent of creating a new node and to 
516 *  allocate any memory necessary for tracking purposes.
517 *
518 *  @note rtems_filesystem_freenode_t must be called by
519 *  the generic after calling this routine
520 */
521typedef int (*rtems_filesystem_evalmake_t)(
522   const char                       *path,       /* IN */
523   rtems_filesystem_location_info_t *pathloc,    /* IN/OUT */
524   const char                      **name        /* OUT    */
525);
526
527/**
528 *  This type defines the interface to the link(2) system call
529 *  support which is provided by a file system implementation.
530 */ 
531typedef int (*rtems_filesystem_link_t)(
532  rtems_filesystem_location_info_t  *to_loc,      /* IN */
533  rtems_filesystem_location_info_t  *parent_loc,  /* IN */
534  const char                        *name         /* IN */
535);
536
537/**
538 *  This type defines the interface to the unlink(2) system call
539 *  support which is provided by a file system implementation.
540 */ 
541typedef int (*rtems_filesystem_unlink_t)(
542  rtems_filesystem_location_info_t  *parent_pathloc, /* IN */
543  rtems_filesystem_location_info_t  *pathloc         /* IN */
544);
545
546/**
547 *  This type defines the interface to the chown(2) system call
548 *  support which is provided by a file system implementation.
549 */ 
550typedef int (*rtems_filesystem_chown_t)(
551  rtems_filesystem_location_info_t  *pathloc,       /* IN */
552  uid_t                              owner,         /* IN */
553  gid_t                              group          /* IN */
554);
555
556/**
557 *  This type defines the interface to the freenod(2) system call
558 *  support which is provided by a file system implementation.
559 */ 
560typedef int (*rtems_filesystem_freenode_t)(
561 rtems_filesystem_location_info_t      *pathloc       /* IN */
562);
563
564/**
565 *  This type defines the interface that allows the implemented
566 *  filesystem ot mount another filesystem at the given location.
567 */ 
568typedef int (* rtems_filesystem_mount_t ) (
569   rtems_filesystem_mount_table_entry_t *mt_entry     /* IN */
570);
571
572/**
573 *  This type defines the interface that allows a file system
574 *  implementation to do any necessary work that is needed when
575 *  it is being mounted.
576 */ 
577typedef int (* rtems_filesystem_fsmount_me_t )(
578  rtems_filesystem_mount_table_entry_t *mt_entry,     /* IN */
579  const void                           *data          /* IN */
580);
581
582/**
583 *  This type defines the interface allow the filesystem to
584 *  unmount a filesystem that was mounted at one of its node
585 *  locations.
586 */ 
587typedef int (* rtems_filesystem_unmount_t ) (
588  rtems_filesystem_mount_table_entry_t *mt_entry     /* IN */
589);
590
591/**
592 *  This type defines the interface that allows a file system
593 *  implementation to do any necessary work that is needed when
594 *  it is being unmounted.
595 */ 
596typedef int (* rtems_filesystem_fsunmount_me_t ) (
597   rtems_filesystem_mount_table_entry_t *mt_entry    /* IN */
598);
599
600/**
601 *  This type defines the interface that will return the
602 *  type of a filesystem implementations node.
603 */ 
604typedef rtems_filesystem_node_types_t (* rtems_filesystem_node_type_t) (
605  rtems_filesystem_location_info_t    *pathloc      /* IN */
606);
607
608/**
609 *  This type defines the interface to the time(2) system call
610 *  support which is provided by a file system implementation.
611 */ 
612typedef int (* rtems_filesystem_utime_t)(
613  rtems_filesystem_location_info_t  *pathloc,       /* IN */
614  time_t                             actime,        /* IN */
615  time_t                             modtime        /* IN */
616);
617
618/**
619 *  This type defines the interface to the link(2) system call
620 *  support which is provided by a file system implementation.
621 */ 
622typedef int (*rtems_filesystem_evaluate_link_t)(
623  rtems_filesystem_location_info_t *pathloc,     /* IN/OUT */
624  int                               flags        /* IN     */
625);
626
627/**
628 *  This type defines the interface to the symlink(2) system call
629 *  support which is provided by a file system implementation.
630 */ 
631typedef int (*rtems_filesystem_symlink_t)(
632 rtems_filesystem_location_info_t  *loc,         /* IN */
633 const char                        *link_name,   /* IN */
634 const char                        *node_name
635);
636
637/**
638 *  This type defines the interface to the readlink(2) system call
639 *  support which is provided by a file system implementation.
640 */ 
641typedef int (*rtems_filesystem_readlink_t)(
642 rtems_filesystem_location_info_t  *loc,     /* IN  */
643 char                              *buf,     /* OUT */
644 size_t                            bufsize
645);
646
647/**
648 *  This type defines the interface to the name(2) system call
649 *  support which is provided by a file system implementation.
650 */ 
651typedef int (*rtems_filesystem_rename_t)(
652 rtems_filesystem_location_info_t  *old_parent_loc,  /* IN */
653 rtems_filesystem_location_info_t  *old_loc,         /* IN */
654 rtems_filesystem_location_info_t  *new_parent_loc,  /* IN */
655 const char                        *name             /* IN */
656);
657
658/**
659 *  This type defines the interface to the statvfs(2) system call
660 *  support which is provided by a file system implementation.
661 */ 
662typedef int (*rtems_filesystem_statvfs_t)(
663 rtems_filesystem_location_info_t  *loc,     /* IN  */
664 struct statvfs                    *buf      /* OUT */
665);
666
667/** @} */
668
669/**
670 * @brief File system operations table.
671 */
672struct _rtems_filesystem_operations_table {
673
674    /**
675     *  This field points to the file system specific implementation
676     *  of the support routine that evaluates a character path and
677     *  returns the node assocated with the last node in the path.
678     *
679     *  @note This method must have a filesystem specific implementation.
680     *
681     *  @note There is no default implementation.
682     */
683    rtems_filesystem_evalpath_t      evalpath_h;
684
685    /**
686     *  This field points to the file system specific implementation
687     *  of the support routine that evaluates a character path and
688     *  returns the node assocated with next to the last node in
689     *  the path.  The last node will be the new node to be created.
690     *
691     *  @note This method must have a filesystem specific implementation.
692     *
693     *  @note There is no default implementation.
694     */
695    rtems_filesystem_evalmake_t      evalformake_h;
696
697    /**
698     *  This field points to the file system specific implementation
699     *  of the support routine for the link(2) system call
700     *
701     *  @note This method may use a default implementation.
702     *
703     *  @note The default implementation returns -1 and sets
704     *  errno to ENOTSUP.
705     */
706    rtems_filesystem_link_t          link_h;
707
708    /**
709     *  This field points to the file system specific implementation
710     *  of the support routine for the unlink(2) system call
711     *
712     *  @note This method may use a default implementation.
713     *
714     *  @note The default implementation returns -1 and sets
715     *  errno to ENOTSUP.
716     */
717    rtems_filesystem_unlink_t        unlink_h;
718
719    /**
720     *  This field points to the file system specific implementation
721     *  of a method that returns the node type of the given node.
722     *
723     *  @note This method may use a default implementation.
724     *
725     *  @note The default implementation returns -1 and sets
726     *  errno to ENOTSUP.
727     */
728    rtems_filesystem_node_type_t     node_type_h;
729
730    /**
731     *  This field points to the file system specific implementation
732     *  of the support routine for the link(2) system call
733     *
734     *  @note This method may use a mknod implementation.
735     *
736     *  @note The default implementation returns -1 and sets
737     *  errno to ENOTSUP.
738     */
739    rtems_filesystem_mknod_t         mknod_h;
740
741    /**
742     *  This field points to the file system specific implementation
743     *  of the support routine for the link(2) system call
744     *
745     *  @note This method may use a default implementation.
746     *
747     *  @note The default implementation returns -1 and sets
748     *  errno to ENOTSUP.
749     */
750    rtems_filesystem_chown_t         chown_h;
751
752    /**
753     *  This field points to the file system specific implementation
754     *  of the support routine for the freenod(2) system call
755     *
756     *  @note This method may use a default implementation.
757     *
758     *  @note The default implementation returns -1 and sets
759     *  errno to ENOTSUP.
760     */
761    rtems_filesystem_freenode_t      freenod_h;
762
763    /**
764     *  This field points to the file system specific implementation
765     *  of the support routine for the mount(2) system call
766     *
767     *  @note This method may use a default implementation.
768     *
769     *  @note The default implementation returns -1 and sets
770     *  errno to ENOTSUP.
771     */
772    rtems_filesystem_mount_t         mount_h;
773
774    /**
775     *  This field points to the file system specific implementation
776     *  of the support routine for the fsmount(2) system call
777     *
778     *  @note This method may use a default implementation.
779     *
780     *  @note The default implementation returns -1 and sets
781     *  errno to ENOTSUP.
782     */
783    rtems_filesystem_fsmount_me_t    fsmount_me_h;
784
785    /**
786     *  This field points to the file system specific implementation
787     *  of the support routine for the unmount(2) system call
788     *
789     *  @note This method may use a default implementation.
790     *
791     *  @note The default implementation returns -1 and sets
792     *  errno to ENOTSUP.
793     */
794    rtems_filesystem_unmount_t       unmount_h;
795
796    /**
797     *  This field points to the file system specific implementation
798     *  of the support routine for the fsunmount(2) system call
799     *
800     *  @note This method may use a default implementation.
801     *
802     *  @note The default implementation returns -1 and sets
803     *  errno to ENOTSUP.
804     */
805    rtems_filesystem_fsunmount_me_t  fsunmount_me_h;
806
807    /**
808     *  This field points to the file system specific implementation
809     *  of the support routine for the utime(2) system call
810     *
811     *  @note This method may use a default implementation.
812     *
813     *  @note The default implementation returns -1 and sets
814     *  errno to ENOTSUP.
815     */
816    rtems_filesystem_utime_t         utime_h;
817
818    /**
819     *  This field points to the file system specific implementation
820     *  of the support routine for the eval_link(2) system call
821     *
822     *  @note This method may use a default implementation.
823     *
824     *  @note The default implementation returns -1 and sets
825     *  errno to ENOTSUP.
826     */
827    rtems_filesystem_evaluate_link_t eval_link_h;
828
829    /**
830     *  This field points to the file system specific implementation
831     *  of the support routine for the sumlink(2) system call
832     *
833     *  @note This method may use a default implementation.
834     *
835     *  @note The default implementation returns -1 and sets
836     *  errno to ENOTSUP.
837     */
838    rtems_filesystem_symlink_t       symlink_h;
839
840    /**
841     *  This field points to the file system specific implementation
842     *  of the support routine for the readlink(2) system call
843     *
844     *  @note This method may use a default implementation.
845     *
846     *  @note The default implementation returns -1 and sets
847     *  errno to ENOTSUP.
848     */
849    rtems_filesystem_readlink_t      readlink_h;
850
851    /**
852     *  This field points to the file system specific implementation
853     *  of the support routine for the rename(2) system call
854     *
855     *  @note This method may use a default implementation.
856     *
857     *  @note The default implementation returns -1 and sets
858     *  errno to ENOTSUP.
859     */
860    rtems_filesystem_rename_t        rename_h;
861
862    /**
863     *  This field points to the file system specific implementation
864     *  of the support routine for the statvfs(2) system call
865     *
866     *  @note This method may use a default implementation.
867     *
868     *  @note The default implementation returns -1 and sets
869     *  errno to ENOTSUP.
870     */
871    rtems_filesystem_statvfs_t       statvfs_h;
872};
873
874/*
875 * @brief Default filesystem evalpath
876 */
877
878
879/**
880 * @brief Provides a defualt routine for filesystem
881 * implementation of a link command.
882 */
883int rtems_filesystem_default_link(
884 rtems_filesystem_location_info_t  *to_loc,      /* IN */
885 rtems_filesystem_location_info_t  *parent_loc,  /* IN */
886 const char                        *name         /* IN */
887);
888
889/**
890 * @brief Provides a defualt routine for filesystem
891 * implementation of a unlink command.
892 */
893int rtems_filesystem_default_unlink(
894 rtems_filesystem_location_info_t  *parent_pathloc, /* IN */
895 rtems_filesystem_location_info_t  *pathloc         /* IN */
896);
897
898/**
899 * @brief Provides a defualt routine for filesystem
900 * implementation of a chown command.
901 */
902int rtems_filesystem_default_chown(
903 rtems_filesystem_location_info_t  *pathloc,       /* IN */
904 uid_t                              owner,         /* IN */
905 gid_t                              group          /* IN */
906);
907
908/**
909 * @brief Provides a defualt routine for filesystem
910 * implementation of a freenode command.
911 */
912int rtems_filesystem_default_freenode(
913 rtems_filesystem_location_info_t      *pathloc       /* IN */
914);
915
916/**
917 * @brief Provides a defualt routine for filesystem
918 * implementation of a mount command.
919 */
920int rtems_filesystem_default_mount (
921   rtems_filesystem_mount_table_entry_t *mt_entry     /* IN */
922);
923
924/**
925 * @brief Provides a defualt routine for filesystem
926 * implementation of a fsmount command.
927 */
928int rtems_filesystem_default_fsmount(
929  rtems_filesystem_mount_table_entry_t *mt_entry,     /* IN */
930  const void                           *data          /* IN */
931);
932
933/**
934 * @brief Provides a defualt routine for filesystem
935 * implementation of a unmount command.
936 */
937int rtems_filesystem_default_unmount(
938  rtems_filesystem_mount_table_entry_t *mt_entry     /* IN */
939);
940
941/**
942 * @brief Provides a defualt routine for filesystem
943 * implementation of a fsunmount command.
944 */
945int rtems_filesystem_default_fsunmount(
946   rtems_filesystem_mount_table_entry_t *mt_entry    /* IN */
947);
948
949
950/**
951 * @brief Provides a defualt routine for filesystem
952 * implementation of a utime command.
953 */
954int rtems_filesystem_default_utime(
955  rtems_filesystem_location_info_t  *pathloc,       /* IN */
956  time_t                             actime,        /* IN */
957  time_t                             modtime        /* IN */
958);
959
960/**
961 * @brief Provides a defualt routine for filesystem
962 * implementation of a link command.
963 */
964int rtems_filesystem_default_evaluate_link(
965  rtems_filesystem_location_info_t *pathloc,     /* IN/OUT */
966  int                               flags        /* IN     */
967);
968
969/**
970 * @brief Provides a defualt routine for filesystem
971 * implementation of a symlink command.
972 */
973int rtems_filesystem_default_symlink(
974 rtems_filesystem_location_info_t  *loc,         /* IN */
975 const char                        *link_name,   /* IN */
976 const char                        *node_name
977);
978
979/**
980 * @brief Provides a defualt routine for filesystem
981 * implementation of a readlink command.
982 */
983int rtems_filesystem_default_readlink(
984 rtems_filesystem_location_info_t  *loc,     /* IN  */
985 char                              *buf,     /* OUT */
986 size_t                            bufsize
987);
988
989/**
990 * @brief Provides a defualt routine for filesystem
991 * implementation of a rename command.
992 */
993int rtems_filesystem_default_rename(
994 rtems_filesystem_location_info_t  *old_parent_loc,  /* IN */
995 rtems_filesystem_location_info_t  *old_loc,         /* IN */
996 rtems_filesystem_location_info_t  *new_parent_loc,  /* IN */
997 const char                        *name             /* IN */
998);
999
1000/**
1001 * @brief Provides a defualt routine for filesystem
1002 * implementation of a statvfs command.
1003 */
1004int rtems_filesystem_default_statvfs(
1005 rtems_filesystem_location_info_t  *loc,     /* IN  */
1006 struct statvfs                    *buf      /* OUT */
1007);
1008
1009/**
1010 * @brief File system table entry.
1011 */
1012typedef struct rtems_filesystem_table_t {
1013  const char                    *type;
1014  rtems_filesystem_fsmount_me_t  mount_h;
1015} rtems_filesystem_table_t;
1016
1017/**
1018 * @brief Static table of file systems.
1019 *
1020 * Externally defined by confdefs.h or the user.
1021 */
1022extern const rtems_filesystem_table_t rtems_filesystem_table [];
1023
1024/**
1025 * @brief Per file system table entry routine type.
1026 *
1027 * @see rtems_filesystem_iterate().
1028 *
1029 * @retval true Continue the iteration.
1030 * @retval false Stop the iteration.
1031 */
1032typedef bool (*rtems_per_filesystem_routine)(
1033  const rtems_filesystem_table_t *entry,
1034  void *arg
1035);
1036
1037/**
1038 * @brief Iterates over the file system table.
1039 *
1040 * For each file system table entry the @a routine will be called with the
1041 * table entry and the @a routine_arg parameter.
1042 */
1043void
1044rtems_filesystem_iterate(
1045  rtems_per_filesystem_routine routine,
1046  void *routine_arg
1047);
1048
1049/**
1050 * @brief Gets the mount handler for the file system @a type.
1051 *
1052 * @return The file system mount handler associated with the @a type, or
1053 * @c NULL if no such association exists.
1054 */
1055rtems_filesystem_fsmount_me_t
1056rtems_filesystem_get_mount_handler(
1057  const char *type
1058);
1059
1060/*
1061 * Get the first entry in the mount table.
1062 */
1063rtems_filesystem_mount_table_entry_t*
1064rtems_filesystem_mounts_first( void );
1065
1066/*
1067 * Get the next entry in the mount table.
1068 */
1069rtems_filesystem_mount_table_entry_t*
1070rtems_filesystem_mounts_next( rtems_filesystem_mount_table_entry_t *entry );
1071
1072/*
1073 * Register a file system.
1074 */
1075int
1076rtems_filesystem_register(
1077  const char                    *type,
1078  rtems_filesystem_fsmount_me_t  mount_h
1079);
1080
1081/*
1082 * Unregister a file system.
1083 */
1084int
1085rtems_filesystem_unregister(
1086  const char *type
1087);
1088
1089/**
1090 * @brief Contain file system specific information which is required to support
1091 * fpathconf().
1092 */
1093typedef struct {
1094  int    link_max;                 /* count */
1095  int    max_canon;                /* max formatted input line size */
1096  int    max_input;                /* max input line size */
1097  int    name_max;                 /* max name length */
1098  int    path_max;                 /* max path */
1099  int    pipe_buf;                 /* pipe buffer size */
1100  int    posix_async_io;           /* async IO supported on fs, 0=no, 1=yes */
1101  int    posix_chown_restrictions; /* can chown: 0=no, 1=yes */
1102  int    posix_no_trunc;           /* error on names > max name, 0=no, 1=yes */
1103  int    posix_prio_io;            /* priority IO, 0=no, 1=yes */
1104  int    posix_sync_io;            /* file can be sync'ed, 0=no, 1=yes */
1105  int    posix_vdisable;           /* special char processing, 0=no, 1=yes */
1106} rtems_filesystem_limits_and_options_t;
1107
1108/**
1109 * @brief Default pathconf settings.
1110 *
1111 * Override in a filesystem.
1112 */
1113extern const rtems_filesystem_limits_and_options_t rtems_filesystem_default_pathconf;
1114
1115/**
1116 * @brief Mount table entry.
1117 */
1118struct rtems_filesystem_mount_table_entry_tt {
1119  rtems_chain_node                       Node;
1120  rtems_filesystem_location_info_t       mt_point_node;
1121  rtems_filesystem_location_info_t       mt_fs_root;
1122  int                                    options;
1123  void                                  *fs_info;
1124
1125  rtems_filesystem_limits_and_options_t  pathconf_limits_and_options;
1126
1127  /*
1128   * The target or mount point of the file system.
1129   */
1130  const char                            *target;
1131
1132  /*
1133   * The type of filesystem or the name of the filesystem.
1134   */
1135  const char                            *type;
1136
1137  /*
1138   *  When someone adds a mounted filesystem on a real device,
1139   *  this will need to be used.
1140   *
1141   *  The lower layers can manage how this is managed. Leave as a
1142   *  string.
1143   */
1144  char                                  *dev;
1145};
1146
1147/**
1148 * @brief The pathconf setting for a file system.
1149 */
1150#define rtems_filesystem_pathconf(_mte) ((_mte)->pathconf_limits_and_options)
1151
1152/**
1153 * @brief The type of file system. Its name.
1154 */
1155#define rtems_filesystem_type(_mte) ((_mte)->type)
1156
1157/**
1158 * @brief The mount point of a file system.
1159 */
1160#define rtems_filesystem_mount_point(_mte) ((_mte)->target)
1161
1162/**
1163 * @brief The device entry of a file system.
1164 */
1165#define rtems_filesystem_mount_device(_mte) ((_mte)->dev)
1166
1167/**
1168 * @brief File systems options.
1169 */
1170typedef enum {
1171  RTEMS_FILESYSTEM_READ_ONLY,
1172  RTEMS_FILESYSTEM_READ_WRITE,
1173  RTEMS_FILESYSTEM_BAD_OPTIONS
1174} rtems_filesystem_options_t;
1175
1176/**
1177 * @brief An open file data structure.
1178 *
1179 * It will be indexed by 'fd'.
1180 *
1181 * @todo Should really have a separate per/file data structure that this points
1182 * to (eg: size, offset, driver, pathname should be in that)
1183 */
1184struct rtems_libio_tt {
1185  rtems_driver_name_t                    *driver;
1186  rtems_off64_t                           size;      /* size of file */
1187  rtems_off64_t                           offset;    /* current offset into file */
1188  uint32_t                                flags;
1189  rtems_filesystem_location_info_t        pathinfo;
1190  rtems_id                                sem;
1191  uint32_t                                data0;     /* private to "driver" */
1192  void                                   *data1;     /* ... */
1193  void                                   *file_info; /* used by file handlers */
1194  const rtems_filesystem_file_handlers_r *handlers;  /* type specific handlers */
1195};
1196
1197/**
1198 * @brief Paramameter block for read/write.
1199 *
1200 * It must include 'offset' instead of using iop's offset since we can have
1201 * multiple outstanding i/o's on a device.
1202 */
1203typedef struct {
1204  rtems_libio_t          *iop;
1205  rtems_off64_t           offset;
1206  char                   *buffer;
1207  uint32_t                count;
1208  uint32_t                flags;
1209  uint32_t                bytes_moved;
1210} rtems_libio_rw_args_t;
1211
1212/**
1213 * @brief Parameter block for open/close.
1214 */
1215typedef struct {
1216  rtems_libio_t          *iop;
1217  uint32_t                flags;
1218  uint32_t                mode;
1219} rtems_libio_open_close_args_t;
1220
1221/**
1222 * @brief Parameter block for ioctl.
1223 */
1224typedef struct {
1225  rtems_libio_t          *iop;
1226  uint32_t                command;
1227  void                   *buffer;
1228  uint32_t                ioctl_return;
1229} rtems_libio_ioctl_args_t;
1230
1231/**
1232 * @name Flag Values
1233 *
1234 * @{
1235 */
1236
1237#define LIBIO_FLAGS_NO_DELAY      0x0001  /* return immediately if no data */
1238#define LIBIO_FLAGS_READ          0x0002  /* reading */
1239#define LIBIO_FLAGS_WRITE         0x0004  /* writing */
1240#define LIBIO_FLAGS_OPEN          0x0100  /* device is open */
1241#define LIBIO_FLAGS_APPEND        0x0200  /* all writes append */
1242#define LIBIO_FLAGS_CREATE        0x0400  /* create file */
1243#define LIBIO_FLAGS_CLOSE_ON_EXEC 0x0800  /* close on process exec() */
1244#define LIBIO_FLAGS_READ_WRITE    (LIBIO_FLAGS_READ | LIBIO_FLAGS_WRITE)
1245
1246/** @} */
1247
1248void rtems_libio_init(void);
1249
1250/**
1251 * @name External I/O Handlers
1252 *
1253 * @{
1254 */
1255
1256typedef int (*rtems_libio_open_t)(
1257  const char  *pathname,
1258  uint32_t    flag,
1259  uint32_t    mode
1260);
1261
1262typedef int (*rtems_libio_close_t)(
1263  int  fd
1264);
1265
1266typedef int (*rtems_libio_read_t)(
1267  int         fd,
1268  void       *buffer,
1269  uint32_t    count
1270);
1271
1272typedef int (*rtems_libio_write_t)(
1273  int         fd,
1274  const void *buffer,
1275  uint32_t    count
1276);
1277
1278typedef int (*rtems_libio_ioctl_t)(
1279  int         fd,
1280  uint32_t    command,
1281  void       *buffer
1282);
1283
1284typedef rtems_off64_t (*rtems_libio_lseek_t)(
1285  int           fd,
1286  rtems_off64_t offset,
1287  int           whence
1288);
1289
1290/** @} */
1291
1292/**
1293 * @name Permission Macros
1294 *
1295 * @{
1296 */
1297
1298/*
1299 *  The following macros are used to build up the permissions sets
1300 *  used to check permissions.  These are similar in style to the
1301 *  mode_t bits and should stay compatible with them.
1302 */
1303#define RTEMS_LIBIO_PERMS_READ   S_IROTH
1304#define RTEMS_LIBIO_PERMS_WRITE  S_IWOTH
1305#define RTEMS_LIBIO_PERMS_RDWR   (S_IROTH|S_IWOTH)
1306#define RTEMS_LIBIO_PERMS_EXEC   S_IXOTH
1307#define RTEMS_LIBIO_PERMS_SEARCH RTEMS_LIBIO_PERMS_EXEC
1308#define RTEMS_LIBIO_PERMS_RWX    S_IRWXO
1309
1310/** @} */
1311
1312union __rtems_dev_t {
1313  dev_t device;
1314  struct {
1315     rtems_device_major_number major;
1316     rtems_device_minor_number minor;
1317  } __overlay;
1318};
1319
1320static inline dev_t rtems_filesystem_make_dev_t(
1321  rtems_device_major_number _major,
1322  rtems_device_minor_number _minor
1323)
1324{
1325  union __rtems_dev_t temp;
1326
1327  temp.__overlay.major = _major;
1328  temp.__overlay.minor = _minor;
1329  return temp.device;
1330}
1331
1332static inline rtems_device_major_number rtems_filesystem_dev_major_t(
1333  dev_t device
1334)
1335{
1336  union __rtems_dev_t temp;
1337
1338  temp.device = device;
1339  return temp.__overlay.major;
1340}
1341
1342
1343static inline rtems_device_minor_number rtems_filesystem_dev_minor_t(
1344  dev_t device
1345)
1346{
1347  union __rtems_dev_t temp;
1348
1349  temp.device = device;
1350  return temp.__overlay.minor;
1351}
1352
1353#define rtems_filesystem_split_dev_t( _dev, _major, _minor ) \
1354  do { \
1355    (_major) = rtems_filesystem_dev_major_t ( _dev ); \
1356    (_minor) = rtems_filesystem_dev_minor_t( _dev ); \
1357  } while(0)
1358
1359/*
1360 * Verifies that the permission flag is valid.
1361 */
1362#define rtems_libio_is_valid_perms( _perm )     \
1363 (~ ((~RTEMS_LIBIO_PERMS_RWX) & _perm ))
1364
1365/**
1366 * @name File System Types
1367 *
1368 * @{
1369 */
1370
1371#define RTEMS_FILESYSTEM_TYPE_IMFS "imfs"
1372#define RTEMS_FILESYSTEM_TYPE_MINIIMFS "mimfs"
1373#define RTEMS_FILESYSTEM_TYPE_DEVFS "devfs"
1374#define RTEMS_FILESYSTEM_TYPE_FTPFS "ftpfs"
1375#define RTEMS_FILESYSTEM_TYPE_TFTPFS "tftpfs"
1376#define RTEMS_FILESYSTEM_TYPE_NFS "nfs"
1377#define RTEMS_FILESYSTEM_TYPE_DOSFS "dosfs"
1378#define RTEMS_FILESYSTEM_TYPE_RFS "rfs"
1379
1380/** @} */
1381
1382/*
1383 *  Prototypes for filesystem
1384 */
1385
1386void rtems_filesystem_initialize( void );
1387
1388int unmount(
1389  const char *mount_path
1390);
1391
1392int mount(
1393  const char                 *source,
1394  const char                 *target,
1395  const char                 *filesystemtype,
1396  rtems_filesystem_options_t options,
1397  const void                 *data
1398);
1399
1400/**
1401 * @brief Mounts a file system and makes the @a target path.
1402 *
1403 * The @a target path will be created with rtems_mkdir() and must not be
1404 * @c NULL.
1405 *
1406 * @see mount().
1407 *
1408 * @retval 0 Successful operation.
1409 * @retval -1 An error occured.  The @c errno indicates the error.
1410 */
1411int mount_and_make_target_path(
1412  const char                 *source,
1413  const char                 *target,
1414  const char                 *filesystemtype,
1415  rtems_filesystem_options_t options,
1416  const void                 *data
1417);
1418
1419/*
1420 *  Boot Time Mount Table Structure
1421 */
1422
1423typedef struct {
1424  const char                              *type;
1425  rtems_filesystem_options_t               fsoptions;
1426  const char                              *device;
1427  const char                              *mount_point;
1428} rtems_filesystem_mount_table_t;
1429
1430extern const rtems_filesystem_mount_table_t *rtems_filesystem_mount_table;
1431extern const int                             rtems_filesystem_mount_table_size;
1432
1433typedef void (*rtems_libio_init_functions_t)(void);
1434extern  rtems_libio_init_functions_t rtems_libio_init_helper;
1435
1436void    open_dev_console(void);
1437
1438typedef void (*rtems_libio_supp_functions_t)(void);
1439extern  rtems_libio_supp_functions_t rtems_libio_supp_helper;
1440
1441typedef void (*rtems_fs_init_functions_t)(void);
1442extern  rtems_fs_init_functions_t    rtems_fs_init_helper;
1443
1444/**
1445 * @brief Creates a directory and all its parent directories according to
1446 * @a path.
1447 *
1448 * The @a mode value selects the access permissions of the directory.
1449 *
1450 * @retval 0 Successful operation.
1451 * @retval -1 An error occured.  The @c errno indicates the error.
1452 */
1453extern int rtems_mkdir(const char *path, mode_t mode);
1454
1455/** @} */
1456
1457/**
1458 * @defgroup Termios Termios
1459 *
1460 * @ingroup LibIO
1461 *
1462 * @brief Termios
1463 *
1464 * @{
1465 */
1466
1467typedef struct rtems_termios_callbacks {
1468  int    (*firstOpen)(int major, int minor, void *arg);
1469  int    (*lastClose)(int major, int minor, void *arg);
1470  int    (*pollRead)(int minor);
1471  ssize_t (*write)(int minor, const char *buf, size_t len);
1472  int    (*setAttributes)(int minor, const struct termios *t);
1473  int    (*stopRemoteTx)(int minor);
1474  int    (*startRemoteTx)(int minor);
1475  int    outputUsesInterrupts;
1476} rtems_termios_callbacks;
1477
1478void rtems_termios_initialize (void);
1479
1480/*
1481 * CCJ: Change before opening a tty. Newer code from Eric is coming
1482 * so extra work to handle an open tty is not worth it. If the tty
1483 * is open, close then open it again.
1484 */
1485rtems_status_code rtems_termios_bufsize (
1486  int cbufsize,     /* cooked buffer size */
1487  int raw_input,    /* raw input buffer size */
1488  int raw_output    /* raw output buffer size */
1489);
1490
1491rtems_status_code rtems_termios_open (
1492  rtems_device_major_number      major,
1493  rtems_device_minor_number      minor,
1494  void                          *arg,
1495  const rtems_termios_callbacks *callbacks
1496);
1497
1498rtems_status_code rtems_termios_close(
1499  void *arg
1500);
1501
1502rtems_status_code rtems_termios_read(
1503  void *arg
1504);
1505
1506rtems_status_code rtems_termios_write(
1507  void *arg
1508);
1509
1510rtems_status_code rtems_termios_ioctl(
1511  void *arg
1512);
1513
1514int rtems_termios_enqueue_raw_characters(
1515  void *ttyp,
1516  char *buf,
1517  int   len
1518);
1519
1520int rtems_termios_dequeue_characters(
1521  void *ttyp,
1522  int   len
1523);
1524
1525/** @} */
1526
1527#ifdef __cplusplus
1528}
1529#endif
1530
1531#endif /* _RTEMS_LIBIO_H */
Note: See TracBrowser for help on using the repository browser.