]> git.karo-electronics.de Git - karo-tx-redboot.git/blob - packages/io/fileio/v2_0/src/fio.h
Initial revision
[karo-tx-redboot.git] / packages / io / fileio / v2_0 / src / fio.h
1 #ifndef CYGONCE_FIO_H
2 #define CYGONCE_FIO_H
3 //=============================================================================
4 //
5 //      fio.h
6 //
7 //      Fileio private 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 // Copyright (C) 2002 Nick Garnett
15 //
16 // eCos is free software; you can redistribute it and/or modify it under
17 // the terms of the GNU General Public License as published by the Free
18 // Software Foundation; either version 2 or (at your option) any later version.
19 //
20 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
21 // 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 along
26 // with eCos; if not, write to the Free Software Foundation, Inc.,
27 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
28 //
29 // As a special exception, if other files instantiate templates or use macros
30 // or inline functions from this file, or you compile this file and link it
31 // with other works to produce a work based on this file, this file does not
32 // by itself cause the resulting work to be covered by the GNU General Public
33 // License. However the source code for this file must still be made available
34 // in accordance with section (3) of the GNU General Public License.
35 //
36 // This exception does not invalidate any other reasons why a work based on
37 // this file might be covered by the GNU General Public License.
38 //
39 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
40 // at http://sources.redhat.com/ecos/ecos-license/
41 // -------------------------------------------
42 //####ECOSGPLCOPYRIGHTEND####
43 //=============================================================================
44 //#####DESCRIPTIONBEGIN####
45 //
46 // Author(s):     nickg
47 // Contributors:  nickg
48 // Date:          2000-05-25
49 // Purpose:       Fileio private header
50 // Description:   This file contains private definitions for communication
51 //                between the parts of the fileio package.
52 //              
53 // Usage:
54 //              #include "fio.h"
55 //              ...
56 //              
57 //
58 //####DESCRIPTIONEND####
59 //
60 //=============================================================================
61
62 #include <pkgconf/hal.h>
63 #include <pkgconf/io_fileio.h>
64 #include <pkgconf/isoinfra.h>
65
66 #include <cyg/infra/cyg_type.h>
67
68 #include <stddef.h>             // NULL, size_t
69 #include <unistd.h>
70 #include <limits.h>
71 #include <sys/types.h>
72
73 #include <cyg/fileio/fileio.h>
74 #include <cyg/fileio/sockio.h>
75
76 #include <errno.h>
77
78 #ifdef CYGPKG_KERNEL
79 #include <pkgconf/kernel.h>
80 #include <cyg/kernel/mutex.hxx>        // mutex definitions
81
82 #define FILEIO_MUTEX_LOCK(_m_)   ((_m_).lock())
83 #define FILEIO_MUTEX_UNLOCK(_m_) ((_m_).unlock())
84
85 #else
86 #define FILEIO_MUTEX_LOCK(_m_) 
87 #define FILEIO_MUTEX_UNLOCK(_m_)
88 #endif
89
90
91 //=============================================================================
92 // POSIX API support
93
94 #ifdef CYGPKG_POSIX
95 #include <pkgconf/posix.h>
96 #include <cyg/posix/export.h>
97
98 #define CYG_FILEIO_FUNCTION_START() CYG_POSIX_FUNCTION_START()
99
100 #define CYG_FILEIO_FUNCTION_FINISH() CYG_POSIX_FUNCTION_FINISH()
101
102 #else
103
104 #define CYG_FILEIO_FUNCTION_START() CYG_EMPTY_STATEMENT
105
106 #define CYG_FILEIO_FUNCTION_FINISH() CYG_EMPTY_STATEMENT
107
108 #endif
109
110 #ifdef CYGPKG_POSIX_SIGNALS
111
112 #define CYG_FILEIO_SIGMASK_SET( __set, __oset ) \
113         CYG_PTHREAD_SIGMASK_SET( __set, __oset )
114
115 #define CYG_FILEIO_SIGPENDING() CYG_POSIX_SIGPENDING()
116
117 #define CYG_FILEIO_DELIVER_SIGNALS( __mask ) \
118         CYG_POSIX_DELIVER_SIGNALS( __mask )
119
120 #else
121
122 #define CYG_FILEIO_SIGMASK_SET( __set, __oset ) \
123 CYG_MACRO_START \
124 CYG_UNUSED_PARAM( const sigset_t*, __set ); \
125 CYG_UNUSED_PARAM( const sigset_t*, __oset ); \
126 CYG_MACRO_END
127
128 #define CYG_FILEIO_SIGPENDING() (0)
129
130 #define CYG_FILEIO_DELIVER_SIGNALS( __mask ) CYG_UNUSED_PARAM( const sigset_t*, __mask )
131
132 typedef int sigset_t;
133
134 #endif
135
136 //=============================================================================
137 // Fileio function entry and return macros.
138
139 // Handle entry to a fileio package function. 
140 #define FILEIO_ENTRY()                          \
141     CYG_REPORT_FUNCTYPE( "returning %d" );      \
142     CYG_FILEIO_FUNCTION_START();                \
143
144 // Do a fileio package defined return. This requires the error code
145 // to be placed in errno, and if it is non-zero, -1 returned as the
146 // result of the function. This also gives us a place to put any
147 // generic tidyup handling needed for things like signal delivery and
148 // cancellation.
149 #define FILEIO_RETURN(err)                      \
150 CYG_MACRO_START                                 \
151     int __retval = 0;                           \
152     CYG_FILEIO_FUNCTION_FINISH();               \
153     if( err != 0 ) __retval = -1, errno = err;  \
154     CYG_REPORT_RETVAL( __retval );              \
155     return __retval;                            \
156 CYG_MACRO_END
157
158 #define FILEIO_RETURN_VALUE(val)                \
159 CYG_MACRO_START                                 \
160     CYG_FILEIO_FUNCTION_FINISH();               \
161     CYG_REPORT_RETVAL( val );                   \
162     return val;                                 \
163 CYG_MACRO_END
164
165 #define FILEIO_RETURN_VOID()                    \
166 CYG_MACRO_START                                 \
167     CYG_FILEIO_FUNCTION_FINISH();               \
168     CYG_REPORT_RETURN();                        \
169     return;                                     \
170 CYG_MACRO_END
171
172 //=============================================================================
173 // Cancellation support
174 // If the POSIX package is present we want to include cancellation points
175 // in the routines that are defined to contain them.
176 // The macro CYG_CANCELLATION_POINT does this.
177
178 #ifdef CYGINT_ISO_PTHREAD_IMPL
179
180 # include <pthread.h>
181
182 # define CYG_CANCELLATION_POINT pthread_testcancel()
183
184 #else
185
186 # define CYG_CANCELLATION_POINT CYG_EMPTY_STATEMENT
187
188 #endif
189
190 //=============================================================================
191 // Internal exports
192
193 //-----------------------------------------------------------------------------
194 // Exports from misc.cxx
195
196 // Current directory info
197 __externC cyg_mtab_entry *cyg_cdir_mtab_entry;
198 __externC cyg_dir cyg_cdir_dir;
199
200 __externC int cyg_mtab_lookup( cyg_dir *dir, const char **name, cyg_mtab_entry **mte);
201
202 //-----------------------------------------------------------------------------
203 // Exports from fd.cxx
204
205 __externC void cyg_fd_init();
206
207 __externC cyg_file *cyg_file_alloc();
208
209 __externC void cyg_file_free(cyg_file * fp);
210
211 __externC int cyg_fd_alloc(int low);
212
213 __externC void cyg_fd_assign(int fd, cyg_file *fp);
214
215 __externC int cyg_fd_free(int fd);
216
217 __externC cyg_file *cyg_fp_get( int fd );
218
219 __externC void cyg_fp_free( cyg_file *fp );
220
221 __externC void cyg_file_lock( cyg_file *fp, cyg_uint32 syncmode );
222
223 __externC void cyg_file_unlock( cyg_file *fp, cyg_uint32 syncmode );
224
225 //-----------------------------------------------------------------------------
226 // Exports from socket.cxx
227
228 __externC void cyg_nstab_init();
229
230 //-----------------------------------------------------------------------------
231 #endif // ifndef CYGONCE_FIO_H
232 // End of fio.h