[4d3017a] | 1 | /** |
---|
| 2 | * @file rtems/libio_.h |
---|
| 3 | */ |
---|
| 4 | |
---|
[07a3253d] | 5 | /* |
---|
| 6 | * Libio Internal Information |
---|
| 7 | * |
---|
[08311cc3] | 8 | * COPYRIGHT (c) 1989-1999. |
---|
[07a3253d] | 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 |
---|
[0eae36c7] | 13 | * http://www.rtems.com/license/LICENSE. |
---|
[07a3253d] | 14 | * |
---|
| 15 | * $Id$ |
---|
| 16 | */ |
---|
| 17 | |
---|
[3ba74c73] | 18 | #ifndef __RTEMS_LIBIO_INTERNAL__h |
---|
| 19 | #define __RTEMS_LIBIO_INTERNAL__h |
---|
[07a3253d] | 20 | |
---|
| 21 | #ifdef __cplusplus |
---|
| 22 | extern "C" { |
---|
| 23 | #endif |
---|
| 24 | |
---|
| 25 | #include <rtems.h> |
---|
[23c4bbf5] | 26 | #include <rtems/libio.h> /* include before standard IO */ |
---|
[07a3253d] | 27 | |
---|
[50f32b11] | 28 | #include <sys/types.h> |
---|
[7a3878b] | 29 | |
---|
[07a3253d] | 30 | #include <errno.h> |
---|
| 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 | |
---|
[51435fc7] | 39 | extern rtems_id rtems_libio_semaphore; |
---|
| 40 | extern rtems_filesystem_file_handlers_r rtems_filesystem_null_handlers; |
---|
[07a3253d] | 41 | |
---|
| 42 | /* |
---|
| 43 | * File descriptor Table Information |
---|
| 44 | */ |
---|
| 45 | |
---|
[83c5fc1] | 46 | extern uint32_t rtems_libio_number_iops; |
---|
[07a3253d] | 47 | extern rtems_libio_t *rtems_libio_iops; |
---|
| 48 | extern rtems_libio_t *rtems_libio_last_iop; |
---|
[cca4400] | 49 | extern rtems_libio_t *rtems_libio_iop_freelist; |
---|
[07a3253d] | 50 | |
---|
| 51 | /* |
---|
| 52 | * rtems_libio_iop |
---|
| 53 | * |
---|
| 54 | * Macro to return the file descriptor pointer. |
---|
| 55 | */ |
---|
| 56 | |
---|
| 57 | #define rtems_libio_iop(_fd) \ |
---|
[83c5fc1] | 58 | ((((uint32_t )(_fd)) < rtems_libio_number_iops) ? \ |
---|
[07a3253d] | 59 | &rtems_libio_iops[_fd] : 0) |
---|
| 60 | |
---|
[de2ee43d] | 61 | /* |
---|
| 62 | * rtems_libio_iop_to_descriptor |
---|
| 63 | * |
---|
| 64 | * Macro to convert an internal file descriptor pointer (iop) into |
---|
| 65 | * the integer file descriptor used by the "section 2" system calls. |
---|
| 66 | */ |
---|
| 67 | |
---|
| 68 | #define rtems_libio_iop_to_descriptor(_iop) \ |
---|
| 69 | ((!(_iop)) ? -1 : (_iop - rtems_libio_iops)) |
---|
| 70 | |
---|
[50f32b11] | 71 | /* |
---|
[2d733c42] | 72 | * rtems_libio_check_is_open |
---|
[50f32b11] | 73 | * |
---|
[2d733c42] | 74 | * Macro to check if a file descriptor is actually open. |
---|
| 75 | */ |
---|
| 76 | |
---|
| 77 | #define rtems_libio_check_is_open(_iop) \ |
---|
| 78 | do { \ |
---|
| 79 | if (((_iop)->flags & LIBIO_FLAGS_OPEN) == 0) { \ |
---|
| 80 | errno = EBADF; \ |
---|
| 81 | return -1; \ |
---|
| 82 | } \ |
---|
| 83 | } while (0) |
---|
| 84 | |
---|
[07a3253d] | 85 | /* |
---|
| 86 | * rtems_libio_check_fd |
---|
| 87 | * |
---|
| 88 | * Macro to check if a file descriptor number is valid. |
---|
| 89 | */ |
---|
| 90 | |
---|
| 91 | #define rtems_libio_check_fd(_fd) \ |
---|
| 92 | do { \ |
---|
[83c5fc1] | 93 | if ((uint32_t ) (_fd) >= rtems_libio_number_iops) { \ |
---|
[07a3253d] | 94 | errno = EBADF; \ |
---|
| 95 | return -1; \ |
---|
| 96 | } \ |
---|
| 97 | } while (0) |
---|
| 98 | |
---|
| 99 | /* |
---|
[2d733c42] | 100 | * rtems_libio_check_buffer |
---|
[07a3253d] | 101 | * |
---|
| 102 | * Macro to check if a buffer pointer is valid. |
---|
| 103 | */ |
---|
| 104 | |
---|
| 105 | #define rtems_libio_check_buffer(_buffer) \ |
---|
| 106 | do { \ |
---|
| 107 | if ((_buffer) == 0) { \ |
---|
| 108 | errno = EINVAL; \ |
---|
| 109 | return -1; \ |
---|
| 110 | } \ |
---|
| 111 | } while (0) |
---|
| 112 | |
---|
| 113 | /* |
---|
| 114 | * rtems_libio_check_count |
---|
| 115 | * |
---|
| 116 | * Macro to check if a count or length is valid. |
---|
| 117 | */ |
---|
| 118 | |
---|
| 119 | #define rtems_libio_check_count(_count) \ |
---|
| 120 | do { \ |
---|
| 121 | if ((_count) == 0) { \ |
---|
| 122 | return 0; \ |
---|
| 123 | } \ |
---|
| 124 | } while (0) |
---|
| 125 | |
---|
| 126 | /* |
---|
| 127 | * rtems_libio_check_permissions |
---|
| 128 | * |
---|
| 129 | * Macro to check if a file descriptor is open for this operation. |
---|
| 130 | */ |
---|
| 131 | |
---|
| 132 | #define rtems_libio_check_permissions(_iop, _flag) \ |
---|
| 133 | do { \ |
---|
| 134 | if (((_iop)->flags & (_flag)) == 0) { \ |
---|
[a02224e] | 135 | rtems_set_errno_and_return_minus_one( EINVAL ); \ |
---|
[07a3253d] | 136 | return -1; \ |
---|
| 137 | } \ |
---|
| 138 | } while (0) |
---|
| 139 | |
---|
[dd0f326] | 140 | /* |
---|
| 141 | * rtems_filesystem_freenode |
---|
| 142 | * |
---|
| 143 | * Macro to free a node. |
---|
| 144 | */ |
---|
| 145 | |
---|
| 146 | #define rtems_filesystem_freenode( _node ) \ |
---|
| 147 | do { \ |
---|
[1af79634] | 148 | if ( (_node)->ops )\ |
---|
| 149 | if ( (_node)->ops->freenod_h ) \ |
---|
| 150 | (*(_node)->ops->freenod_h)( (_node) ); \ |
---|
[dd0f326] | 151 | } while (0) |
---|
| 152 | |
---|
[07a3253d] | 153 | /* |
---|
| 154 | * rtems_filesystem_is_separator |
---|
| 155 | * |
---|
| 156 | * Macro to determine if a character is a path name separator. |
---|
| 157 | * |
---|
| 158 | * NOTE: This macro handles MS-DOS and UNIX style names. |
---|
| 159 | */ |
---|
| 160 | |
---|
| 161 | #define rtems_filesystem_is_separator( _ch ) \ |
---|
| 162 | ( ((_ch) == '/') || ((_ch) == '\\') || ((_ch) == '\0')) |
---|
| 163 | |
---|
| 164 | /* |
---|
| 165 | * rtems_filesystem_get_start_loc |
---|
| 166 | * |
---|
| 167 | * Macro to determine if path is absolute or relative. |
---|
| 168 | */ |
---|
| 169 | |
---|
| 170 | #define rtems_filesystem_get_start_loc( _path, _index, _loc ) \ |
---|
| 171 | do { \ |
---|
| 172 | if ( rtems_filesystem_is_separator( (_path)[ 0 ] ) ) { \ |
---|
| 173 | *(_loc) = rtems_filesystem_root; \ |
---|
| 174 | *(_index) = 1; \ |
---|
| 175 | } else { \ |
---|
| 176 | *(_loc) = rtems_filesystem_current; \ |
---|
| 177 | *(_index) = 0; \ |
---|
| 178 | } \ |
---|
| 179 | } while (0) |
---|
| 180 | |
---|
| 181 | #define rtems_filesystem_get_sym_start_loc( _path, _index, _loc ) \ |
---|
| 182 | do { \ |
---|
| 183 | if ( rtems_filesystem_is_separator( (_path)[ 0 ] ) ) { \ |
---|
| 184 | *(_loc) = rtems_filesystem_root; \ |
---|
| 185 | *(_index) = 1; \ |
---|
| 186 | } else { \ |
---|
| 187 | *(_index) = 0; \ |
---|
| 188 | } \ |
---|
| 189 | } while (0) |
---|
| 190 | |
---|
| 191 | |
---|
| 192 | /* |
---|
| 193 | * External structures |
---|
| 194 | */ |
---|
[d09ad1f0] | 195 | #include <rtems/userenv.h> |
---|
[2a929cc] | 196 | |
---|
[50f32b11] | 197 | extern rtems_user_env_t * rtems_current_user_env; |
---|
| 198 | extern rtems_user_env_t rtems_global_user_env; |
---|
[2a929cc] | 199 | |
---|
| 200 | /* |
---|
| 201 | * Instantiate a private copy of the per user information for the calling task. |
---|
| 202 | */ |
---|
[07a3253d] | 203 | |
---|
[2a929cc] | 204 | rtems_status_code rtems_libio_set_private_env(void); |
---|
[d8a9155] | 205 | rtems_status_code rtems_libio_share_private_env(rtems_id task_id) ; |
---|
[50f32b11] | 206 | |
---|
[07a3253d] | 207 | /* |
---|
| 208 | * File Descriptor Routine Prototypes |
---|
| 209 | */ |
---|
| 210 | |
---|
| 211 | rtems_libio_t *rtems_libio_allocate(void); |
---|
| 212 | |
---|
[83c5fc1] | 213 | uint32_t rtems_libio_fcntl_flags( |
---|
| 214 | uint32_t fcntl_flags |
---|
[07a3253d] | 215 | ); |
---|
| 216 | |
---|
[83c5fc1] | 217 | uint32_t rtems_libio_to_fcntl_flags( |
---|
| 218 | uint32_t flags |
---|
[3ef8798] | 219 | ); |
---|
| 220 | |
---|
[07a3253d] | 221 | void rtems_libio_free( |
---|
| 222 | rtems_libio_t *iop |
---|
| 223 | ); |
---|
| 224 | |
---|
| 225 | int rtems_libio_is_open_files_in_fs( |
---|
| 226 | rtems_filesystem_mount_table_entry_t *mt_entry |
---|
| 227 | ); |
---|
| 228 | |
---|
| 229 | int rtems_libio_is_file_open( |
---|
| 230 | void *node_access |
---|
| 231 | ); |
---|
| 232 | |
---|
| 233 | /* |
---|
| 234 | * File System Routine Prototypes |
---|
| 235 | */ |
---|
| 236 | |
---|
| 237 | int rtems_filesystem_evaluate_path( |
---|
| 238 | const char *pathname, |
---|
| 239 | int flags, |
---|
| 240 | rtems_filesystem_location_info_t *pathloc, |
---|
| 241 | int follow_link |
---|
| 242 | ); |
---|
| 243 | |
---|
[de691e68] | 244 | int rtems_filesystem_evaluate_parent( |
---|
| 245 | int flags, |
---|
| 246 | rtems_filesystem_location_info_t *pathloc |
---|
| 247 | ); |
---|
| 248 | |
---|
[07a3253d] | 249 | void rtems_filesystem_initialize(); |
---|
| 250 | |
---|
| 251 | int init_fs_mount_table(); |
---|
| 252 | |
---|
| 253 | #ifdef __cplusplus |
---|
| 254 | } |
---|
| 255 | #endif |
---|
| 256 | |
---|
| 257 | #endif |
---|
| 258 | /* end of include file */ |
---|