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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [io/] [fileio/] [v2_0/] [include/] [fileio.h] - Blame information for rev 174

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
#ifndef CYGONCE_FILEIO_H
2
#define CYGONCE_FILEIO_H
3
//=============================================================================
4
//
5
//      fileio.h
6
//
7
//      Fileio header
8
//
9
//=============================================================================
10
//####ECOSGPLCOPYRIGHTBEGIN####
11
// -------------------------------------------
12
// This file is part of eCos, the Embedded Configurable Operating System.
13
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
14
//
15
// eCos is free software; you can redistribute it and/or modify it under
16
// the terms of the GNU General Public License as published by the Free
17
// Software Foundation; either version 2 or (at your option) any later version.
18
//
19
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
20
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
21
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
22
// for more details.
23
//
24
// You should have received a copy of the GNU General Public License along
25
// with eCos; if not, write to the Free Software Foundation, Inc.,
26
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
27
//
28
// As a special exception, if other files instantiate templates or use macros
29
// or inline functions from this file, or you compile this file and link it
30
// with other works to produce a work based on this file, this file does not
31
// by itself cause the resulting work to be covered by the GNU General Public
32
// License. However the source code for this file must still be made available
33
// in accordance with section (3) of the GNU General Public License.
34
//
35
// This exception does not invalidate any other reasons why a work based on
36
// this file might be covered by the GNU General Public License.
37
//
38
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
39
// at http://sources.redhat.com/ecos/ecos-license/
40
// -------------------------------------------
41
//####ECOSGPLCOPYRIGHTEND####
42
//=============================================================================
43
//#####DESCRIPTIONBEGIN####
44
//
45
// Author(s):     nickg
46
// Contributors:  nickg
47
// Date:          2000-05-25
48
// Purpose:       Fileio header
49
// Description:   This header contains the external definitions of the general file
50
//                IO subsystem for POSIX and EL/IX compatability.
51
//              
52
// Usage:
53
//              #include <fileio.h>
54
//              ...
55
//              
56
//
57
//####DESCRIPTIONEND####
58
//
59
//=============================================================================
60
 
61
#include <pkgconf/hal.h>
62
#include <pkgconf/kernel.h>
63
#include <pkgconf/io_fileio.h>
64
 
65
#include <cyg/infra/cyg_type.h>
66
#include <cyg/hal/hal_tables.h>
67
 
68
#include <stddef.h>             // NULL, size_t
69
#include <limits.h>
70
#include <sys/types.h>
71
#include <fcntl.h>
72
#include <sys/stat.h>
73
 
74
//=============================================================================
75
// forward definitions
76
 
77
struct cyg_mtab_entry;
78
typedef struct cyg_mtab_entry cyg_mtab_entry;
79
 
80
struct  cyg_fstab_entry;
81
typedef struct  cyg_fstab_entry  cyg_fstab_entry;
82
 
83
struct CYG_FILEOPS_TAG;
84
typedef struct CYG_FILEOPS_TAG cyg_fileops;
85
 
86
struct CYG_FILE_TAG;
87
typedef struct CYG_FILE_TAG cyg_file;
88
 
89
struct CYG_IOVEC_TAG;
90
typedef struct CYG_IOVEC_TAG cyg_iovec;
91
 
92
struct CYG_UIO_TAG;
93
typedef struct CYG_UIO_TAG cyg_uio;
94
 
95
struct CYG_SELINFO_TAG;
96
typedef struct CYG_SELINFO_TAG cyg_selinfo;
97
 
98
//=============================================================================
99
// Directory pointer
100
 
101
typedef CYG_ADDRWORD cyg_dir;
102
 
103
#define CYG_DIR_NULL 0
104
 
105
//=============================================================================
106
// Filesystem table entry
107
 
108
typedef int     cyg_fsop_mount    ( cyg_fstab_entry *fste, cyg_mtab_entry *mte );
109
typedef int     cyg_fsop_umount   ( cyg_mtab_entry *mte );
110
typedef int     cyg_fsop_open     ( cyg_mtab_entry *mte, cyg_dir dir, const char *name,
111
                                    int mode,  cyg_file *fte );
112
typedef int     cyg_fsop_unlink   ( cyg_mtab_entry *mte, cyg_dir dir, const char *name );
113
typedef int     cyg_fsop_mkdir    ( cyg_mtab_entry *mte, cyg_dir dir, const char *name );
114
typedef int     cyg_fsop_rmdir    ( cyg_mtab_entry *mte, cyg_dir dir, const char *name );
115
typedef int     cyg_fsop_rename   ( cyg_mtab_entry *mte, cyg_dir dir1, const char *name1,
116
                                    cyg_dir dir2, const char *name2 );
117
typedef int     cyg_fsop_link     ( cyg_mtab_entry *mte, cyg_dir dir1, const char *name1,
118
                                    cyg_dir dir2, const char *name2, int type );
