OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rtems-20020807/] [cpukit/] [libcsupport/] [include/] [rtems/] [libio.h] - Blame information for rev 1026

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1026 ivang
/*
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
 *  libio.h,v 1.37 2002/01/16 22:54:59 joel Exp
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
typedef enum {
37
  RTEMS_FILESYSTEM_DIRECTORY,
38
  RTEMS_FILESYSTEM_DEVICE,
39
  RTEMS_FILESYSTEM_HARD_LINK,
40
  RTEMS_FILESYSTEM_SYM_LINK,
41
  RTEMS_FILESYSTEM_MEMORY_FILE
42
} rtems_filesystem_node_types_t;
43
 
44
/*
45
 *  File Handler Operations Table
46
 */
47
 
48
typedef int (*rtems_filesystem_open_t)(
49
  rtems_libio_t *iop,
50
  const char    *pathname,
51
  unsigned32     flag,
52
  unsigned32     mode
53
);
54
 
55
typedef int (*rtems_filesystem_close_t)(
56
  rtems_libio_t *iop
57
);
58
 
59
typedef int (*rtems_filesystem_read_t)(
60
  rtems_libio_t *iop,
61
  void          *buffer,
62
  unsigned32     count
63
);
64
 
65
typedef int (*rtems_filesystem_write_t)(
66
  rtems_libio_t *iop,
67
  const void    *buffer,
68
  unsigned32    count
69
);
70
 
71
typedef int (*rtems_filesystem_ioctl_t)(
72
  rtems_libio_t *iop,
73
  unsigned32     command,
74
  void          *buffer
75
);
76
 
77
typedef int (*rtems_filesystem_lseek_t)(
78
  rtems_libio_t *iop,
79
  off_t          length,
80
  int            whence
81
);
82
 
83
typedef int (*rtems_filesystem_fstat_t)(
84
  rtems_filesystem_location_info_t *loc,
85
  struct stat                      *buf
86
);
87
 
88
typedef int (*rtems_filesystem_fchmod_t)(
89
  rtems_filesystem_location_info_t *loc,
90
  mode_t                            mode
91
);
92
 
93
typedef int (*rtems_filesystem_ftruncate_t)(
94
  rtems_libio_t *iop,
95
  off_t          length
96
);
97
 
98
typedef int (*rtems_filesystem_fpathconf_t)(
99
  rtems_libio_t *iop,
100
  int name
101
);
102
 
103
typedef int (*rtems_filesystem_fsync_t)(
104
  rtems_libio_t *iop
105
);
106
 
107
typedef int (*rtems_filesystem_fdatasync_t)(
108
  rtems_libio_t *iop
109
);
110
 
111
typedef int (*rtems_filesystem_fcntl_t)(
112
  int            cmd,
113
  rtems_libio_t *iop
114
);
115
 
116
typedef int (*rtems_filesystem_rmnod_t)(
117
 rtems_filesystem_location_info_t      *pathloc       /* IN */
118
);
119
 
120
struct _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
 
149
typedef 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
 
161
typedef 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
 
167
typedef 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
 
173
typedef 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
 
179
typedef int (*rtems_filesystem_unlink_t)(
180
 rtems_filesystem_location_info_t  *pathloc       /* IN */
181
);
182
 
183
typedef 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
 
189
typedef int (*rtems_filesystem_freenode_t)(
190
 rtems_filesystem_location_info_t      *pathloc       /* IN */
191
);
192
 
193
typedef int (* rtems_filesystem_mount_t ) (
194
   rtems_filesystem_mount_table_entry_t *mt_entry     /* in */
195
);
196
 
197
typedef int (* rtems_filesystem_fsmount_me_t )(
198
   rtems_filesystem_mount_table_entry_t *mt_entry
199
);
200
 
201
typedef int (* rtems_filesystem_unmount_t ) (
202
   rtems_filesystem_mount_table_entry_t *mt_entry     /* in */
203
);
204
 
205
typedef int (* rtems_filesystem_fsunmount_me_t ) (
206
   rtems_filesystem_mount_table_entry_t *mt_entry    /* in */
207
);
208
 
209
typedef rtems_filesystem_node_types_t (* rtems_filesystem_node_type_t) (
210
  rtems_filesystem_location_info_t    *pathloc      /* in */
211
);
212
 
213
typedef 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
 
219
typedef int (*rtems_filesystem_evaluate_link_t)(
220
  rtems_filesystem_location_info_t *pathloc,     /* IN/OUT */
221
  int                               flags        /* IN     */
222
);
223
 
224
typedef 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
 
230
typedef 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
 */
243
struct _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
 
269
struct 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
 
283
typedef 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
 
302
struct 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
 
324
typedef 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
 
339
struct 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
    unsigned32                        flags;
344
    rtems_filesystem_location_info_t  pathinfo;
345
    Objects_Id                        sem;
346
    unsigned32                        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
 
358
typedef struct {
359
    rtems_libio_t          *iop;
360
    off_t                   offset;
361
    unsigned8              *buffer;
362
    unsigned32              count;
363
    unsigned32              flags;
364
    unsigned32              bytes_moved;
365
} rtems_libio_rw_args_t;
366
 
367
/*
368
 *  param block for open/close
369
 */
