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