119
typedef int     cyg_fsop_opendir  ( cyg_mtab_entry *mte, cyg_dir dir, const char *name,
120
                                    cyg_file *fte );
121
typedef int     cyg_fsop_chdir    ( cyg_mtab_entry *mte, cyg_dir dir, const char *name,
122
                                    cyg_dir *dir_out );
123
typedef int     cyg_fsop_stat     ( cyg_mtab_entry *mte, cyg_dir dir, const char *name,
124
                                    struct stat *buf);
125
typedef int     cyg_fsop_getinfo  ( cyg_mtab_entry *mte, cyg_dir dir, const char *name,
126
                                    int key, void *buf, int len );
127
typedef int     cyg_fsop_setinfo  ( cyg_mtab_entry *mte, cyg_dir dir, const char *name,
128
                                    int key, void *buf, int len );
129
 
130
 
131
struct cyg_fstab_entry
132
{
133
    const char          *name;          // filesystem name
134
    CYG_ADDRWORD        data;           // private data value
135
    cyg_uint32          syncmode;       // synchronization mode
136
 
137
    cyg_fsop_mount      *mount;
138
    cyg_fsop_umount     *umount;
139
    cyg_fsop_open       *open;
140
    cyg_fsop_unlink     *unlink;
141
    cyg_fsop_mkdir      *mkdir;
142
    cyg_fsop_rmdir      *rmdir;
143
    cyg_fsop_rename     *rename;
144
    cyg_fsop_link       *link;
145
    cyg_fsop_opendir    *opendir;
146
    cyg_fsop_chdir      *chdir;
147
    cyg_fsop_stat       *stat;
148
    cyg_fsop_getinfo    *getinfo;
149
    cyg_fsop_setinfo    *setinfo;
150
} CYG_HAL_TABLE_TYPE;
151
 
152
//-----------------------------------------------------------------------------
153
// Keys for getinfo() and setinfo()
154
 
155
#define FS_INFO_CONF            1       /* pathconf() */
156
#define FS_INFO_ACCESS          2       /* access() */
157
#define FS_INFO_GETCWD          3       /* getcwd() */
158
 
159
//-----------------------------------------------------------------------------
160
// Types for link()
161
 
162
#define CYG_FSLINK_HARD         1       /* form a hard link */
163
#define CYG_FSLINK_SOFT         2       /* form a soft link */
164
 
165
//-----------------------------------------------------------------------------
166
// getinfo() and setinfo() buffers structures.
167
 
168
struct cyg_getcwd_info
169
{
170
    char        *buf;           /* buffer for cwd string */
171
    size_t      size;           /* size of buffer */
172
};
173
 
174
//-----------------------------------------------------------------------------
175
// Macro to define an initialized fstab entry
176
 
177
#define FSTAB_ENTRY( _l, _name, _data, _syncmode, _mount, _umount,      \
178
                     _open, _unlink,  _mkdir, _rmdir, _rename, _link,   \
179
                     _opendir, _chdir, _stat, _getinfo, _setinfo)       \
180
struct cyg_fstab_entry _l CYG_HAL_TABLE_ENTRY(fstab) =                  \
181
{                                                                       \
182
    _name,                                                              \
183
    _data,                                                              \
184
    _syncmode,                                                          \
185
    _mount,                                                             \
186
    _umount,                                                            \
187
    _open,                                                              \
188
    _unlink,                                                            \
189
    _mkdir,                                                             \
190
    _rmdir,                                                             \
191
    _rename,                                                            \
192
    _link,                                                              \
193
    _opendir,                                                           \
194
    _chdir,                                                             \
195
    _stat,                                                              \
196
    _getinfo,                                                           \
197
    _setinfo                                                            \
198
};
199
 
200
//=============================================================================
201
// Mount table entry
202
 
203
struct cyg_mtab_entry
204
{
205
    const char          *name;          // name of mount point
206
    const char          *fsname;        // name of implementing filesystem
207
    const char          *devname;       // name of hardware device
208
    CYG_ADDRWORD        data;           // private data value
209
 
210
    // The following are filled in after a successful mount operation
211
    cyg_bool            valid;          // Valid entry?
212
    cyg_fstab_entry     *fs;            // pointer to fstab entry
213
    cyg_dir             root;           // root directory pointer
214
} CYG_HAL_TABLE_TYPE;
215
 
216
 
217
// This macro defines an initialized mtab entry
218
 
219
#define MTAB_ENTRY( _l, _name, _fsname, _devname, _data )       \
220
struct cyg_mtab_entry _l CYG_HAL_TABLE_ENTRY(mtab) =            \
221
{                                                               \
222
    _name,                                                      \
223
    _fsname,                                                    \
224
    _devname,                                                   \
225
    _data,                                                      \
226
    false,                                                      \
227
    NULL,                                                       \
228
    CYG_DIR_NULL                                                \
229
};
230
 
