source:
rtems/cpukit/libcsupport/include/rtems/libio_.h
@
8638d32b
Last change on this file since 8638d32b was 8638d32b, checked in by Joel Sherrill <joel.sherrill@…>, on 09/04/03 at 18:46:59 | |
---|---|
|
|
File size: 6.2 KB |
Rev | Line | |
---|---|---|
[07a3253d] | 1 | /* |
2 | * Libio Internal Information | |
3 | * | |
[08311cc3] | 4 | * COPYRIGHT (c) 1989-1999. |
[07a3253d] | 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 | |
[8638d32b] | 9 | * http://www.rtems.com/license/LICENSE. |
[07a3253d] | 10 | * |
11 | * $Id$ | |
12 | */ | |
13 | ||
[3ba74c73] | 14 | #ifndef __RTEMS_LIBIO_INTERNAL__h |
15 | #define __RTEMS_LIBIO_INTERNAL__h | |
[07a3253d] | 16 | |
17 | #ifdef __cplusplus | |
18 | extern "C" { | |
19 | #endif | |
20 | ||
21 | #include <rtems.h> | |
[23c4bbf5] | 22 | #include <rtems/libio.h> /* include before standard IO */ |
[07a3253d] | 23 | |
[87fb080d] | 24 | #include <sys/types.h> |
[7a3878b] | 25 | |
[07a3253d] | 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 | ||
[51435fc7] | 35 | extern rtems_id rtems_libio_semaphore; |
36 | extern rtems_filesystem_file_handlers_r rtems_filesystem_null_handlers; | |
[07a3253d] | 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; | |
[cca4400] | 45 | extern rtems_libio_t *rtems_libio_iop_freelist; |
[07a3253d] | 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 | ||
[2d733c42] | 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 | ||
[07a3253d] | 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 | /* | |
[2d733c42] | 86 | * rtems_libio_check_buffer |
[07a3253d] | 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) { \ | |
[a02224e] | 121 | rtems_set_errno_and_return_minus_one( EINVAL ); \ |
[07a3253d] | 122 | return -1; \ |
123 | } \ | |
124 | } while (0) | |
125 | ||
[dd0f326] | 126 | /* |
127 | * rtems_filesystem_freenode | |
128 | * | |
129 | * Macro to free a node. | |
130 | */ | |
131 | ||
132 | #define rtems_filesystem_freenode( _node ) \ | |
133 | do { \ | |
[1af79634] | 134 | if ( (_node)->ops )\ |
135 | if ( (_node)->ops->freenod_h ) \ | |
136 | (*(_node)->ops->freenod_h)( (_node) ); \ | |
[dd0f326] | 137 | } while (0) |
138 | ||
[07a3253d] | 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 | */ | |
[d09ad1f0] | 181 | #include <rtems/userenv.h> |
[2a929cc] | 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 | */ | |
[07a3253d] | 189 | |
[2a929cc] | 190 | rtems_status_code rtems_libio_set_private_env(void); |
[d8a9155] | 191 | rtems_status_code rtems_libio_share_private_env(rtems_id task_id) ; |
192 | ||
[07a3253d] | 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 | ||
[3ef8798] | 203 | unsigned32 rtems_libio_to_fcntl_flags( |
204 | unsigned32 flags | |
205 | ); | |
206 | ||
[07a3253d] | 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 */ |
Note: See TracBrowser
for help on using the repository browser.