source: rtems/c/src/exec/libcsupport/include/rtems/libio.h @ cca4400

4.104.114.84.95
Last change on this file since cca4400 was cca4400, checked in by Joel Sherrill <joel.sherrill@…>, on 12/10/98 at 23:31:54

Merged Eric Norum's select patch that was based on 4.0 and resolved
all conflicts.

  • Property mode set to 100644
File size: 15.6 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-1998.
10 *  On-Line Applications Research Corporation (OAR).
11 *  Copyright assigned to U.S. Government, 1994.
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.OARcorp.com/rtems/license.html.
16 *
17 *  $Id$
18 */
19
20#ifndef _RTEMS_LIBIO_H
21#define _RTEMS_LIBIO_H
22
23#include <sys/types.h>
24#include <sys/stat.h>
25
26/*
27 *  Define data types which must be constructed using forward references.
28 */
29
30typedef struct rtems_libio_tt rtems_libio_t;
31
32struct rtems_filesystem_location_info_tt;
33typedef struct rtems_filesystem_location_info_tt
34    rtems_filesystem_location_info_t;
35
36struct rtems_filesystem_mount_table_entry_tt;
37typedef struct rtems_filesystem_mount_table_entry_tt
38    rtems_filesystem_mount_table_entry_t;
39
40/*
41 * Valid RTEMS file types.
42 */
43typedef enum {
44  RTEMS_FILESYSTEM_DIRECTORY,
45  RTEMS_FILESYSTEM_DEVICE,
46  RTEMS_FILESYSTEM_HARD_LINK,
47  RTEMS_FILESYSTEM_SYM_LINK,
48  RTEMS_FILESYSTEM_MEMORY_FILE
49} rtems_filesystem_node_types_t;
50
51/*
52 *  File Handler Operations Table
53 */
54
55typedef int (*rtems_filesystem_open_t)(
56  rtems_libio_t *iop,
57  const char    *pathname,
58  unsigned32     flag,
59  unsigned32     mode
60);
61
62typedef int (*rtems_filesystem_close_t)(
63  rtems_libio_t *iop
64);
65
66typedef int (*rtems_filesystem_read_t)(
67  rtems_libio_t *iop,
68  void          *buffer,
69  unsigned32     count
70);
71
72typedef int (*rtems_filesystem_write_t)(
73  rtems_libio_t *iop,
74  const void    *buffer,
75  unsigned32    count
76);
77
78typedef int (*rtems_filesystem_ioctl_t)(
79  rtems_libio_t *iop,
80  unsigned32     command,
81  void          *buffer
82);
83
84typedef int (*rtems_filesystem_lseek_t)(
85  rtems_libio_t *iop,
86  off_t          length,
87  int            whence
88);
89
90typedef int (*rtems_filesystem_fstat_t)(
91  rtems_filesystem_location_info_t *loc,
92  struct stat                      *buf
93);
94
95typedef int (*rtems_filesystem_fchmod_t)(
96  rtems_filesystem_location_info_t *loc,
97  mode_t                            mode
98);
99
100typedef int (*rtems_filesystem_ftruncate_t)(
101  rtems_libio_t *iop,
102  off_t          length
103);
104
105typedef int (*rtems_filesystem_fpathconf_t)(
106  rtems_libio_t *iop,
107  int name
108);
109
110typedef int (*rtems_filesystem_fsync_t)(
111  rtems_libio_t *iop
112);
113
114typedef int (*rtems_filesystem_fdatasync_t)(
115  rtems_libio_t *iop
116);
117
118typedef struct {
119    rtems_filesystem_open_t         open;
120    rtems_filesystem_close_t        close;
121    rtems_filesystem_read_t         read;
122    rtems_filesystem_write_t        write;
123    rtems_filesystem_ioctl_t        ioctl;
124    rtems_filesystem_lseek_t        lseek;
125    rtems_filesystem_fstat_t        fstat;
126    rtems_filesystem_fchmod_t       fchmod;
127    rtems_filesystem_ftruncate_t    ftruncate;
128    rtems_filesystem_fpathconf_t    fpathconf;
129    rtems_filesystem_fsync_t        fsync;
130    rtems_filesystem_fdatasync_t    fdatasync;
131} rtems_filesystem_file_handlers_r;
132
133/*
134 *  File System Operations Table
135 */
136
137/*
138 *  XXX
139 *  This routine does not allocate any space and rtems_filesystem_freenode_t
140 *  is not called by the generic after calling this routine.
141 *  ie. node_access does not have to contain valid data when the
142 *      routine returns.
143 */
144
145typedef int (*rtems_filesystem_mknod_t)(
146   const char                        *path,       /* IN */
147   mode_t                             mode,       /* IN */
148   dev_t                              dev,        /* IN */
149   rtems_filesystem_location_info_t  *pathloc     /* IN/OUT */
150);
151
152/*
153 *  rtems_filesystem_freenode_t must be called by the generic after
154 *  calling this routine
155 */
156
157typedef int (*rtems_filesystem_evalpath_t)(
158  const char                        *pathname,      /* IN     */
159  int                                flags,         /* IN     */
160  rtems_filesystem_location_info_t  *pathloc        /* IN/OUT */
161);
162
163typedef int (*rtems_filesystem_evalmake_t)(
164   const char                       *path,       /* IN */
165   rtems_filesystem_location_info_t *pathloc,    /* IN/OUT */
166   const char                      **name        /* OUT    */
167);
168
169typedef int (*rtems_filesystem_link_t)(
170 rtems_filesystem_location_info_t  *to_loc,      /* IN */
171 rtems_filesystem_location_info_t  *parent_loc,  /* IN */
172 const char                        *name         /* IN */
173);
174
175typedef int (*rtems_filesystem_unlink_t)(
176 rtems_filesystem_location_info_t  *pathloc       /* IN */
177);
178
179typedef int (*rtems_filesystem_chown_t)(
180 rtems_filesystem_location_info_t  *pathloc,       /* IN */
181 uid_t                              owner,         /* IN */
182 gid_t                              group          /* IN */
183);
184
185typedef int (*rtems_filesystem_freenode_t)(
186 rtems_filesystem_location_info_t      *pathloc       /* IN */
187);
188
189typedef int (*rtems_filesystem_rmnod_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 */
243typedef struct {
244    rtems_filesystem_evalpath_t      evalpath;
245    rtems_filesystem_evalmake_t      evalformake;
246    rtems_filesystem_link_t          link;
247    rtems_filesystem_unlink_t        unlink;
248    rtems_filesystem_node_type_t     node_type;
249    rtems_filesystem_mknod_t         mknod;
250    rtems_filesystem_rmnod_t         rmnod;
251    rtems_filesystem_chown_t         chown;
252    rtems_filesystem_freenode_t      freenod;
253    rtems_filesystem_mount_t         mount;
254    rtems_filesystem_fsmount_me_t    fsmount_me;
255    rtems_filesystem_unmount_t       unmount;
256    rtems_filesystem_fsunmount_me_t  fsunmount_me;
257    rtems_filesystem_utime_t         utime;
258    rtems_filesystem_evaluate_link_t eval_link;
259    rtems_filesystem_symlink_t       symlink;
260    rtems_filesystem_readlink_t      readlink;
261} rtems_filesystem_operations_table;
262
263#define IMFS_FILE_SYSTEM IMFS_ops
264extern rtems_filesystem_operations_table  IMFS_ops;
265
266
267/*
268 * Structure used to determine a location/filesystem in the tree.
269 */
270
271struct rtems_filesystem_location_info_tt
272{
273  void                                   *node_access;
274  rtems_filesystem_file_handlers_r       *handlers;
275  rtems_filesystem_operations_table      *ops;
276  rtems_filesystem_mount_table_entry_t   *mt_entry;
277};
278
279/*
280 *  Structure used to contain file system specific information which
281 *  is required to support fpathconf().
282 */
283
284typedef struct {
285  int    link_max;
286  int    max_canon;
287  int    max_input;
288  int    name_max;
289  int    path_max;
290  int    pipe_buf;
291  int    posix_async_io;
292  int    posix_chown_restrictions;
293  int    posix_no_trunc;
294  int    posix_prio_io;
295  int    posix_sync_io;
296  int    posix_vdisable;
297} rtems_filesystem_limits_and_options_t;
298
299/*
300 * Structure for a mount table entry.
301 */
302
303struct rtems_filesystem_mount_table_entry_tt{
304  Chain_Node                             Node;
305  rtems_filesystem_location_info_t       mt_point_node;
306  rtems_filesystem_location_info_t       mt_fs_root;
307  int                                    options;
308  void                                  *fs_info;
309
310  rtems_filesystem_limits_and_options_t  pathconf_limits_and_options;
311
312  /*
313   *  When someone adds a mounted filesystem on a real device,
314   *  this will need to be used.
315   *
316   *  The best option long term for this is probably an open file descriptor.
317   */
318  char                                  *dev;
319};
320
321/*
322 *  Valid RTEMS file systems options
323 */
324
325typedef enum
326{
327  RTEMS_FILESYSTEM_READ_ONLY,
328  RTEMS_FILESYSTEM_READ_WRITE_ONLY,
329  RTEMS_FILESYSTEM_BAD_OPTIONS
330} rtems_filesystem_options_t;
331
332
333/*
334 *  An open file data structure, indexed by 'fd'
335 *  TODO:
336 *     should really have a separate per/file data structure that this
337 *     points to (eg: size, offset, driver, pathname should be in that)
338 */
339
340struct rtems_libio_tt {
341    rtems_driver_name_t              *driver;
342    off_t                             size;      /* size of file */
343    off_t                             offset;    /* current offset into file */
344    unsigned32                        flags;
345    rtems_filesystem_location_info_t  pathinfo;
346    Objects_Id                        sem;     
347    unsigned32                        data0;     /* private to "driver" */
348    void                             *data1;     /* ... */
349    void                             *file_info; /* used by file handlers */
350    rtems_filesystem_file_handlers_r *handlers;  /* type specific handlers */
351};
352
353/*
354 *  param block for read/write
355 *  Note: it must include 'offset' instead of using iop's offset since
356 *        we can have multiple outstanding i/o's on a device.
357 */
358
359typedef struct {
360    rtems_libio_t          *iop;
361    off_t                   offset;
362    unsigned8              *buffer;
363    unsigned32              count;
364    unsigned32              flags;
365    unsigned32              bytes_moved;
366} rtems_libio_rw_args_t;
367
368/*
369 *  param block for open/close
370 */
371
372typedef struct {
373    rtems_libio_t          *iop;
374    unsigned32              flags;
375    unsigned32              mode;
376} rtems_libio_open_close_args_t;
377
378/*
379 *  param block for ioctl
380 */
381
382typedef struct {
383    rtems_libio_t          *iop;
384    unsigned32              command;
385    void                   *buffer;
386    unsigned32              ioctl_return;
387} rtems_libio_ioctl_args_t;
388
389/*
390 *  Values for 'flag'
391 */
392
393#define LIBIO_FLAGS_NO_DELAY      0x0001  /* return immediately if no data */
394#define LIBIO_FLAGS_READ          0x0002  /* reading */
395#define LIBIO_FLAGS_WRITE         0x0004  /* writing */
396#define LIBIO_FLAGS_OPEN          0x0100  /* device is open */
397#define LIBIO_FLAGS_APPEND        0x0200  /* all writes append */
398#define LIBIO_FLAGS_CREATE        0x0400  /* create file */
399#define LIBIO_FLAGS_CLOSE_ON_EXEC 0x0800  /* close on process exec() */
400
401#define LIBIO_FLAGS_HANDLER_SHIFT 12
402#define LIBIO_FLAGS_HANDLER_MASK  0xF000  /* mask for external handler type */
403#define LIBIO_FLAGS_HANDLER_RTEMS 0x0000  /* `traditional' RTEMS I/O */
404#define LIBIO_FLAGS_HANDLER_SOCK  0x1000  /* BSD socket */
405
406#define LIBIO_FLAGS_READ_WRITE    (LIBIO_FLAGS_READ | LIBIO_FLAGS_WRITE)
407
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  unsigned32  flag,
418  unsigned32  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  unsigned32  count
429);
430
431typedef int (*rtems_libio_write_t)(
432  int         fd,
433  const void *buffer,
434  unsigned32  count
435);
436
437typedef int (*rtems_libio_ioctl_t)(
438  int         fd,
439  unsigned32  command,
440  void       *buffer
441);
442
443typedef int (*rtems_libio_lseek_t)(
444  int    fd,
445  off_t  offset,
446  int    whence
447);
448
449typedef struct {
450    rtems_libio_open_t   open;
451    rtems_libio_close_t  close;
452    rtems_libio_read_t   read;
453    rtems_libio_write_t  write;
454    rtems_libio_ioctl_t  ioctl;
455    rtems_libio_lseek_t  lseek;
456} rtems_libio_handler_t;
457
458/*
459 *  Register a set of external handlers
460 */
461
462void rtems_register_libio_handler(
463  int                          handler_flag,
464  const rtems_libio_handler_t *handler
465);
466
467/*
468 *  Macros to assist in management of external IO handlers.
469 */
470
471#define RTEMS_FILE_DESCRIPTOR_TYPE_FILE         0x0000
472#define RTEMS_FILE_DESCRIPTOR_TYPE_SOCKET       0x1000
473#define rtems_make_file_descriptor(fd,flags)    ((fd)|(flags))
474#define rtems_file_descriptor_base(fd)          ((fd) & 0x0FFF)
475#define rtems_file_descriptor_type(fd)          ((fd) & 0xF000)
476#define rtems_file_descriptor_type_index(fd)    ((((fd) & 0xF000) >> 12) - 1)
477
478/*
479 *  IOCTL values
480 */
481
482#define       RTEMS_IO_GET_ATTRIBUTES 1
483#define       RTEMS_IO_SET_ATTRIBUTES 2
484#define       RTEMS_IO_TCDRAIN        3
485
486/*
487 *  The following macros are used to build up the permissions sets
488 *  used to check permissions.  These are similar in style to the
489 *  mode_t bits and should stay compatible with them.
490 */
491
492#define RTEMS_LIBIO_PERMS_READ   S_IROTH
493#define RTEMS_LIBIO_PERMS_WRITE  S_IWOTH
494#define RTEMS_LIBIO_PERMS_RDWR   (S_IROTH|S_IWOTH)
495#define RTEMS_LIBIO_PERMS_EXEC   S_IXOTH
496#define RTEMS_LIBIO_PERMS_SEARCH RTEMS_LIBIO_PERMS_EXEC
497#define RTEMS_LIBIO_PERMS_RWX    S_IRWXO
498
499/*
500 *  Macros
501 */
502
503#define rtems_filesystem_make_dev_t( _major, _minor ) \
504  ((((dev_t)(_major)) << 32) | (dev_t)(_minor))
505
506#define rtems_filesystem_split_dev_t( _dev, _major, _minor ) \
507  do { \
508    (_major) = (rtems_device_major_number) ((_dev) >> 32); \
509    (_minor) = (rtems_device_minor_number) ((_dev) & 0xFFFFFFFF); \
510  } while(0)
511
512/*
513 * Verifies that the permission flag is valid.
514 */
515#define rtems_libio_is_valid_perms( _perm )     \
516 (~ ((~RTEMS_LIBIO_PERMS_RWX) & _perm ))
517
518
519/*
520 *  Prototypes for filesystem
521 */
522
523void rtems_filesystem_initialize( void );
524
525
526/*
527 * Callbacks from TERMIOS routines to device-dependent code
528 */
529
530#include <termios.h>
531
532typedef struct rtems_termios_callbacks {
533  int    (*firstOpen)(int major, int minor, void *arg);
534  int    (*lastClose)(int major, int minor, void *arg);
535  int    (*pollRead)(int minor);
536  int    (*write)(int minor, const char *buf, int len);
537  int    (*setAttributes)(int minor, const struct termios *t);
538  int    (*stopRemoteTx)(int minor);
539  int    (*startRemoteTx)(int minor);
540  int    outputUsesInterrupts;
541} rtems_termios_callbacks;
542
543/*
544 *  Device-independent TERMIOS routines
545 */
546
547void rtems_termios_initialize (void);
548
549rtems_status_code rtems_termios_open (
550  rtems_device_major_number      major,
551  rtems_device_minor_number      minor,
552  void                          *arg,
553  const rtems_termios_callbacks *callbacks
554);
555
556rtems_status_code rtems_termios_close(
557  void *arg
558);
559
560rtems_status_code rtems_termios_read(
561  void *arg
562);
563
564rtems_status_code rtems_termios_write(
565  void *arg
566);
567
568rtems_status_code rtems_termios_ioctl(
569  void *arg
570);
571
572int rtems_termios_enqueue_raw_characters(
573  void *ttyp,
574  char *buf,
575  int   len
576);
577
578int rtems_termios_dequeue_characters(
579  void *ttyp,
580  int   len
581);
582
583void rtems_termios_reserve_resources(
584  rtems_configuration_table *configuration,
585  rtems_unsigned32           number_of_devices
586);
587
588int unmount(
589  const char *mount_path
590);
591
592int mount(
593  rtems_filesystem_mount_table_entry_t **mt_entry,
594  rtems_filesystem_operations_table    *fs_ops,
595  char                                 *fsoptions,
596  char                                 *device,
597  char                                 *mount_point
598);
599
600#endif /* _RTEMS_LIBIO_H */
Note: See TracBrowser for help on using the repository browser.