source: rtems/cpukit/libcsupport/include/rtems/libio.h @ 50f32b11

4.104.114.84.95
Last change on this file since 50f32b11 was 50f32b11, checked in by Ralf Corsepius <ralf.corsepius@…>, on 04/18/04 at 06:05:35

Remove stray white spaces.

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