source: rtems/cpukit/libcsupport/include/rtems/libio.h @ 7dce4c2d

4.104.114.84.95
Last change on this file since 7dce4c2d was 7945944, checked in by Ralf Corsepius <ralf.corsepius@…>, on 01/28/05 at 08:04:27

New header guards.

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