OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [lib/] [libc/] [libio.h] - Blame information for rev 493

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

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

powered by: WebSVN 2.1.0

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