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