1 | /* |
---|
2 | * @file rtems/libio_.h |
---|
3 | */ |
---|
4 | |
---|
5 | /* |
---|
6 | * Libio Internal Information |
---|
7 | * |
---|
8 | * COPYRIGHT (c) 1989-1999. |
---|
9 | * On-Line Applications Research Corporation (OAR). |
---|
10 | * |
---|
11 | * The license and distribution terms for this file may be |
---|
12 | * found in the file LICENSE in this distribution or at |
---|
13 | * http://www.rtems.com/license/LICENSE. |
---|
14 | * |
---|
15 | * $Id$ |
---|
16 | */ |
---|
17 | |
---|
18 | #ifndef _RTEMS_RTEMS_LIBIO__H |
---|
19 | #define _RTEMS_RTEMS_LIBIO__H |
---|
20 | |
---|
21 | #include <rtems.h> |
---|
22 | #include <rtems/libio.h> /* include before standard IO */ |
---|
23 | |
---|
24 | #include <sys/types.h> |
---|
25 | |
---|
26 | #include <errno.h> |
---|
27 | |
---|
28 | #ifdef __cplusplus |
---|
29 | extern "C" { |
---|
30 | #endif |
---|
31 | |
---|
32 | /* |
---|
33 | * Semaphore to protect the io table |
---|
34 | */ |
---|
35 | |
---|
36 | #define RTEMS_LIBIO_SEM rtems_build_name('L', 'B', 'I', 'O') |
---|
37 | #define RTEMS_LIBIO_IOP_SEM(n) rtems_build_name('L', 'B', 'I', n) |
---|
38 | |
---|
39 | extern rtems_id rtems_libio_semaphore; |
---|
40 | extern const rtems_filesystem_file_handlers_r rtems_filesystem_null_handlers; |
---|
41 | |
---|
42 | /* |
---|
43 | * Mount table list. |
---|
44 | */ |
---|
45 | extern rtems_chain_control rtems_filesystem_mount_table_control; |
---|
46 | |
---|
47 | /* |
---|
48 | * File descriptor Table Information |
---|
49 | */ |
---|
50 | |
---|
51 | extern uint32_t rtems_libio_number_iops; |
---|
52 | extern rtems_libio_t *rtems_libio_iops; |
---|
53 | extern rtems_libio_t *rtems_libio_last_iop; |
---|
54 | extern rtems_libio_t *rtems_libio_iop_freelist; |
---|
55 | |
---|
56 | /* |
---|
57 | * rtems_libio_iop |
---|
58 | * |
---|
59 | * Macro to return the file descriptor pointer. |
---|
60 | */ |
---|
61 | |
---|
62 | #define rtems_libio_iop(_fd) \ |
---|
63 | ((((uint32_t)(_fd)) < rtems_libio_number_iops) ? \ |
---|
64 | &rtems_libio_iops[_fd] : 0) |
---|
65 | |
---|
66 | /* |
---|
67 | * rtems_libio_iop_to_descriptor |
---|
68 | * |
---|
69 | * Macro to convert an internal file descriptor pointer (iop) into |
---|
70 | * the integer file descriptor used by the "section 2" system calls. |
---|
71 | */ |
---|
72 | |
---|
73 | #define rtems_libio_iop_to_descriptor(_iop) \ |
---|
74 | ((!(_iop)) ? -1 : (_iop - rtems_libio_iops)) |
---|
75 | |
---|
76 | /* |
---|
77 | * rtems_libio_check_is_open |
---|
78 | * |
---|
79 | * Macro to check if a file descriptor is actually open. |
---|
80 | */ |
---|
81 | |
---|
82 | #define rtems_libio_check_is_open(_iop) \ |
---|
83 | do { \ |
---|
84 | if (((_iop)->flags & LIBIO_FLAGS_OPEN) == 0) { \ |
---|
85 | errno = EBADF; \ |
---|
86 | return -1; \ |
---|
87 | } \ |
---|
88 | } while (0) |
---|
89 | |
---|
90 | /* |
---|
91 | * rtems_libio_check_fd |
---|
92 | * |
---|
93 | * Macro to check if a file descriptor number is valid. |
---|
94 | */ |
---|
95 | |
---|
96 | #define rtems_libio_check_fd(_fd) \ |
---|
97 | do { \ |
---|
98 | if ((uint32_t) (_fd) >= rtems_libio_number_iops) { \ |
---|
99 | errno = EBADF; \ |
---|
100 | return -1; \ |
---|
101 | } \ |
---|
102 | } while (0) |
---|
103 | |
---|
104 | /* |
---|
105 | * rtems_libio_check_buffer |
---|
106 | * |
---|
107 | * Macro to check if a buffer pointer is valid. |
---|
108 | */ |
---|
109 | |
---|
110 | #define rtems_libio_check_buffer(_buffer) \ |
---|
111 | do { \ |
---|
112 | if ((_buffer) == 0) { \ |
---|
113 | errno = EINVAL; \ |
---|
114 | return -1; \ |
---|
115 | } \ |
---|
116 | } while (0) |
---|
117 | |
---|
118 | /* |
---|
119 | * rtems_libio_check_count |
---|
120 | * |
---|
121 | * Macro to check if a count or length is valid. |
---|
122 | */ |
---|
123 | |
---|
124 | #define rtems_libio_check_count(_count) \ |
---|
125 | do { \ |
---|
126 | if ((_count) == 0) { \ |
---|
127 | return 0; \ |
---|
128 | } \ |
---|
129 | } while (0) |
---|
130 | |
---|
131 | /* |
---|
132 | * rtems_libio_check_permissions |
---|
133 | * |
---|
134 | * Macro to check if a file descriptor is open for this operation. |
---|
135 | */ |
---|
136 | |
---|
137 | #define rtems_libio_check_permissions(_iop, _flag) \ |
---|
138 | do { \ |
---|
139 | if (((_iop)->flags & (_flag)) == 0) { \ |
---|
140 | rtems_set_errno_and_return_minus_one( EINVAL ); \ |
---|
141 | return -1; \ |
---|
142 | } \ |
---|
143 | } while (0) |
---|
144 | |
---|
145 | /* |
---|
146 | * rtems_filesystem_freenode |
---|
147 | * |
---|
148 | * Macro to free a node. |
---|
149 | */ |
---|
150 | |
---|
151 | #define rtems_filesystem_freenode( _node ) \ |
---|
152 | do { \ |
---|
153 | if ( (_node)->ops )\ |
---|
154 | if ( (_node)->ops->freenod_h ) \ |
---|
155 | (*(_node)->ops->freenod_h)( (_node) ); \ |
---|
156 | } while (0) |
---|
157 | |
---|
158 | |
---|
159 | /* |
---|
160 | * External structures |
---|
161 | */ |
---|
162 | #include <rtems/userenv.h> |
---|
163 | |
---|
164 | extern rtems_user_env_t * rtems_current_user_env; |
---|
165 | extern rtems_user_env_t rtems_global_user_env; |
---|
166 | |
---|
167 | /* |
---|
168 | * Instantiate a private copy of the per user information for the calling task. |
---|
169 | */ |
---|
170 | |
---|
171 | rtems_status_code rtems_libio_set_private_env(void); |
---|
172 | rtems_status_code rtems_libio_share_private_env(rtems_id task_id) ; |
---|
173 | |
---|
174 | static inline void rtems_libio_lock( void ) |
---|
175 | { |
---|
176 | rtems_semaphore_obtain( rtems_libio_semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT ); |
---|
177 | } |
---|
178 | |
---|
179 | static inline void rtems_libio_unlock( void ) |
---|
180 | { |
---|
181 | rtems_semaphore_release( rtems_libio_semaphore ); |
---|
182 | } |
---|
183 | |
---|
184 | /* |
---|
185 | * File Descriptor Routine Prototypes |
---|
186 | */ |
---|
187 | |
---|
188 | rtems_libio_t *rtems_libio_allocate(void); |
---|
189 | |
---|
190 | uint32_t rtems_libio_fcntl_flags( |
---|
191 | uint32_t fcntl_flags |
---|
192 | ); |
---|
193 | |
---|
194 | uint32_t rtems_libio_to_fcntl_flags( |
---|
195 | uint32_t flags |
---|
196 | ); |
---|
197 | |
---|
198 | void rtems_libio_free( |
---|
199 | rtems_libio_t *iop |
---|
200 | ); |
---|
201 | |
---|
202 | int rtems_libio_is_open_files_in_fs( |
---|
203 | rtems_filesystem_mount_table_entry_t *mt_entry |
---|
204 | ); |
---|
205 | |
---|
206 | int rtems_libio_is_file_open( |
---|
207 | void *node_access |
---|
208 | ); |
---|
209 | |
---|
210 | /* |
---|
211 | * File System Routine Prototypes |
---|
212 | */ |
---|
213 | |
---|
214 | int rtems_filesystem_evaluate_relative_path( |
---|
215 | const char *pathname, |
---|
216 | size_t pathnamelen, |
---|
217 | int flags, |
---|
218 | rtems_filesystem_location_info_t *pathloc, |
---|
219 | int follow_link |
---|
220 | ); |
---|
221 | |
---|
222 | int rtems_filesystem_evaluate_path( |
---|
223 | const char *pathname, |
---|
224 | size_t pathnamelen, |
---|
225 | int flags, |
---|
226 | rtems_filesystem_location_info_t *pathloc, |
---|
227 | int follow_link |
---|
228 | ); |
---|
229 | |
---|
230 | int rtems_filesystem_dirname( |
---|
231 | const char *pathname |
---|
232 | ); |
---|
233 | |
---|
234 | int rtems_filesystem_prefix_separators( |
---|
235 | const char *pathname, |
---|
236 | int pathnamelen |
---|
237 | ); |
---|
238 | |
---|
239 | void rtems_filesystem_initialize(void); |
---|
240 | |
---|
241 | int init_fs_mount_table(void); |
---|
242 | |
---|
243 | int rtems_filesystem_is_separator(char ch); |
---|
244 | |
---|
245 | void rtems_filesystem_get_start_loc(const char *path, |
---|
246 | int *index, |
---|
247 | rtems_filesystem_location_info_t *loc); |
---|
248 | |
---|
249 | void rtems_filesystem_get_sym_start_loc(const char *path, |
---|
250 | int *index, |
---|
251 | rtems_filesystem_location_info_t *loc); |
---|
252 | |
---|
253 | #ifdef __cplusplus |
---|
254 | } |
---|
255 | #endif |
---|
256 | |
---|
257 | #endif |
---|
258 | /* end of include file */ |
---|