231
//=============================================================================
232
// IO vector descriptors
233
 
234
struct CYG_IOVEC_TAG
235
{
236
    void           *iov_base;           /* Base address. */
237
    ssize_t        iov_len;             /* Length. */
238
};
239
 
240
enum    cyg_uio_rw { UIO_READ, UIO_WRITE };
241
 
242
/* Segment flag values. */
243
enum cyg_uio_seg
244
{
245
    UIO_USERSPACE,                      /* from user data space */
246
    UIO_SYSSPACE                        /* from system space */
247
};
248
 
249
struct CYG_UIO_TAG
250
{
251
    struct CYG_IOVEC_TAG *uio_iov;      /* pointer to array of iovecs */
252
    int                  uio_iovcnt;    /* number of iovecs in array */
253
    off_t                uio_offset;    /* offset into file this uio corresponds to */
254
    ssize_t              uio_resid;     /* residual i/o count */
255
    enum cyg_uio_seg     uio_segflg;    /* see above */
256
    enum cyg_uio_rw      uio_rw;        /* see above */
257
};
258
 
259
// Limits
260
#define UIO_SMALLIOV    8               /* 8 on stack, else malloc */
261
 
262
//=============================================================================
263
// Description of open file
264
 
265
typedef int cyg_fileop_readwrite (struct CYG_FILE_TAG *fp, struct CYG_UIO_TAG *uio);
266
typedef cyg_fileop_readwrite cyg_fileop_read;
267
typedef cyg_fileop_readwrite cyg_fileop_write;
268
typedef int cyg_fileop_lseek   (struct CYG_FILE_TAG *fp, off_t *pos, int whence );
269
typedef int cyg_fileop_ioctl   (struct CYG_FILE_TAG *fp, CYG_ADDRWORD com,
270
                                CYG_ADDRWORD data);
271
typedef int cyg_fileop_select  (struct CYG_FILE_TAG *fp, int which, CYG_ADDRWORD info);
272
typedef int cyg_fileop_fsync   (struct CYG_FILE_TAG *fp, int mode );
273
typedef int cyg_fileop_close   (struct CYG_FILE_TAG *fp);
274
typedef int cyg_fileop_fstat   (struct CYG_FILE_TAG *fp, struct stat *buf );
275
typedef int cyg_fileop_getinfo (struct CYG_FILE_TAG *fp, int key, void *buf, int len );
276
typedef int cyg_fileop_setinfo (struct CYG_FILE_TAG *fp, int key, void *buf, int len );
277
 
278
struct CYG_FILEOPS_TAG
279
{
280
    cyg_fileop_read     *fo_read;
281
    cyg_fileop_write    *fo_write;
282
    cyg_fileop_lseek    *fo_lseek;
283
    cyg_fileop_ioctl    *fo_ioctl;
284
    cyg_fileop_select   *fo_select;
285
    cyg_fileop_fsync    *fo_fsync;
286
    cyg_fileop_close    *fo_close;
287
    cyg_fileop_fstat    *fo_fstat;
288
    cyg_fileop_getinfo  *fo_getinfo;
289
    cyg_fileop_setinfo  *fo_setinfo;
290
};
291
 
292
struct CYG_FILE_TAG
293
{
294
    cyg_uint32                  f_flag;         /* file state                   */
295
    cyg_uint16                  f_ucount;       /* use count                    */
296
    cyg_uint16                  f_type;         /* descriptor type              */
297
    cyg_uint32                  f_syncmode;     /* synchronization protocol     */
298
    struct CYG_FILEOPS_TAG      *f_ops;         /* file operations              */
299
    off_t                       f_offset;       /* current offset               */
300
    CYG_ADDRWORD                f_data;         /* file or socket               */
301
    CYG_ADDRWORD                f_xops;         /* extra type specific ops      */
302
    cyg_mtab_entry              *f_mte;         /* mount table entry            */
303
};
304
 
305
//-----------------------------------------------------------------------------
306
// File flags
307
 
308
// Allocation here is that bits 0..15 are copies of bits from the open
309
// flags, bits 16..23 are extra bits that are visible to filesystems but
310
// are not derived from the open call, and bits 24..31 are reserved for
311
// the fileio infrastructure.
312
#define CYG_FREAD       O_RDONLY
313
#define CYG_FWRITE      O_WRONLY
314
#define CYG_FNONBLOCK   O_NONBLOCK
315
#define CYG_FAPPEND     O_APPEND
316
#define CYG_FASYNC      0x00010000
317
#define CYG_FDIR        0x00020000
318
 
