source: rtems/c/src/lib/include/rtems/libio.h @ 7b0001f7

4.104.114.84.95
Last change on this file since 7b0001f7 was 7b0001f7, checked in by Joel Sherrill <joel.sherrill@…>, on 10/25/00 at 16:56:11

2000-10-24 Joel Sherrill <joel@…>

  • libc/ioman.c: Moved to libfs.
  • libc/Makefile.am: Removed ioman.c as part of moving it to libfs.
  • libc/base_fs.c: Removed include of imfs.h and reworded comment to avoid being IMFS specific.
  • libc/libio.h: Removed prototype of IMFS_ops since it should not be in this file.
  • libc/mount.c: Removed IMFS specific configuration information.
  • libc/unmount.c: Removed include of imfs.h and reworded comment to avoid being IMFS specific.
  • Property mode set to 100644
File size: 15.1 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_h;
130    rtems_filesystem_close_t        close_h;
131    rtems_filesystem_read_t         read_h;
132    rtems_filesystem_write_t        write_h;
133    rtems_filesystem_ioctl_t        ioctl_h;
134    rtems_filesystem_lseek_t        lseek_h;
135    rtems_filesystem_fstat_t        fstat_h;
136    rtems_filesystem_fchmod_t       fchmod_h;
137    rtems_filesystem_ftruncate_t    ftruncate_h;
138    rtems_filesystem_fpathconf_t    fpathconf_h;
139    rtems_filesystem_fsync_t        fsync_h;
140    rtems_filesystem_fdatasync_t    fdatasync_h;
141    rtems_filesystem_fcntl_t        fcntl_h;
142    rtems_filesystem_rmnod_t        rmnod_h;
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_h;
253    rtems_filesystem_evalmake_t      evalformake_h;
254    rtems_filesystem_link_t          link_h;
255    rtems_filesystem_unlink_t        unlink_h;
256    rtems_filesystem_node_type_t     node_type_h;
257    rtems_filesystem_mknod_t         mknod_h;
258    rtems_filesystem_chown_t         chown_h;
259    rtems_filesystem_freenode_t      freenod_h;
260    rtems_filesystem_mount_t         mount_h;
261    rtems_filesystem_fsmount_me_t    fsmount_me_h;
262    rtems_filesystem_unmount_t       unmount_h;
263    rtems_filesystem_fsunmount_me_t  fsunmount_me_h;
264    rtems_filesystem_utime_t         utime_h;
265    rtems_filesystem_evaluate_link_t eval_link_h;
266    rtems_filesystem_symlink_t       symlink_h;
267    rtems_filesystem_readlink_t      readlink_h;
268} rtems_filesystem_operations_table;
269
270/*
271 * Structure used to determine a location/filesystem in the tree.
272 */
273
274struct rtems_filesystem_location_info_tt
275{
276  void                                   *node_access;
277  rtems_filesystem_file_handlers_r       *handlers;
278  rtems_filesystem_operations_table      *ops;
279  rtems_filesystem_mount_table_entry_t   *mt_entry;
280};
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    unsigned32                        flags;
348    rtems_filesystem_location_info_t  pathinfo;
349    Objects_Id                        sem;     
350    unsigned32                        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    unsigned8              *buffer;
366    unsigned32              count;
367    unsigned32              flags;
368    unsigned32              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    unsigned32              flags;
378    unsigned32              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    unsigned32              command;
388    void                   *buffer;
389    unsigned32              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  unsigned32  flag,
414  unsigned32  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  unsigned32  count
425);
426
427typedef int (*rtems_libio_write_t)(
428  int         fd,
429  const void *buffer,
430  unsigned32  count
431);
432
433typedef int (*rtems_libio_ioctl_t)(
434  int         fd,
435  unsigned32  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#define rtems_filesystem_make_dev_t( _major, _minor ) \
463  ((((dev_t)(_major)) << 32) | (dev_t)(_minor))
464
465#define rtems_filesystem_dev_major_t( _dev ) \
466  (rtems_device_major_number) ((_dev) >> 32)
467
468#define rtems_filesystem_dev_minor_t( _dev ) \
469  (rtems_device_minor_number) ((_dev) & 0xFFFFFFFF)
470
471#define rtems_filesystem_split_dev_t( _dev, _major, _minor ) \
472  do { \
473    (_major) = rtems_filesystem_dev_major_t ( _dev ); \
474    (_minor) = rtems_filesystem_dev_minor_t( _dev ); \
475  } while(0)
476
477/*
478 * Verifies that the permission flag is valid.
479 */
480#define rtems_libio_is_valid_perms( _perm )     \
481 (~ ((~RTEMS_LIBIO_PERMS_RWX) & _perm ))
482
483
484/*
485 *  Prototypes for filesystem
486 */
487
488void rtems_filesystem_initialize( void );
489
490
491/*
492 * Callbacks from TERMIOS routines to device-dependent code
493 */
494
495#include <termios.h>
496
497typedef struct rtems_termios_callbacks {
498  int    (*firstOpen)(int major, int minor, void *arg);
499  int    (*lastClose)(int major, int minor, void *arg);
500  int    (*pollRead)(int minor);
501  int    (*write)(int minor, const char *buf, int len);
502  int    (*setAttributes)(int minor, const struct termios *t);
503  int    (*stopRemoteTx)(int minor);
504  int    (*startRemoteTx)(int minor);
505  int    outputUsesInterrupts;
506} rtems_termios_callbacks;
507
508/*
509 *  Device-independent TERMIOS routines
510 */
511
512void rtems_termios_initialize (void);
513
514rtems_status_code rtems_termios_open (
515  rtems_device_major_number      major,
516  rtems_device_minor_number      minor,
517  void                          *arg,
518  const rtems_termios_callbacks *callbacks
519);
520
521rtems_status_code rtems_termios_close(
522  void *arg
523);
524
525rtems_status_code rtems_termios_read(
526  void *arg
527);
528
529rtems_status_code rtems_termios_write(
530  void *arg
531);
532
533rtems_status_code rtems_termios_ioctl(
534  void *arg
535);
536
537int rtems_termios_enqueue_raw_characters(
538  void *ttyp,
539  char *buf,
540  int   len
541);
542
543int rtems_termios_dequeue_characters(
544  void *ttyp,
545  int   len
546);
547
548void rtems_termios_reserve_resources(
549  rtems_configuration_table *configuration,
550  rtems_unsigned32           number_of_devices
551);
552
553int unmount(
554  const char *mount_path
555);
556
557int mount(
558  rtems_filesystem_mount_table_entry_t **mt_entry,
559  rtems_filesystem_operations_table    *fs_ops,
560  rtems_filesystem_options_t            fsoptions,
561  char                                 *device,
562  char                                 *mount_point
563);
564
565/*
566 *  Boot Time Mount Table Structure
567 */
568
569typedef struct {
570  rtems_filesystem_operations_table     *fs_ops;
571  rtems_filesystem_options_t             fsoptions;
572  char                                  *device;
573  char                                  *mount_point;
574} rtems_filesystem_mount_table_t;
575
576extern rtems_filesystem_mount_table_t *rtems_filesystem_mount_table;
577extern int                             rtems_filesystem_mount_table_size;
578
579#endif /* _RTEMS_LIBIO_H */
Note: See TracBrowser for help on using the repository browser.