370
 
371
typedef struct {
372
    rtems_libio_t          *iop;
373
    unsigned32              flags;
374
    unsigned32              mode;
375
} rtems_libio_open_close_args_t;
376
 
377
/*
378
 *  param block for ioctl
379
 */
380
 
381
typedef struct {
382
    rtems_libio_t          *iop;
383
    unsigned32              command;
384
    void                   *buffer;
385
    unsigned32              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
 
401
void rtems_libio_init(void);
402
 
403
/*
404
 *  External I/O handlers
405
 */
406
 
407
typedef int (*rtems_libio_open_t)(
408
  const char  *pathname,
409
  unsigned32  flag,
410
  unsigned32  mode
411
);
412
 
413
typedef int (*rtems_libio_close_t)(
414
  int  fd
415
);
416
 
417
typedef int (*rtems_libio_read_t)(
418
  int         fd,
419
  void       *buffer,
420
  unsigned32  count
421
);
422
 
423
typedef int (*rtems_libio_write_t)(
424
  int         fd,
425
  const void *buffer,
426
  unsigned32  count
427
);
428
 
429
typedef int (*rtems_libio_ioctl_t)(
430
  int         fd,
431
  unsigned32  command,
432
  void       *buffer
433
);
434
 
435
typedef 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
#define rtems_filesystem_make_dev_t( _major, _minor ) \
459
  ((((dev_t)(_major)) << 32) | (dev_t)(_minor))
460
 
461
#define rtems_filesystem_dev_major_t( _dev ) \
462
  (rtems_device_major_number) ((_dev) >> 32)
463
 
464
#define rtems_filesystem_dev_minor_t( _dev ) \
465
  (rtems_device_minor_number) ((_dev) & 0xFFFFFFFF)
466
 
467
#define rtems_filesystem_split_dev_t( _dev, _major, _minor ) \
468
  do { \
469
    (_major) = rtems_filesystem_dev_major_t ( _dev ); \
470
    (_minor) = rtems_filesystem_dev_minor_t( _dev ); \
471
  } while(0)
472
 
473
/*
474
 * Verifies that the permission flag is valid.
475
 */
476
#define rtems_libio_is_valid_perms( _perm )     \
477
 (~ ((~RTEMS_LIBIO_PERMS_RWX) & _perm ))
478
 
479
 
480
/*
481
 *  Prototypes for filesystem
482
 */
483
 
484
void rtems_filesystem_initialize( void );
485
 
486
 
487
/*
488
 * Callbacks from TERMIOS routines to device-dependent code
489
 */
490
 
491
#include <termios.h>
492
 
493
typedef struct rtems_termios_callbacks {
494
  int    (*firstOpen)(int major, int minor, void *arg);
495
  int    (*lastClose)(int major, int minor, void *arg);
496
  int    (*pollRead)(int minor);
497
  int    (*write)(int minor, const char *buf, int len);
498
  int    (*setAttributes)(int minor, const struct termios *t);
499
  int    (*stopRemoteTx)(int minor);
500
  int    (*startRemoteTx)(int minor);
501
  int    outputUsesInterrupts;
502
} rtems_termios_callbacks;
503
 
504
/*
505
 *  Device-independent TERMIOS routines
506
 */
507
 
508
void rtems_termios_initialize (void);
509
 
510
rtems_status_code rtems_termios_open (
511
  rtems_device_major_number      major,
512
  rtems_device_minor_number      minor,
513
  void                          *arg,
514
  const rtems_termios_callbacks *callbacks
515
);
516
 
517
rtems_status_code rtems_termios_close(
518
  void *arg
519
);
520
 
521
rtems_status_code rtems_termios_read(
522
  void *arg
523
);
524
 
525
rtems_status_code rtems_termios_write(
526
  void *arg
527
);
528
 
529
rtems_status_code rtems_termios_ioctl(
530
  void *arg
531
);
532
 
533
int rtems_termios_enqueue_raw_characters(
534
  void *ttyp,
535
  char *buf,
536
  int   len
537
);
538
 
539
int rtems_termios_dequeue_characters(
540
  void *ttyp,
541
  int   len
542
);
543
 
544
void rtems_termios_reserve_resources(
545
  rtems_configuration_table *configuration,
546
  rtems_unsigned32           number_of_devices
547
);
548
 
549
int unmount(
550
  const char *mount_path
551
);
552
 
553
int mount(
554
  rtems_filesystem_mount_table_entry_t **mt_entry,
555
  rtems_filesystem_operations_table    *fs_ops,
556
  rtems_filesystem_options_t            fsoptions,
557
  char                                 *device,
558
  char                                 *mount_point
559
);
560
 
561
/*
562
 *  Boot Time Mount Table Structure
563
 */
564
 
565
typedef struct {
566
  rtems_filesystem_operations_table     *fs_ops;
567
  rtems_filesystem_options_t             fsoptions;
568
  char                                  *device;
569
  char                                  *mount_point;
570
} rtems_filesystem_mount_table_t;
571
 
572
extern rtems_filesystem_mount_table_t *rtems_filesystem_mount_table;
573
extern int                             rtems_filesystem_mount_table_size;
574
 
575
#endif /* _RTEMS_LIBIO_H */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.