319
#define CYG_FLOCKED     0x01000000  // Set if file is locked
320
#define CYG_FLOCK       0x02000000  // Lock during file ops
321
#define CYG_FALLOC      0x80000000  // File is "busy", i.e. allocated
322
 
323
// Mask for open mode bits stored in file object
324
#define CYG_FILE_MODE_MASK (CYG_FREAD|CYG_FWRITE|CYG_FNONBLOCK|CYG_FAPPEND)
325
 
326
//-----------------------------------------------------------------------------
327
// Type of file
328
 
329
#define CYG_FILE_TYPE_FILE      1       /* file */
330
#define CYG_FILE_TYPE_SOCKET    2       /* communications endpoint */
331
#define CYG_FILE_TYPE_DEVICE    3       /* device */
332
 
333
//-----------------------------------------------------------------------------
334
// Keys for getinf() and setinfo()
335
 
336
#define FILE_INFO_CONF          1       /* fpathconf() */
337
 
338
//-----------------------------------------------------------------------------
339
// Modes for fsync()
340
 
341
#define CYG_FSYNC              1
342
#define CYG_FDATASYNC          2
343
 
344
//-----------------------------------------------------------------------------
345
// Get/set info buffer structures
346
 
347
// This is used for pathconf() and fpathconf()
348
struct cyg_pathconf_info
349
{
350
    int         name;           // POSIX defined variable name
351
    long        value;          // Returned variable value
352
};
353
 
354
//=============================================================================
355
// Synchronization modes
356
// These values are filled into the syncmode fields of the above structures
357
// and define the synchronization protocol used when accessing the object in
358
// question.
359
 
360
#define CYG_SYNCMODE_NONE               (0)     // no locking required
361
 
362
#define CYG_SYNCMODE_FILE_FILESYSTEM    0x0002  // lock fs during file ops
363
#define CYG_SYNCMODE_FILE_MOUNTPOINT    0x0004  // lock mte during file ops
364
#define CYG_SYNCMODE_IO_FILE            0x0010  // lock file during io ops
365
#define CYG_SYNCMODE_IO_FILESYSTEM      0x0020  // lock fs during io ops
366
#define CYG_SYNCMODE_IO_MOUNTPOINT      0x0040  // lock mte during io ops
367
#define CYG_SYNCMODE_SOCK_FILE          0x0100  // lock socket during socket ops
368
#define CYG_SYNCMODE_SOCK_NETSTACK      0x0800  // lock netstack during socket ops
369
 
370
#define CYG_SYNCMODE_IO_SHIFT           (4)     // shift for IO to file bits
371
#define CYG_SYNCMODE_SOCK_SHIFT         (8)     // shift for sock to file bits
372
 
373
//=============================================================================
374
// Mount and umount functions
375
 
376
__externC int mount( const char *devname,
377
                     const char *dir,
378
                     const char *fsname);
379
 
380
__externC int umount( const char *name);
381
 
382
//=============================================================================
383
// Select support
384
 
385
//-----------------------------------------------------------------------------
386
// Data structure for embedding in client data structures. A pointer to this
387
// must be passed to cyg_selrecord() and cyg_selwakeup().
388
 
389
struct CYG_SELINFO_TAG
390
{
391
    CYG_ADDRWORD        si_info;        // info passed through from fo_select()
392
    CYG_ADDRESS         si_thread;      // selecting thread pointer
393
};
394
 
395
//-----------------------------------------------------------------------------
396
// Select support functions.
397
 
398
// cyg_selinit() is used to initialize a selinfo structure.
399
__externC void cyg_selinit( struct CYG_SELINFO_TAG *sip );
400
 
401
// cyg_selrecord() is called when a client device needs to register
402
// the current thread for selection.
403
__externC void cyg_selrecord( CYG_ADDRWORD info, struct CYG_SELINFO_TAG *sip );
404
 
405
// cyg_selwakeup() is called when the client device matches the select
406
// criterion, and needs to wake up a selector.
407
__externC void cyg_selwakeup( struct CYG_SELINFO_TAG *sip );
408
 
409
//=============================================================================
410
// Timestamp support
411
 
412
// Provides the current time as a time_t timestamp for use in filesystem
413
// data strucures.
414
 
415
__externC time_t cyg_timestamp(void);
416
 
417
//=============================================================================
418
// Default functions.
419
// Cast to the appropriate type, these functions can be put into any of
420
// the operation table slots to provide the defined error code.
421
 
422
__externC int cyg_fileio_enosys(void);
423
__externC int cyg_fileio_erofs(void);
424
__externC int cyg_fileio_enoerr(void);
425
__externC int cyg_fileio_enotdir(void);
426
__externC cyg_fileop_select cyg_fileio_seltrue;
427
 
428
//-----------------------------------------------------------------------------
429
#endif // ifndef CYGONCE_FILEIO_H
430
// End of fileio.h

powered by: WebSVN 2.1.0

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