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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [io/] [fileio/] [current/] [include/] [fileio.h] - Blame information for rev 838

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

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

powered by: WebSVN 2.1.0

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