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

4.104.114.84.95
Last change on this file since e8213f3 was 80c2966, checked in by Ralf Corsepius <ralf.corsepius@…>, on 06/18/06 at 06:28:22

2006-06-18 Ralf Corsépius <ralf.corsepius@…>

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