source: rtems/cpukit/libcsupport/include/rtems/libio.h @ 558a5f48

4.104.115
Last change on this file since 558a5f48 was dfce6724, checked in by Chris Johns <chrisj@…>, on 06/02/10 at 00:43:13

2010-06-01 Chris Johns <chrisj@…>

  • libcsupport/include/rtems/libio.h: Make the struct name the same as the typedef.
  • sapi/include/confdefs.h: Fixes for use in C++.
  • Property mode set to 100644
File size: 19.1 KB
Line 
1/**
2 * @file rtems/libio.h
3 */
4
5/*
6 *  System call and file system interface definition
7 *
8 *  General purpose communication channel for RTEMS to allow UNIX/POSIX
9 *  system call behavior under RTEMS.  Initially this supported only
10 *  IO to devices but has since been enhanced to support networking
11 *  and support for mounted file systems.
12 *
13 *  COPYRIGHT (c) 1989-2008.
14 *  On-Line Applications Research Corporation (OAR).
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 *  $Id$
21 */
22
23#ifndef _RTEMS_RTEMS_LIBIO_H
24#define _RTEMS_RTEMS_LIBIO_H
25
26#include <rtems.h>
27#include <rtems/chain.h>
28#include <sys/types.h>
29#include <sys/stat.h>
30#include <sys/ioctl.h>
31#include <sys/statvfs.h>
32
33/*
34 *  Define data types which must be constructed using forward references.
35 */
36
37#include <rtems/fs.h>
38
39#ifdef __cplusplus
40extern "C" {
41#endif
42
43/*
44 * A 64bit file offset for internal use by RTEMS. Based on the newlib type.
45 */
46typedef _off64_t rtems_off64_t;
47
48/*
49 * Valid RTEMS file types.
50 */
51#define RTEMS_FILESYSTEM_DIRECTORY   1
52#define RTEMS_FILESYSTEM_DEVICE      2
53#define RTEMS_FILESYSTEM_HARD_LINK   3
54#define RTEMS_FILESYSTEM_SYM_LINK    4
55#define RTEMS_FILESYSTEM_MEMORY_FILE 5
56typedef int rtems_filesystem_node_types_t;
57
58/*
59 *  File Handler Operations Table
60 */
61typedef int (*rtems_filesystem_open_t)(
62  rtems_libio_t *iop,
63  const char    *pathname,
64  uint32_t       flag,
65  uint32_t       mode
66);
67
68typedef int (*rtems_filesystem_close_t)(
69  rtems_libio_t *iop
70);
71
72typedef ssize_t (*rtems_filesystem_read_t)(
73  rtems_libio_t *iop,
74  void          *buffer,
75  size_t         count
76);
77
78typedef ssize_t (*rtems_filesystem_write_t)(
79  rtems_libio_t *iop,
80  const void    *buffer,
81  size_t         count
82);
83
84typedef int (*rtems_filesystem_ioctl_t)(
85  rtems_libio_t *iop,
86  uint32_t       command,
87  void          *buffer
88);
89
90typedef rtems_off64_t (*rtems_filesystem_lseek_t)(
91  rtems_libio_t *iop,
92  rtems_off64_t  length,
93  int            whence
94);
95
96typedef int (*rtems_filesystem_fstat_t)(
97  rtems_filesystem_location_info_t *loc,
98  struct stat                      *buf
99);
100
101typedef int (*rtems_filesystem_fchmod_t)(
102  rtems_filesystem_location_info_t *loc,
103  mode_t                            mode
104);
105
106typedef int (*rtems_filesystem_ftruncate_t)(
107  rtems_libio_t *iop,
108  rtems_off64_t  length
109);
110
111typedef int (*rtems_filesystem_fpathconf_t)(
112  rtems_libio_t *iop,
113  int name
114);
115
116typedef int (*rtems_filesystem_fsync_t)(
117  rtems_libio_t *iop
118);
119
120typedef int (*rtems_filesystem_fdatasync_t)(
121  rtems_libio_t *iop
122);
123
124typedef int (*rtems_filesystem_fcntl_t)(
125  int            cmd,
126  rtems_libio_t *iop
127);
128
129typedef int (*rtems_filesystem_rmnod_t)(
130 rtems_filesystem_location_info_t      *parent_loc,   /* IN */
131 rtems_filesystem_location_info_t      *pathloc       /* IN */
132);
133
134struct _rtems_filesystem_file_handlers_r {
135    rtems_filesystem_open_t         open_h;
136    rtems_filesystem_close_t        close_h;
137    rtems_filesystem_read_t         read_h;
138    rtems_filesystem_write_t        write_h;
139    rtems_filesystem_ioctl_t        ioctl_h;
140    rtems_filesystem_lseek_t        lseek_h;
141    rtems_filesystem_fstat_t        fstat_h;
142    rtems_filesystem_fchmod_t       fchmod_h;
143    rtems_filesystem_ftruncate_t    ftruncate_h;
144    rtems_filesystem_fpathconf_t    fpathconf_h;
145    rtems_filesystem_fsync_t        fsync_h;
146    rtems_filesystem_fdatasync_t    fdatasync_h;
147    rtems_filesystem_fcntl_t        fcntl_h;
148    rtems_filesystem_rmnod_t        rmnod_h;
149};
150
151/*
152 *  File System Operations Table
153 */
154
155/*
156 *  XXX
157 *  This routine does not allocate any space and rtems_filesystem_freenode_t
158 *  is not called by the generic after calling this routine.
159 *  ie. node_access does not have to contain valid data when the
160 *      routine returns.
161 */
162typedef int (*rtems_filesystem_mknod_t)(
163   const char                        *path,       /* IN */
164   mode_t                             mode,       /* IN */
165   dev_t                              dev,        /* IN */
166   rtems_filesystem_location_info_t  *pathloc     /* IN/OUT */
167);
168
169/*
170 *  rtems_filesystem_freenode_t must be called by the generic after
171 *  calling this routine
172 */
173
174typedef int (*rtems_filesystem_evalpath_t)(
175  const char                        *pathname,      /* IN     */
176  size_t                             pathnamelen,   /* IN     */
177  int                                flags,         /* IN     */
178  rtems_filesystem_location_info_t  *pathloc        /* IN/OUT */
179);
180
181typedef int (*rtems_filesystem_evalmake_t)(
182   const char                       *path,       /* IN */
183   rtems_filesystem_location_info_t *pathloc,    /* IN/OUT */
184   const char                      **name        /* OUT    */
185);
186
187typedef int (*rtems_filesystem_link_t)(
188 rtems_filesystem_location_info_t  *to_loc,      /* IN */
189 rtems_filesystem_location_info_t  *parent_loc,  /* IN */
190 const char                        *name         /* IN */
191);
192
193typedef int (*rtems_filesystem_unlink_t)(
194 rtems_filesystem_location_info_t  *parent_pathloc, /* IN */
195 rtems_filesystem_location_info_t  *pathloc         /* IN */
196);
197
198typedef int (*rtems_filesystem_chown_t)(
199 rtems_filesystem_location_info_t  *pathloc,       /* IN */
200 uid_t                              owner,         /* IN */
201 gid_t                              group          /* IN */
202);
203
204typedef int (*rtems_filesystem_freenode_t)(
205 rtems_filesystem_location_info_t      *pathloc       /* IN */
206);
207
208typedef int (* rtems_filesystem_mount_t ) (
209   rtems_filesystem_mount_table_entry_t *mt_entry     /* IN */
210);
211
212typedef int (* rtems_filesystem_fsmount_me_t )(
213  rtems_filesystem_mount_table_entry_t *mt_entry,     /* IN */
214  const void                           *data          /* IN */
215);
216
217typedef int (* rtems_filesystem_unmount_t ) (
218  rtems_filesystem_mount_table_entry_t *mt_entry     /* IN */
219);
220
221typedef int (* rtems_filesystem_fsunmount_me_t ) (
222   rtems_filesystem_mount_table_entry_t *mt_entry    /* IN */
223);
224
225typedef rtems_filesystem_node_types_t (* rtems_filesystem_node_type_t) (
226  rtems_filesystem_location_info_t    *pathloc      /* IN */
227);
228
229typedef int (* rtems_filesystem_utime_t)(
230  rtems_filesystem_location_info_t  *pathloc,       /* IN */
231  time_t                             actime,        /* IN */
232  time_t                             modtime        /* IN */
233);
234
235typedef int (*rtems_filesystem_evaluate_link_t)(
236  rtems_filesystem_location_info_t *pathloc,     /* IN/OUT */
237  int                               flags        /* IN     */
238);
239
240typedef int (*rtems_filesystem_symlink_t)(
241 rtems_filesystem_location_info_t  *loc,         /* IN */
242 const char                        *link_name,   /* IN */
243 const char                        *node_name
244);
245
246typedef int (*rtems_filesystem_readlink_t)(
247 rtems_filesystem_location_info_t  *loc,     /* IN  */
248 char                              *buf,     /* OUT */
249 size_t                            bufsize
250);
251
252typedef int (*rtems_filesystem_rename_t)(
253 rtems_filesystem_location_info_t  *old_parent_loc,  /* IN */
254 rtems_filesystem_location_info_t  *old_loc,         /* IN */
255 rtems_filesystem_location_info_t  *new_parent_loc,  /* IN */
256 const char                        *name             /* IN */
257);
258
259typedef int (*rtems_filesystem_statvfs_t)(
260 rtems_filesystem_location_info_t  *loc,     /* IN  */
261 struct statvfs                    *buf      /* OUT */
262);
263
264/*
265 * operations table that must be defined for every file system.
266 */
267
268/*
269 * File system types
270 */
271struct _rtems_filesystem_operations_table {
272    rtems_filesystem_evalpath_t      evalpath_h;
273    rtems_filesystem_evalmake_t      evalformake_h;
274    rtems_filesystem_link_t          link_h;
275    rtems_filesystem_unlink_t        unlink_h;
276    rtems_filesystem_node_type_t     node_type_h;
277    rtems_filesystem_mknod_t         mknod_h;
278    rtems_filesystem_chown_t         chown_h;
279    rtems_filesystem_freenode_t      freenod_h;
280    rtems_filesystem_mount_t         mount_h;
281    rtems_filesystem_fsmount_me_t    fsmount_me_h;
282    rtems_filesystem_unmount_t       unmount_h;
283    rtems_filesystem_fsunmount_me_t  fsunmount_me_h;
284    rtems_filesystem_utime_t         utime_h;
285    rtems_filesystem_evaluate_link_t eval_link_h;
286    rtems_filesystem_symlink_t       symlink_h;
287    rtems_filesystem_readlink_t      readlink_h;
288    rtems_filesystem_rename_t        rename_h;
289    rtems_filesystem_statvfs_t       statvfs_h;
290};
291
292/*
293 * File system table used by mount to manage file systems.
294 */
295typedef struct rtems_filesystem_table_t {
296  const char                    *type;
297  rtems_filesystem_fsmount_me_t  mount_h;
298} rtems_filesystem_table_t;
299
300/*
301 * File system table runtime loaded nodes.
302 */
303typedef struct rtems_filesystem_table_node_t {
304  rtems_chain_node         node;
305  rtems_filesystem_table_t entry;
306} rtems_filesystem_table_node_t;
307
308/*
309 * Get the first entry in the filesystem table.
310 */
311const rtems_filesystem_table_t* rtems_filesystem_table_first( void );
312
313/*
314 * Get the next entry in the file system table.
315 */
316const rtems_filesystem_table_t*
317rtems_filesystem_table_next( const rtems_filesystem_table_t *entry );
318
319/*
320 * Get the first entry in the mount table.
321 */
322rtems_filesystem_mount_table_entry_t*
323rtems_filesystem_mounts_first( void );
324
325/*
326 * Get the next entry in the mount table.
327 */
328rtems_filesystem_mount_table_entry_t*
329rtems_filesystem_mounts_next( rtems_filesystem_mount_table_entry_t *entry );
330
331/*
332 * Register a file system.
333 */
334int
335rtems_filesystem_register(
336  const char                    *type,
337  rtems_filesystem_fsmount_me_t  mount_h
338);
339
340/*
341 * Unregister a file system.
342 */
343int
344rtems_filesystem_unregister(
345  const char *type
346);
347
348/*
349 *  Structure used to contain file system specific information which
350 *  is required to support fpathconf().
351 */
352typedef struct {
353  int    link_max;                 /* count */
354  int    max_canon;                /* max formatted input line size */
355  int    max_input;                /* max input line size */
356  int    name_max;                 /* max name length */
357  int    path_max;                 /* max path */
358  int    pipe_buf;                 /* pipe buffer size */
359  int    posix_async_io;           /* async IO supported on fs, 0=no, 1=yes */
360  int    posix_chown_restrictions; /* can chown: 0=no, 1=yes */
361  int    posix_no_trunc;           /* error on names > max name, 0=no, 1=yes */
362  int    posix_prio_io;            /* priority IO, 0=no, 1=yes */
363  int    posix_sync_io;            /* file can be sync'ed, 0=no, 1=yes */
364  int    posix_vdisable;           /* special char processing, 0=no, 1=yes */
365} rtems_filesystem_limits_and_options_t;
366
367/*
368 * Default pathconf settings. Override in a filesystem.
369 */
370extern const rtems_filesystem_limits_and_options_t rtems_filesystem_default_pathconf;
371
372/*
373 * Structure for a mount table entry.
374 */
375
376struct rtems_filesystem_mount_table_entry_tt {
377  rtems_chain_node                       Node;
378  rtems_filesystem_location_info_t       mt_point_node;
379  rtems_filesystem_location_info_t       mt_fs_root;
380  int                                    options;
381  void                                  *fs_info;
382
383  rtems_filesystem_limits_and_options_t  pathconf_limits_and_options;
384
385  /*
386   * The target or mount point of the file system.
387   */
388  const char                            *target;
389
390  /*
391   * The type of filesystem or the name of the filesystem.
392   */
393  const char                            *type;
394
395  /*
396   *  When someone adds a mounted filesystem on a real device,
397   *  this will need to be used.
398   *
399   *  The lower layers can manage how this is managed. Leave as a
400   *  string.
401   */
402  char                                  *dev;
403};
404
405/**
406 * The pathconf setting for a file system.
407 */
408#define rtems_filesystem_pathconf(_mte) ((_mte)->pathconf_limits_and_options)
409
410/**
411 * The type of file system. Its name.
412 */
413#define rtems_filesystem_type(_mte) ((_mte)->type)
414
415/**
416 * The mount point of a file system.
417 */
418#define rtems_filesystem_mount_point(_mte) ((_mte)->target)
419
420/**
421 * The device entry of a file system.
422 */
423#define rtems_filesystem_mount_device(_mte) ((_mte)->dev)
424
425/*
426 *  Valid RTEMS file systems options
427 */
428typedef enum {
429  RTEMS_FILESYSTEM_READ_ONLY,
430  RTEMS_FILESYSTEM_READ_WRITE,
431  RTEMS_FILESYSTEM_BAD_OPTIONS
432} rtems_filesystem_options_t;
433
434
435/*
436 *  An open file data structure, indexed by 'fd'
437 *  TODO:
438 *     should really have a separate per/file data structure that this
439 *     points to (eg: size, offset, driver, pathname should be in that)
440 */
441struct rtems_libio_tt {
442  rtems_driver_name_t                    *driver;
443  rtems_off64_t                           size;      /* size of file */
444  rtems_off64_t                           offset;    /* current offset into file */
445  uint32_t                                flags;
446  rtems_filesystem_location_info_t        pathinfo;
447  rtems_id                                sem;
448  uint32_t                                data0;     /* private to "driver" */
449  void                                   *data1;     /* ... */
450  void                                   *file_info; /* used by file handlers */
451  const rtems_filesystem_file_handlers_r *handlers;  /* type specific handlers */
452};
453
454/*
455 *  param block for read/write
456 *  Note: it must include 'offset' instead of using iop's offset since
457 *        we can have multiple outstanding i/o's on a device.
458 */
459typedef struct {
460  rtems_libio_t          *iop;
461  rtems_off64_t           offset;
462  char                   *buffer;
463  uint32_t                count;
464  uint32_t                flags;
465  uint32_t                bytes_moved;
466} rtems_libio_rw_args_t;
467
468/*
469 *  param block for open/close
470 */
471typedef struct {
472  rtems_libio_t          *iop;
473  uint32_t                flags;
474  uint32_t                mode;
475} rtems_libio_open_close_args_t;
476
477/*
478 *  param block for ioctl
479 */
480typedef struct {
481  rtems_libio_t          *iop;
482  uint32_t                command;
483  void                   *buffer;
484  uint32_t                ioctl_return;
485} rtems_libio_ioctl_args_t;
486
487/*
488 *  Values for 'flag'
489 */
490#define LIBIO_FLAGS_NO_DELAY      0x0001  /* return immediately if no data */
491#define LIBIO_FLAGS_READ          0x0002  /* reading */
492#define LIBIO_FLAGS_WRITE         0x0004  /* writing */
493#define LIBIO_FLAGS_OPEN          0x0100  /* device is open */
494#define LIBIO_FLAGS_APPEND        0x0200  /* all writes append */
495#define LIBIO_FLAGS_CREATE        0x0400  /* create file */
496#define LIBIO_FLAGS_CLOSE_ON_EXEC 0x0800  /* close on process exec() */
497#define LIBIO_FLAGS_READ_WRITE    (LIBIO_FLAGS_READ | LIBIO_FLAGS_WRITE)
498
499void rtems_libio_init(void);
500
501/*
502 *  External I/O handlers
503 */
504
505typedef int (*rtems_libio_open_t)(
506  const char  *pathname,
507  uint32_t    flag,
508  uint32_t    mode
509);
510
511typedef int (*rtems_libio_close_t)(
512  int  fd
513);
514
515typedef int (*rtems_libio_read_t)(
516  int         fd,
517  void       *buffer,
518  uint32_t    count
519);
520
521typedef int (*rtems_libio_write_t)(
522  int         fd,
523  const void *buffer,
524  uint32_t    count
525);
526
527typedef int (*rtems_libio_ioctl_t)(
528  int         fd,
529  uint32_t    command,
530  void       *buffer
531);
532
533typedef rtems_off64_t (*rtems_libio_lseek_t)(
534  int           fd,
535  rtems_off64_t offset,
536  int           whence
537);
538
539/*
540 *  The following macros are used to build up the permissions sets
541 *  used to check permissions.  These are similar in style to the
542 *  mode_t bits and should stay compatible with them.
543 */
544#define RTEMS_LIBIO_PERMS_READ   S_IROTH
545#define RTEMS_LIBIO_PERMS_WRITE  S_IWOTH
546#define RTEMS_LIBIO_PERMS_RDWR   (S_IROTH|S_IWOTH)
547#define RTEMS_LIBIO_PERMS_EXEC   S_IXOTH
548#define RTEMS_LIBIO_PERMS_SEARCH RTEMS_LIBIO_PERMS_EXEC
549#define RTEMS_LIBIO_PERMS_RWX    S_IRWXO
550
551/*
552 *  Macros
553 */
554
555#include <unistd.h>
556
557union __rtems_dev_t {
558  dev_t device;
559  struct {
560     rtems_device_major_number major;
561     rtems_device_minor_number minor;
562  } __overlay;
563};
564
565static inline dev_t rtems_filesystem_make_dev_t(
566  rtems_device_major_number _major,
567  rtems_device_minor_number _minor
568)
569{
570  union __rtems_dev_t temp;
571
572  temp.__overlay.major = _major;
573  temp.__overlay.minor = _minor;
574  return temp.device;
575}
576
577static inline rtems_device_major_number rtems_filesystem_dev_major_t(
578  dev_t device
579)
580{
581  union __rtems_dev_t temp;
582
583  temp.device = device;
584  return temp.__overlay.major;
585}
586
587
588static inline rtems_device_minor_number rtems_filesystem_dev_minor_t(
589  dev_t device
590)
591{
592  union __rtems_dev_t temp;
593
594  temp.device = device;
595  return temp.__overlay.minor;
596}
597
598#define rtems_filesystem_split_dev_t( _dev, _major, _minor ) \
599  do { \
600    (_major) = rtems_filesystem_dev_major_t ( _dev ); \
601    (_minor) = rtems_filesystem_dev_minor_t( _dev ); \
602  } while(0)
603
604/*
605 * Verifies that the permission flag is valid.
606 */
607#define rtems_libio_is_valid_perms( _perm )     \
608 (~ ((~RTEMS_LIBIO_PERMS_RWX) & _perm ))
609
610/*
611 *  Prototypes for filesystem
612 */
613
614void rtems_filesystem_initialize( void );
615
616/*
617 * Callbacks from TERMIOS routines to device-dependent code
618 */
619#include <termios.h>
620
621typedef struct rtems_termios_callbacks {
622  int    (*firstOpen)(int major, int minor, void *arg);
623  int    (*lastClose)(int major, int minor, void *arg);
624  int    (*pollRead)(int minor);
625  ssize_t (*write)(int minor, const char *buf, size_t len);
626  int    (*setAttributes)(int minor, const struct termios *t);
627  int    (*stopRemoteTx)(int minor);
628  int    (*startRemoteTx)(int minor);
629  int    outputUsesInterrupts;
630} rtems_termios_callbacks;
631
632/*
633 *  Device-independent TERMIOS routines
634 */
635void rtems_termios_initialize (void);
636
637/*
638 * CCJ: Change before opening a tty. Newer code from Eric is coming
639 * so extra work to handle an open tty is not worth it. If the tty
640 * is open, close then open it again.
641 */
642rtems_status_code rtems_termios_bufsize (
643  int cbufsize,     /* cooked buffer size */
644  int raw_input,    /* raw input buffer size */
645  int raw_output    /* raw output buffer size */
646);
647
648rtems_status_code rtems_termios_open (
649  rtems_device_major_number      major,
650  rtems_device_minor_number      minor,
651  void                          *arg,
652  const rtems_termios_callbacks *callbacks
653);
654
655rtems_status_code rtems_termios_close(
656  void *arg
657);
658
659rtems_status_code rtems_termios_read(
660  void *arg
661);
662
663rtems_status_code rtems_termios_write(
664  void *arg
665);
666
667rtems_status_code rtems_termios_ioctl(
668  void *arg
669);
670
671int rtems_termios_enqueue_raw_characters(
672  void *ttyp,
673  char *buf,
674  int   len
675);
676
677int rtems_termios_dequeue_characters(
678  void *ttyp,
679  int   len
680);
681
682int unmount(
683  const char *mount_path
684);
685
686int mount(
687  const char                 *source,
688  const char                 *target,
689  const char                 *filesystemtype,
690  rtems_filesystem_options_t options,
691  const void                 *data
692);
693
694/*
695 *  Boot Time Mount Table Structure
696 */
697
698typedef struct {
699  const char                              *type;
700  rtems_filesystem_options_t               fsoptions;
701  const char                              *device;
702  const char                              *mount_point;
703} rtems_filesystem_mount_table_t;
704
705extern const rtems_filesystem_mount_table_t *rtems_filesystem_mount_table;
706extern const int                             rtems_filesystem_mount_table_size;
707
708typedef void (*rtems_libio_init_functions_t)(void);
709extern  rtems_libio_init_functions_t rtems_libio_init_helper;
710
711void    open_dev_console(void);
712
713typedef void (*rtems_libio_supp_functions_t)(void);
714extern  rtems_libio_supp_functions_t rtems_libio_supp_helper;
715
716typedef void (*rtems_fs_init_functions_t)(void);
717extern  rtems_fs_init_functions_t    rtems_fs_init_helper;
718
719#ifdef __cplusplus
720}
721#endif
722
723#endif /* _RTEMS_LIBIO_H */
Note: See TracBrowser for help on using the repository browser.