source: rtems/c/src/lib/libc/libio.h @ 073e2411

4.104.114.84.95
Last change on this file since 073e2411 was 9b05600, checked in by Joel Sherrill <joel.sherrill@…>, on 06/14/00 at 20:22:31

* empty log message *

  • Property mode set to 100644
File size: 15.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.OARcorp.com/rtems/license.html.
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
31typedef struct rtems_libio_tt rtems_libio_t;
32
33struct rtems_filesystem_location_info_tt;
34typedef struct rtems_filesystem_location_info_tt
35    rtems_filesystem_location_info_t;
36
37struct rtems_filesystem_mount_table_entry_tt;
38typedef struct rtems_filesystem_mount_table_entry_tt
39    rtems_filesystem_mount_table_entry_t;
40
41/*
42 * Valid RTEMS file types.
43 */
44typedef enum {
45  RTEMS_FILESYSTEM_DIRECTORY,
46  RTEMS_FILESYSTEM_DEVICE,
47  RTEMS_FILESYSTEM_HARD_LINK,
48  RTEMS_FILESYSTEM_SYM_LINK,
49  RTEMS_FILESYSTEM_MEMORY_FILE
50} 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  unsigned32     flag,
60  unsigned32     mode
61);
62
63typedef int (*rtems_filesystem_close_t)(
64  rtems_libio_t *iop
65);
66
67typedef int (*rtems_filesystem_read_t)(
68  rtems_libio_t *iop,
69  void          *buffer,
70  unsigned32     count
71);
72
73typedef int (*rtems_filesystem_write_t)(
74  rtems_libio_t *iop,
75  const void    *buffer,
76  unsigned32    count
77);
78
79typedef int (*rtems_filesystem_ioctl_t)(
80  rtems_libio_t *iop,
81  unsigned32     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
128typedef struct {
129    rtems_filesystem_open_t         open;
130    rtems_filesystem_close_t        close;
131    rtems_filesystem_read_t         read;
132    rtems_filesystem_write_t        write;
133    rtems_filesystem_ioctl_t        ioctl;
134    rtems_filesystem_lseek_t        lseek;
135    rtems_filesystem_fstat_t        fstat;
136    rtems_filesystem_fchmod_t       fchmod;
137    rtems_filesystem_ftruncate_t    ftruncate;
138    rtems_filesystem_fpathconf_t    fpathconf;
139    rtems_filesystem_fsync_t        fsync;
140    rtems_filesystem_fdatasync_t    fdatasync;
141    rtems_filesystem_fcntl_t        fcntl;
142    rtems_filesystem_rmnod_t        rmnod;
143} rtems_filesystem_file_handlers_r;
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 */
251typedef struct {
252    rtems_filesystem_evalpath_t      evalpath;
253    rtems_filesystem_evalmake_t      evalformake;
254    rtems_filesystem_link_t          link;
255    rtems_filesystem_unlink_t        unlink;
256    rtems_filesystem_node_type_t     node_type;
257    rtems_filesystem_mknod_t         mknod;
258    rtems_filesystem_chown_t         chown;
259    rtems_filesystem_freenode_t      freenod;
260    rtems_filesystem_mount_t         mount;
261    rtems_filesystem_fsmount_me_t    fsmount_me;
262    rtems_filesystem_unmount_t       unmount;
263    rtems_filesystem_fsunmount_me_t  fsunmount_me;
264    rtems_filesystem_utime_t         utime;
265    rtems_filesystem_evaluate_link_t eval_link;
266    rtems_filesystem_symlink_t       symlink;
267    rtems_filesystem_readlink_t      readlink;
268} rtems_filesystem_operations_table;
269
270#define IMFS_FILE_SYSTEM IMFS_ops
271extern rtems_filesystem_operations_table  IMFS_ops;
272
273
274/*
275 * Structure used to determine a location/filesystem in the tree.
276 */
277
278struct rtems_filesystem_location_info_tt
279{
280  void                                   *node_access;
281  rtems_filesystem_file_handlers_r       *handlers;
282  rtems_filesystem_operations_table      *ops;
283  rtems_filesystem_mount_table_entry_t   *mt_entry;
284};
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    unsigned32                        flags;
352    rtems_filesystem_location_info_t  pathinfo;
353    Objects_Id                        sem;     
354    unsigned32                        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    unsigned8              *buffer;
370    unsigned32              count;
371    unsigned32              flags;
372    unsigned32              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    unsigned32              flags;
382    unsigned32              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    unsigned32              command;
392    void                   *buffer;
393    unsigned32              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  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
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#define rtems_filesystem_make_dev_t( _major, _minor ) \
467  ((((dev_t)(_major)) << 32) | (dev_t)(_minor))
468
469#define rtems_filesystem_split_dev_t( _dev, _major, _minor ) \
470  do { \
471    (_major) = (rtems_device_major_number) ((_dev) >> 32); \
472    (_minor) = (rtems_device_minor_number) ((_dev) & 0xFFFFFFFF); \
473  } while(0)
474
475/*
476 * Verifies that the permission flag is valid.
477 */
478#define rtems_libio_is_valid_perms( _perm )     \
479 (~ ((~RTEMS_LIBIO_PERMS_RWX) & _perm ))
480
481
482/*
483 *  Prototypes for filesystem
484 */
485
486void rtems_filesystem_initialize( void );
487
488
489/*
490 * Callbacks from TERMIOS routines to device-dependent code
491 */
492
493#include <termios.h>
494
495typedef struct rtems_termios_callbacks {
496  int    (*firstOpen)(int major, int minor, void *arg);
497  int    (*lastClose)(int major, int minor, void *arg);
498  int    (*pollRead)(int minor);
499  int    (*write)(int minor, const char *buf, int len);
500  int    (*setAttributes)(int minor, const struct termios *t);
501  int    (*stopRemoteTx)(int minor);
502  int    (*startRemoteTx)(int minor);
503  int    outputUsesInterrupts;
504} rtems_termios_callbacks;
505
506/*
507 *  Device-independent TERMIOS routines
508 */
509
510void rtems_termios_initialize (void);
511
512rtems_status_code rtems_termios_open (
513  rtems_device_major_number      major,
514  rtems_device_minor_number      minor,
515  void                          *arg,
516  const rtems_termios_callbacks *callbacks
517);
518
519rtems_status_code rtems_termios_close(
520  void *arg
521);
522
523rtems_status_code rtems_termios_read(
524  void *arg
525);
526
527rtems_status_code rtems_termios_write(
528  void *arg
529);
530
531rtems_status_code rtems_termios_ioctl(
532  void *arg
533);
534
535int rtems_termios_enqueue_raw_characters(
536  void *ttyp,
537  char *buf,
538  int   len
539);
540
541int rtems_termios_dequeue_characters(
542  void *ttyp,
543  int   len
544);
545
546void rtems_termios_reserve_resources(
547  rtems_configuration_table *configuration,
548  rtems_unsigned32           number_of_devices
549);
550
551int unmount(
552  const char *mount_path
553);
554
555int mount(
556  rtems_filesystem_mount_table_entry_t **mt_entry,
557  rtems_filesystem_operations_table    *fs_ops,
558  rtems_filesystem_options_t            fsoptions,
559  char                                 *device,
560  char                                 *mount_point
561);
562
563/*
564 *  Boot Time Mount Table Structure
565 */
566
567typedef struct {
568  rtems_filesystem_operations_table     *fs_ops;
569  rtems_filesystem_options_t             fsoptions;
570  char                                  *device;
571  char                                  *mount_point;
572} rtems_filesystem_mount_table_t;
573
574extern rtems_filesystem_mount_table_t *rtems_filesystem_mount_table;
575extern int                             rtems_filesystem_mount_table_size;
576
577#endif /* _RTEMS_LIBIO_H */
Note: See TracBrowser for help on using the repository browser.