1 | /* |
---|
2 | * Libio Internal Information |
---|
3 | * |
---|
4 | * COPYRIGHT (c) 1989-1998. |
---|
5 | * On-Line Applications Research Corporation (OAR). |
---|
6 | * Copyright assigned to U.S. Government, 1994. |
---|
7 | * |
---|
8 | * The license and distribution terms for this file may be |
---|
9 | * found in the file LICENSE in this distribution or at |
---|
10 | * http://www.OARcorp.com/rtems/license.html. |
---|
11 | * |
---|
12 | * $Id$ |
---|
13 | */ |
---|
14 | |
---|
15 | #ifndef __LIBIO__h |
---|
16 | #define __LIBIO__h |
---|
17 | |
---|
18 | #ifdef __cplusplus |
---|
19 | extern "C" { |
---|
20 | #endif |
---|
21 | |
---|
22 | #include <rtems.h> |
---|
23 | #include <rtems/assoc.h> /* assoc.h not included by rtems.h */ |
---|
24 | #include <rtems/libio.h> |
---|
25 | |
---|
26 | #include <stdio.h> /* O_RDONLY, et.al. */ |
---|
27 | #include <fcntl.h> /* O_RDONLY, et.al. */ |
---|
28 | #include <assert.h> |
---|
29 | #include <stdarg.h> |
---|
30 | #include <errno.h> |
---|
31 | |
---|
32 | #if ! defined(O_NDELAY) |
---|
33 | # if defined(solaris2) |
---|
34 | # define O_NDELAY O_NONBLOCK |
---|
35 | # elif defined(RTEMS_NEWLIB) |
---|
36 | # define O_NDELAY _FNBIO |
---|
37 | # endif |
---|
38 | #endif |
---|
39 | |
---|
40 | #if !defined(ENOTSUP) |
---|
41 | #define ENOTSUP EOPNOTSUPP |
---|
42 | #endif |
---|
43 | |
---|
44 | #include <errno.h> |
---|
45 | #include <string.h> /* strcmp */ |
---|
46 | #include <unistd.h> |
---|
47 | #include <stdlib.h> /* calloc() */ |
---|
48 | |
---|
49 | #include "libio.h" /* libio.h not pulled in by rtems */ |
---|
50 | |
---|
51 | |
---|
52 | /* |
---|
53 | * Semaphore to protect the io table |
---|
54 | */ |
---|
55 | |
---|
56 | #define RTEMS_LIBIO_SEM rtems_build_name('L', 'B', 'I', 'O') |
---|
57 | #define RTEMS_LIBIO_IOP_SEM(n) rtems_build_name('L', 'B', 'I', n) |
---|
58 | |
---|
59 | extern rtems_id rtems_libio_semaphore; |
---|
60 | |
---|
61 | /* |
---|
62 | * File descriptor Table Information |
---|
63 | */ |
---|
64 | |
---|
65 | extern unsigned32 rtems_libio_number_iops; |
---|
66 | extern rtems_libio_t *rtems_libio_iops; |
---|
67 | extern rtems_libio_t *rtems_libio_last_iop; |
---|
68 | extern rtems_libio_t *rtems_libio_iop_freelist; |
---|
69 | |
---|
70 | /* |
---|
71 | * External I/O Handlers Table |
---|
72 | * |
---|
73 | * Space for all possible handlers is preallocated |
---|
74 | * to speed up dispatch to external handlers. |
---|
75 | */ |
---|
76 | |
---|
77 | extern rtems_libio_handler_t rtems_libio_handlers[15]; |
---|
78 | |
---|
79 | /* |
---|
80 | * Default mode for all files. |
---|
81 | */ |
---|
82 | |
---|
83 | extern mode_t rtems_filesystem_umask; |
---|
84 | |
---|
85 | /* |
---|
86 | * set_errno_and_return_minus_one |
---|
87 | * |
---|
88 | * Macro to ease common way to return an error. |
---|
89 | */ |
---|
90 | |
---|
91 | #ifndef set_errno_and_return_minus_one |
---|
92 | #define set_errno_and_return_minus_one( _error ) \ |
---|
93 | do { errno = (_error); return -1; } while(0) |
---|
94 | #endif |
---|
95 | |
---|
96 | /* |
---|
97 | * rtems_libio_iop |
---|
98 | * |
---|
99 | * Macro to return the file descriptor pointer. |
---|
100 | */ |
---|
101 | |
---|
102 | #define rtems_libio_iop(_fd) \ |
---|
103 | ((((unsigned32)(_fd)) < rtems_libio_number_iops) ? \ |
---|
104 | &rtems_libio_iops[_fd] : 0) |
---|
105 | |
---|
106 | /* |
---|
107 | * rtems_libio_check_fd |
---|
108 | * |
---|
109 | * Macro to check if a file descriptor number is valid. |
---|
110 | */ |
---|
111 | |
---|
112 | #define rtems_libio_check_fd(_fd) \ |
---|
113 | do { \ |
---|
114 | if ((unsigned32) (_fd) >= rtems_libio_number_iops) { \ |
---|
115 | errno = EBADF; \ |
---|
116 | return -1; \ |
---|
117 | } \ |
---|
118 | } while (0) |
---|
119 | |
---|
120 | /* |
---|
121 | * rtems_libio_check_fd |
---|
122 | * |
---|
123 | * Macro to check if a buffer pointer is valid. |
---|
124 | */ |
---|
125 | |
---|
126 | #define rtems_libio_check_buffer(_buffer) \ |
---|
127 | do { \ |
---|
128 | if ((_buffer) == 0) { \ |
---|
129 | errno = EINVAL; \ |
---|
130 | return -1; \ |
---|
131 | } \ |
---|
132 | } while (0) |
---|
133 | |
---|
134 | /* |
---|
135 | * rtems_libio_check_count |
---|
136 | * |
---|
137 | * Macro to check if a count or length is valid. |
---|
138 | */ |
---|
139 | |
---|
140 | #define rtems_libio_check_count(_count) \ |
---|
141 | do { \ |
---|
142 | if ((_count) == 0) { \ |
---|
143 | return 0; \ |
---|
144 | } \ |
---|
145 | } while (0) |
---|
146 | |
---|
147 | /* |
---|
148 | * rtems_libio_check_permissions |
---|
149 | * |
---|
150 | * Macro to check if a file descriptor is open for this operation. |
---|
151 | */ |
---|
152 | |
---|
153 | #define rtems_libio_check_permissions(_iop, _flag) \ |
---|
154 | do { \ |
---|
155 | if (((_iop)->flags & (_flag)) == 0) { \ |
---|
156 | set_errno_and_return_minus_one( EINVAL ); \ |
---|
157 | return -1; \ |
---|
158 | } \ |
---|
159 | } while (0) |
---|
160 | |
---|
161 | /* |
---|
162 | * rtems_filesystem_is_separator |
---|
163 | * |
---|
164 | * Macro to determine if a character is a path name separator. |
---|
165 | * |
---|
166 | * NOTE: This macro handles MS-DOS and UNIX style names. |
---|
167 | */ |
---|
168 | |
---|
169 | #define rtems_filesystem_is_separator( _ch ) \ |
---|
170 | ( ((_ch) == '/') || ((_ch) == '\\') || ((_ch) == '\0')) |
---|
171 | |
---|
172 | /* |
---|
173 | * rtems_filesystem_get_start_loc |
---|
174 | * |
---|
175 | * Macro to determine if path is absolute or relative. |
---|
176 | */ |
---|
177 | |
---|
178 | #define rtems_filesystem_get_start_loc( _path, _index, _loc ) \ |
---|
179 | do { \ |
---|
180 | if ( rtems_filesystem_is_separator( (_path)[ 0 ] ) ) { \ |
---|
181 | *(_loc) = rtems_filesystem_root; \ |
---|
182 | *(_index) = 1; \ |
---|
183 | } else { \ |
---|
184 | *(_loc) = rtems_filesystem_current; \ |
---|
185 | *(_index) = 0; \ |
---|
186 | } \ |
---|
187 | } while (0) |
---|
188 | |
---|
189 | #define rtems_filesystem_get_sym_start_loc( _path, _index, _loc ) \ |
---|
190 | do { \ |
---|
191 | if ( rtems_filesystem_is_separator( (_path)[ 0 ] ) ) { \ |
---|
192 | *(_loc) = rtems_filesystem_root; \ |
---|
193 | *(_index) = 1; \ |
---|
194 | } else { \ |
---|
195 | *(_index) = 0; \ |
---|
196 | } \ |
---|
197 | } while (0) |
---|
198 | |
---|
199 | |
---|
200 | /* |
---|
201 | * External structures |
---|
202 | */ |
---|
203 | |
---|
204 | extern rtems_filesystem_location_info_t rtems_filesystem_current; |
---|
205 | extern rtems_filesystem_location_info_t rtems_filesystem_root; |
---|
206 | extern nlink_t rtems_filesystem_link_counts; |
---|
207 | |
---|
208 | |
---|
209 | /* |
---|
210 | * File Descriptor Routine Prototypes |
---|
211 | */ |
---|
212 | |
---|
213 | rtems_libio_t *rtems_libio_allocate(void); |
---|
214 | |
---|
215 | unsigned32 rtems_libio_fcntl_flags( |
---|
216 | unsigned32 fcntl_flags |
---|
217 | ); |
---|
218 | |
---|
219 | void rtems_libio_free( |
---|
220 | rtems_libio_t *iop |
---|
221 | ); |
---|
222 | |
---|
223 | int rtems_libio_is_open_files_in_fs( |
---|
224 | rtems_filesystem_mount_table_entry_t *mt_entry |
---|
225 | ); |
---|
226 | |
---|
227 | int rtems_libio_is_file_open( |
---|
228 | void *node_access |
---|
229 | ); |
---|
230 | |
---|
231 | /* |
---|
232 | * File System Routine Prototypes |
---|
233 | */ |
---|
234 | |
---|
235 | int rtems_filesystem_evaluate_path( |
---|
236 | const char *pathname, |
---|
237 | int flags, |
---|
238 | rtems_filesystem_location_info_t *pathloc, |
---|
239 | int follow_link |
---|
240 | ); |
---|
241 | |
---|
242 | void rtems_filesystem_initialize(); |
---|
243 | |
---|
244 | int init_fs_mount_table(); |
---|
245 | |
---|
246 | #ifdef __cplusplus |
---|
247 | } |
---|
248 | #endif |
---|
249 | |
---|
250 | #endif |
---|
251 | /* end of include file */ |
---|
252 | |
---|
253 | |
---|
254 | |
---|