source: rtems/cpukit/libcsupport/include/rtems/libio.h @ 73f6236

4.104.114.84.95
Last change on this file since 73f6236 was 73f6236, checked in by Joel Sherrill <joel.sherrill@…>, on 03/01/99 at 22:40:08

Patch from Eric Norum <eric@…> to eliminate external
IO handlers scheme that was implemented originally just to support
sockets. The file system IO switch is more general and works fine.

  • Property mode set to 100644
File size: 14.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#define LIBIO_FLAGS_READ_WRITE    (LIBIO_FLAGS_READ | LIBIO_FLAGS_WRITE)
401
402void rtems_libio_init(void);
403
404/*
405 *  External I/O handlers
406 */
407
408typedef int (*rtems_libio_open_t)(
409  const char  *pathname,
410  unsigned32  flag,
411  unsigned32  mode
412);
413
414typedef int (*rtems_libio_close_t)(
415  int  fd
416);
417
418typedef int (*rtems_libio_read_t)(
419  int         fd,
420  void       *buffer,
421  unsigned32  count
422);
423
424typedef int (*rtems_libio_write_t)(
425  int         fd,
426  const void *buffer,
427  unsigned32  count
428);
429
430typedef int (*rtems_libio_ioctl_t)(
431  int         fd,
432  unsigned32  command,
433  void       *buffer
434);
435
436typedef int (*rtems_libio_lseek_t)(
437  int    fd,
438  off_t  offset,
439  int    whence
440);
441
442/*
443 *  IOCTL values
444 */
445
446#define       RTEMS_IO_GET_ATTRIBUTES 1
447#define       RTEMS_IO_SET_ATTRIBUTES 2
448#define       RTEMS_IO_TCDRAIN        3
449
450/*
451 *  The following macros are used to build up the permissions sets
452 *  used to check permissions.  These are similar in style to the
453 *  mode_t bits and should stay compatible with them.
454 */
455
456#define RTEMS_LIBIO_PERMS_READ   S_IROTH
457#define RTEMS_LIBIO_PERMS_WRITE  S_IWOTH
458#define RTEMS_LIBIO_PERMS_RDWR   (S_IROTH|S_IWOTH)
459#define RTEMS_LIBIO_PERMS_EXEC   S_IXOTH
460#define RTEMS_LIBIO_PERMS_SEARCH RTEMS_LIBIO_PERMS_EXEC
461#define RTEMS_LIBIO_PERMS_RWX    S_IRWXO
462
463/*
464 *  Macros
465 */
466
467#define rtems_filesystem_make_dev_t( _major, _minor ) \
468  ((((dev_t)(_major)) << 32) | (dev_t)(_minor))
469
470#define rtems_filesystem_split_dev_t( _dev, _major, _minor ) \
471  do { \
472    (_major) = (rtems_device_major_number) ((_dev) >> 32); \
473    (_minor) = (rtems_device_minor_number) ((_dev) & 0xFFFFFFFF); \
474  } while(0)
475
476/*
477 * Verifies that the permission flag is valid.
478 */
479#define rtems_libio_is_valid_perms( _perm )     \
480 (~ ((~RTEMS_LIBIO_PERMS_RWX) & _perm ))
481
482
483/*
484 *  Prototypes for filesystem
485 */
486
487void rtems_filesystem_initialize( void );
488
489
490/*
491 * Callbacks from TERMIOS routines to device-dependent code
492 */
493
494#include <termios.h>
495
496typedef struct rtems_termios_callbacks {
497  int    (*firstOpen)(int major, int minor, void *arg);
498  int    (*lastClose)(int major, int minor, void *arg);
499  int    (*pollRead)(int minor);
500  int    (*write)(int minor, const char *buf, int len);
501  int    (*setAttributes)(int minor, const struct termios *t);
502  int    (*stopRemoteTx)(int minor);
503  int    (*startRemoteTx)(int minor);
504  int    outputUsesInterrupts;
505} rtems_termios_callbacks;
506
507/*
508 *  Device-independent TERMIOS routines
509 */
510
511void rtems_termios_initialize (void);
512
513rtems_status_code rtems_termios_open (
514  rtems_device_major_number      major,
515  rtems_device_minor_number      minor,
516  void                          *arg,
517  const rtems_termios_callbacks *callbacks
518);
519
520rtems_status_code rtems_termios_close(
521  void *arg
522);
523
524rtems_status_code rtems_termios_read(
525  void *arg
526);
527
528rtems_status_code rtems_termios_write(
529  void *arg
530);
531
532rtems_status_code rtems_termios_ioctl(
533  void *arg
534);
535
536int rtems_termios_enqueue_raw_characters(
537  void *ttyp,
538  char *buf,
539  int   len
540);
541
542int rtems_termios_dequeue_characters(
543  void *ttyp,
544  int   len
545);
546
547void rtems_termios_reserve_resources(
548  rtems_configuration_table *configuration,
549  rtems_unsigned32           number_of_devices
550);
551
552int unmount(
553  const char *mount_path
554);
555
556int mount(
557  rtems_filesystem_mount_table_entry_t **mt_entry,
558  rtems_filesystem_operations_table    *fs_ops,
559  char                                 *fsoptions,
560  char                                 *device,
561  char                                 *mount_point
562);
563
564#endif /* _RTEMS_LIBIO_H */
Note: See TracBrowser for help on using the repository browser.