Changeset cca4400 in rtems
- Timestamp:
- Dec 10, 1998, 11:31:54 PM (22 years ago)
- Branches:
- 4.10, 4.11, 4.8, 4.9, 5, master
- Children:
- cdd26ca2
- Parents:
- 6c980128
- Files:
-
- 64 edited
Legend:
- Unmodified
- Added
- Removed
-
VERSION
r6c980128 rcca4400 3 3 # 4 4 5 RTEMS Version 199812035 RTEMS Version 4.0.0 -
c/src/exec/include/rtems/libio_.h
r6c980128 rcca4400 66 66 extern rtems_libio_t *rtems_libio_iops; 67 67 extern rtems_libio_t *rtems_libio_last_iop; 68 extern rtems_libio_t *rtems_libio_iop_freelist; 68 69 69 70 /* -
c/src/exec/libcsupport/include/rtems/libio.h
r6c980128 rcca4400 394 394 #define LIBIO_FLAGS_READ 0x0002 /* reading */ 395 395 #define LIBIO_FLAGS_WRITE 0x0004 /* writing */ 396 #define LIBIO_FLAGS_LINE_BUFFERED 0x0008 /* line buffered io (^h, ^u, etc) */397 396 #define LIBIO_FLAGS_OPEN 0x0100 /* device is open */ 398 397 #define LIBIO_FLAGS_APPEND 0x0200 /* all writes append */ 399 398 #define LIBIO_FLAGS_CREATE 0x0400 /* create file */ 400 399 #define LIBIO_FLAGS_CLOSE_ON_EXEC 0x0800 /* close on process exec() */ 400 401 #define LIBIO_FLAGS_HANDLER_SHIFT 12 402 #define LIBIO_FLAGS_HANDLER_MASK 0xF000 /* mask for external handler type */ 403 #define LIBIO_FLAGS_HANDLER_RTEMS 0x0000 /* `traditional' RTEMS I/O */ 404 #define LIBIO_FLAGS_HANDLER_SOCK 0x1000 /* BSD socket */ 401 405 402 406 #define LIBIO_FLAGS_READ_WRITE (LIBIO_FLAGS_READ | LIBIO_FLAGS_WRITE) -
c/src/exec/libcsupport/include/rtems/libio_.h
r6c980128 rcca4400 66 66 extern rtems_libio_t *rtems_libio_iops; 67 67 extern rtems_libio_t *rtems_libio_last_iop; 68 extern rtems_libio_t *rtems_libio_iop_freelist; 68 69 69 70 /* -
c/src/exec/libcsupport/include/sys/sockio.h
r6c980128 rcca4400 84 84 #define SIOCGIFMEDIA _IOWR('i', 56, struct ifmediareq) /* get net media */ 85 85 86 87 86 /* 88 87 * RTEMS additions for setting/getting `tap' function on incoming packets. 89 88 */ 90 #define SIOCSIFTAP 91 #define SIOCGIFTAP _IOW R('i', 81, struct ifreq) /* get tap function */89 #define SIOCSIFTAP _IOW('i', 80, struct ifreq) /* set tap function */ 90 #define SIOCGIFTAP _IOW('i', 81, struct ifreq) /* get tap function */ 92 91 93 92 #endif /* !_SYS_SOCKIO_H_ */ -
c/src/exec/libcsupport/src/close.c
r6c980128 rcca4400 23 23 int status; 24 24 25 if ( rtems_file_descriptor_type( fd ) ) { 25 rtems_libio_check_fd(fd); 26 iop = rtems_libio_iop(fd); 27 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) { 26 28 int (*fp)(int fd); 27 29 28 fp = rtems_libio_handlers[rtems_file_descriptor_type_index(fd)].close; 30 fp = rtems_libio_handlers[ 31 (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].close; 29 32 if ( fp == NULL ) 30 33 set_errno_and_return_minus_one( EBADF ); … … 32 35 return status; 33 36 } 34 iop = rtems_libio_iop(fd);35 rtems_libio_check_fd(fd);36 37 37 38 if ( !iop->handlers ) -
c/src/exec/libcsupport/src/fchmod.c
r6c980128 rcca4400 28 28 rtems_libio_t *iop; 29 29 30 rtems_libio_check_fd( fd ); 31 iop = rtems_libio_iop( fd ); 32 30 33 /* 31 34 * If this is not a file system based entity, it is an error. 32 35 */ 33 36 34 if ( rtems_file_descriptor_type( fd ))37 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) 35 38 set_errno_and_return_minus_one( EBADF ); 36 39 … … 39 42 */ 40 43 41 iop = rtems_libio_iop( fd );42 rtems_libio_check_fd( fd );43 44 rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE ); 44 45 -
c/src/exec/libcsupport/src/fcntl.c
r6c980128 rcca4400 33 33 va_start( ap, cmd ); 34 34 35 rtems_libio_check_fd( fd ); 36 iop = rtems_libio_iop( fd ); 37 35 38 /* 36 39 * If this is not a file system based entity, it is an error. 37 40 */ 38 41 39 if ( rtems_file_descriptor_type( fd ))42 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) 40 43 set_errno_and_return_minus_one( EBADF ); 41 44 … … 43 46 * Now process the fcntl(). 44 47 */ 45 46 iop = rtems_libio_iop( fd );47 rtems_libio_check_fd( fd );48 48 49 49 /* -
c/src/exec/libcsupport/src/fdatasync.c
r6c980128 rcca4400 23 23 rtems_libio_t *iop; 24 24 25 rtems_libio_check_fd( fd ); 26 iop = rtems_libio_iop( fd ); 27 rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE ); 28 25 29 /* 26 30 * If this file descriptor is mapped to an external set of handlers, … … 28 32 */ 29 33 30 if ( rtems_file_descriptor_type( fd ))34 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) 31 35 set_errno_and_return_minus_one( EBADF ); 32 36 … … 35 39 */ 36 40 37 iop = rtems_libio_iop( fd );38 rtems_libio_check_fd( fd );39 rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE );40 41 41 if ( !iop->handlers->fdatasync ) 42 42 set_errno_and_return_minus_one( ENOTSUP ); -
c/src/exec/libcsupport/src/fpathconf.c
r6c980128 rcca4400 27 27 rtems_filesystem_limits_and_options_t *the_limits; 28 28 29 rtems_libio_check_fd(fd); 30 iop = rtems_libio_iop(fd); 31 rtems_libio_check_permissions(iop, LIBIO_FLAGS_READ); 32 29 33 /* 30 34 * If this file descriptor is mapped to an external set of handlers, … … 33 37 */ 34 38 35 if ( rtems_file_descriptor_type( fd ))39 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) 36 40 set_errno_and_return_minus_one( EBADF ); 37 41 … … 39 43 * Now process the information request. 40 44 */ 41 42 iop = rtems_libio_iop(fd);43 rtems_libio_check_fd(fd);44 rtems_libio_check_permissions(iop, LIBIO_FLAGS_READ);45 45 46 46 the_limits = &iop->pathinfo.mt_entry->pathconf_limits_and_options; -
c/src/exec/libcsupport/src/fsync.c
r6c980128 rcca4400 23 23 rtems_libio_t *iop; 24 24 25 rtems_libio_check_fd( fd ); 26 iop = rtems_libio_iop( fd ); 27 rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE ); 28 25 29 /* 26 30 * If this file descriptor is mapped to an external set of handlers, … … 28 32 */ 29 33 30 if ( rtems_file_descriptor_type( fd ))34 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) 31 35 set_errno_and_return_minus_one( EBADF ); 32 36 … … 35 39 */ 36 40 37 iop = rtems_libio_iop( fd );38 rtems_libio_check_fd( fd );39 rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE );40 41 41 if ( !iop->handlers->fsync ) 42 42 set_errno_and_return_minus_one( ENOTSUP ); -
c/src/exec/libcsupport/src/ftruncate.c
r6c980128 rcca4400 26 26 rtems_filesystem_location_info_t loc; 27 27 28 rtems_libio_check_fd( fd ); 29 iop = rtems_libio_iop( fd ); 30 28 31 /* 29 32 * If this is not a file system based entity, it is an error. 30 33 */ 31 34 32 if ( rtems_file_descriptor_type( fd ))35 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) 33 36 set_errno_and_return_minus_one( EBADF ); 34 37 … … 37 40 */ 38 41 39 iop = rtems_libio_iop( fd );40 41 42 /* 42 43 * Make sure we are not working on a directory … … 50 51 set_errno_and_return_minus_one( EISDIR ); 51 52 52 rtems_libio_check_fd( fd );53 53 rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE ); 54 54 -
c/src/exec/libcsupport/src/ioctl.c
r6c980128 rcca4400 27 27 rtems_libio_t *iop; 28 28 29 rtems_libio_check_fd( fd ); 30 iop = rtems_libio_iop( fd ); 31 29 32 /* 30 33 * If this file descriptor is mapped to an external set of handlers, … … 32 35 */ 33 36 34 if ( rtems_file_descriptor_type( fd )) {37 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) { 35 38 rtems_libio_ioctl_t fp; 36 39 37 fp = rtems_libio_handlers[rtems_file_descriptor_type_index(fd)].ioctl; 40 fp = rtems_libio_handlers[ 41 (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].ioctl; 38 42 if ( fp == NULL ) 39 43 set_errno_and_return_minus_one( EBADF ); … … 46 50 */ 47 51 48 iop = rtems_libio_iop( fd );49 rtems_libio_check_fd( fd );50 51 52 if ( !iop->handlers->ioctl ) 52 53 set_errno_and_return_minus_one( ENOTSUP ); -
c/src/exec/libcsupport/src/libio.c
r6c980128 rcca4400 4 4 * POSIX system calls like open(), read, fstat(), etc. 5 5 * 6 * This provides the foundation for POSIX compliant IO system calls7 * for RTEMS.8 *9 6 * COPYRIGHT (c) 1989-1998. 10 7 * On-Line Applications Research Corporation (OAR). … … 19 16 20 17 #include "libio_.h" /* libio_.h pulls in rtems */ 21 22 /* 23 * Global variables used to manage the File Descriptor Table. 24 * IOP = IO Pointer. 25 */ 26 27 rtems_id rtems_libio_semaphore; 28 rtems_libio_t *rtems_libio_iops; 29 rtems_libio_t *rtems_libio_last_iop; 18 #include <rtems.h> 19 #include <rtems/assoc.h> /* assoc.h not included by rtems.h */ 20 21 #include <stdio.h> /* O_RDONLY, et.al. */ 22 #include <fcntl.h> /* O_RDONLY, et.al. */ 23 #include <assert.h> 24 #include <errno.h> 25 26 #if ! defined(O_NDELAY) 27 # if defined(solaris2) 28 # define O_NDELAY O_NONBLOCK 29 # elif defined(RTEMS_NEWLIB) 30 # define O_NDELAY _FNBIO 31 # endif 32 #endif 33 34 35 #include <errno.h> 36 #include <string.h> /* strcmp */ 37 #include <unistd.h> 38 #include <stdlib.h> /* calloc() */ 39 40 #include "libio.h" /* libio.h not pulled in by rtems */ 41 42 /* 43 * File descriptor Table Information 44 */ 45 46 extern unsigned32 rtems_libio_number_iops; 47 rtems_id rtems_libio_semaphore; 48 rtems_libio_t *rtems_libio_iops; 49 rtems_libio_t *rtems_libio_last_iop; 50 rtems_libio_t *rtems_libio_iop_freelist; 51 52 /* 53 * External I/O Handlers Table 54 * 55 * Space for all possible handlers is preallocated 56 * to speed up dispatch to external handlers. 57 */ 58 30 59 rtems_libio_handler_t rtems_libio_handlers[15]; 60 61 /* 62 * Default mode for all files. 63 */ 64 65 mode_t rtems_filesystem_umask; 31 66 32 67 /* … … 45 80 ) 46 81 { 47 int handler_index = rtems_file_descriptor_type_index( handler_flag ); 48 82 int handler_index = (handler_flag >> LIBIO_FLAGS_HANDLER_SHIFT) - 1; 49 83 50 84 if ((handler_index < 0) || (handler_index >= 15)) … … 62 96 void rtems_libio_init( void ) 63 97 { 64 rtems_status_code rc; 65 66 /* 67 * Allocate memory for the IOP Table 68 */ 69 70 if ( rtems_libio_number_iops > 0 ) { 71 rtems_libio_iops = 72 (rtems_libio_t *) calloc(rtems_libio_number_iops, sizeof(rtems_libio_t)); 73 74 if (rtems_libio_iops == NULL) 75 rtems_fatal_error_occurred( RTEMS_NO_MEMORY ); 76 77 rtems_libio_last_iop = rtems_libio_iops + (rtems_libio_number_iops - 1); 78 } 98 rtems_status_code rc; 99 int i; 100 rtems_libio_t *iop; 101 102 if (rtems_libio_number_iops > 0) 103 { 104 rtems_libio_iops = (rtems_libio_t *) calloc(rtems_libio_number_iops, 105 sizeof(rtems_libio_t)); 106 if (rtems_libio_iops == NULL) 107 rtems_fatal_error_occurred(RTEMS_NO_MEMORY); 108 109 iop = rtems_libio_iop_freelist = rtems_libio_iops; 110 for (i = 0 ; i < (rtems_libio_number_iops - 1) ; i++, iop++) 111 iop->data1 = iop + 1; 112 iop->data1 = NULL; 113 } 79 114 80 115 /* … … 158 193 rtems_semaphore_obtain( rtems_libio_semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT ); 159 194 160 for (iop = rtems_libio_iops; iop <= rtems_libio_last_iop; iop++) 161 if ((iop->flags & LIBIO_FLAGS_OPEN) == 0) { 162 /* 163 * Got an IOP -- create a semaphore for it. 164 */ 165 166 rc = rtems_semaphore_create( 167 RTEMS_LIBIO_IOP_SEM(iop - rtems_libio_iops), 168 1, 169 RTEMS_BINARY_SEMAPHORE | RTEMS_INHERIT_PRIORITY | RTEMS_PRIORITY, 170 RTEMS_NO_PRIORITY, 171 &iop->sem 172 ); 173 if ( rc != RTEMS_SUCCESSFUL ) 174 goto failed; 175 176 iop->flags = LIBIO_FLAGS_OPEN; 177 goto done; 195 if (rtems_libio_iop_freelist) { 196 iop = rtems_libio_iop_freelist; 197 rc = rtems_semaphore_create( 198 RTEMS_LIBIO_IOP_SEM(iop - rtems_libio_iops), 199 1, 200 RTEMS_BINARY_SEMAPHORE | RTEMS_INHERIT_PRIORITY | RTEMS_PRIORITY, 201 RTEMS_NO_PRIORITY, 202 &iop->sem 203 ); 204 if (rc != RTEMS_SUCCESSFUL) 205 goto failed; 206 rtems_libio_iop_freelist = iop->data1; 207 iop->data1 = 0; 208 iop->flags = LIBIO_FLAGS_OPEN; 209 goto done; 178 210 } 179 211 … … 199 231 rtems_semaphore_obtain( rtems_libio_semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT ); 200 232 201 if (iop->sem) 202 rtems_semaphore_delete(iop->sem); 203 204 (void) memset(iop, 0, sizeof(*iop)); 205 206 rtems_semaphore_release( rtems_libio_semaphore ); 233 if (iop->sem) 234 rtems_semaphore_delete(iop->sem); 235 236 iop->data1 = rtems_libio_iop_freelist; 237 rtems_libio_iop_freelist = iop; 238 239 rtems_semaphore_release(rtems_libio_semaphore); 207 240 } 208 241 … … 211 244 * 212 245 * This routine scans the entire file descriptor table to determine if the 213 * are any active file descriptors that refer to the at least one node in the246 * are any active file descriptors that refer to the at least one node in the 214 247 * file system that we are trying to dismount. 215 248 * … … 226 259 227 260 rtems_semaphore_obtain( rtems_libio_semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT ); 228 261 229 262 /* 230 263 * Look for any active file descriptor entry. 231 */ 232 264 */ 265 233 266 for ( iop=rtems_libio_iops ; iop <= rtems_libio_last_iop ; iop++ ) { 234 267 235 268 if ((iop->flags & LIBIO_FLAGS_OPEN) != 0) { 236 269 237 270 /* 238 271 * Check if this node is under the file system that we 239 272 * are trying to dismount. 240 */ 273 */ 241 274 242 275 if ( iop->pathinfo.mt_entry == fs_mt_entry ) { … … 248 281 249 282 rtems_semaphore_release( rtems_libio_semaphore ); 250 283 251 284 return result; 252 285 } … … 257 290 * This routine scans the entire file descriptor table to determine if the 258 291 * given file refers to an active file descriptor. 259 * 292 * 260 293 * If the given file is open a 1 is returned, otherwise a 0 is returned. 261 294 */ … … 266 299 { 267 300 rtems_libio_t *iop; 268 int result=0; 301 int result=0; 269 302 270 303 rtems_semaphore_obtain( rtems_libio_semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT ); … … 273 306 * Look for any active file descriptor entry. 274 307 */ 275 308 276 309 for ( iop=rtems_libio_iops ; iop <= rtems_libio_last_iop ; iop++ ) { 277 310 278 311 if ((iop->flags & LIBIO_FLAGS_OPEN) != 0) { 279 312 280 313 /* 281 314 * Check if this node is under the file system that we 282 315 * are trying to dismount. 283 */ 316 */ 284 317 285 318 if ( iop->pathinfo.node_access == node_access ) { … … 294 327 return result; 295 328 } 329 330 -
c/src/exec/libcsupport/src/lseek.c
r6c980128 rcca4400 25 25 rtems_libio_t *iop; 26 26 27 rtems_libio_check_fd( fd ); 28 iop = rtems_libio_iop( fd ); 29 27 30 /* 28 31 * If this file descriptor is mapped to an external set of handlers, … … 30 33 */ 31 34 32 if ( rtems_file_descriptor_type( fd )) {35 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) { 33 36 rtems_libio_lseek_t fp; 34 37 35 fp = rtems_libio_handlers[rtems_file_descriptor_type_index(fd)].lseek; 38 fp = rtems_libio_handlers[ 39 (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].lseek; 36 40 if ( fp == NULL ) 37 41 set_errno_and_return_minus_one( EBADF ); … … 43 47 * Now process the lseek(). 44 48 */ 45 46 iop = rtems_libio_iop( fd );47 rtems_libio_check_fd( fd );48 49 49 50 switch ( whence ) { -
c/src/exec/libcsupport/src/read.c
r6c980128 rcca4400 27 27 rtems_libio_t *iop; 28 28 29 rtems_libio_check_fd( fd ); 30 iop = rtems_libio_iop( fd ); 31 rtems_libio_check_buffer( buffer ); 32 rtems_libio_check_count( count ); 33 rtems_libio_check_permissions( iop, LIBIO_FLAGS_READ ); 34 29 35 /* 30 36 * If this file descriptor is mapped to an external set of handlers, … … 32 38 */ 33 39 34 if ( rtems_file_descriptor_type( fd )) {40 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) { 35 41 rtems_libio_read_t fp; 36 42 37 fp = rtems_libio_handlers[rtems_file_descriptor_type_index(fd)].read; 43 fp = rtems_libio_handlers[ 44 (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].read; 38 45 if ( fp == NULL ) 39 46 set_errno_and_return_minus_one( EBADF ); … … 45 52 * Now process the read(). 46 53 */ 47 48 iop = rtems_libio_iop( fd );49 rtems_libio_check_fd( fd );50 rtems_libio_check_buffer( buffer );51 rtems_libio_check_count( count );52 rtems_libio_check_permissions( iop, LIBIO_FLAGS_READ );53 54 54 55 if ( !iop->handlers->read ) -
c/src/exec/libcsupport/src/write.c
r6c980128 rcca4400 35 35 rtems_libio_t *iop; 36 36 37 rtems_libio_check_fd( fd ); 38 iop = rtems_libio_iop( fd ); 39 rtems_libio_check_buffer( buffer ); 40 rtems_libio_check_count( count ); 41 rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE ); 42 37 43 /* 38 44 * If this file descriptor is mapped to an external set of handlers, … … 40 46 */ 41 47 42 if ( rtems_file_descriptor_type( fd )) {48 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) { 43 49 rtems_libio_write_t fp; 44 50 45 fp = rtems_libio_handlers[rtems_file_descriptor_type_index(fd)].write; 51 fp = rtems_libio_handlers[ 52 (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].write; 46 53 if ( fp == NULL ) 47 54 set_errno_and_return_minus_one( EBADF ); … … 53 60 * Now process the write() request. 54 61 */ 55 56 iop = rtems_libio_iop( fd );57 rtems_libio_check_fd( fd );58 rtems_libio_check_buffer( buffer );59 rtems_libio_check_count( count );60 rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE );61 62 62 63 if ( !iop->handlers->write ) -
c/src/exec/libnetworking/rtems/rtems_glue.c
r6c980128 rcca4400 30 30 #include <net/netisr.h> 31 31 #include <net/route.h> 32 33 /*34 * Events used by networking routines.35 * Everything will break if the application36 * tries to use these events or if the `sleep'37 * events are equal to any of the NETISR * events.38 */39 #define SBWAIT_EVENT RTEMS_EVENT_2440 #define SOSLEEP_EVENT RTEMS_EVENT_2541 #define NETISR_IP_EVENT (1 << NETISR_IP)42 #define NETISR_ARP_EVENT (1 << NETISR_ARP)43 #define NETISR_EVENTS (NETISR_IP_EVENT|NETISR_ARP_EVENT)44 45 32 46 33 /* … … 247 234 * Register as an external I/O handler 248 235 */ 249 rtems_register_libio_handler ( RTEMS_FILE_DESCRIPTOR_TYPE_SOCKET,236 rtems_register_libio_handler (LIBIO_FLAGS_HANDLER_SOCK, 250 237 &rtems_bsdnet_io_handler); 251 238 … … 306 293 * Set this task as the target of the wakeup operation. 307 294 */ 308 if (sb->sb_sel.si_pid)309 rtems_panic ("Another task is already sleeping on that socket buffer");310 295 rtems_task_ident (RTEMS_SELF, 0, &tid); 311 296 sb->sb_sel.si_pid = tid; 312 297 313 298 /* 314 * Mark the socket buffer as waiting.315 */316 sb->sb_flags |= SB_WAIT;317 318 /*319 299 * Release the network semaphore. 320 300 */ … … 330 310 */ 331 311 rtems_bsdnet_semaphore_obtain (); 332 333 /*334 * Relinquish ownership of the socket buffer335 */336 sb->sb_flags &= ~SB_WAIT;337 sb->sb_sel.si_pid = 0;338 312 339 313 /* … … 356 330 register struct sockbuf *sb; 357 331 { 358 if (sb->sb_flags & SB_WAIT) { 359 sb->sb_flags &= ~SB_WAIT; 360 rtems_event_send (sb->sb_sel.si_pid, SBWAIT_EVENT); 332 rtems_id tid; 333 334 if ((tid = sb->sb_sel.si_pid) != 0) { 335 sb->sb_sel.si_pid = 0; 336 rtems_event_send (tid, SBWAIT_EVENT); 361 337 } 362 338 } -
c/src/exec/libnetworking/rtems/rtems_syscall.c
r6c980128 rcca4400 25 25 #include <net/if.h> 26 26 #include <net/route.h> 27 28 /*29 *********************************************************************30 * Map RTEMS file descriptor to BSD socket *31 *********************************************************************32 */33 struct fdsock {34 int indexFreeNext;35 struct socket *sock;36 };37 static struct fdsock *fdsock;38 static int fdsockCount;39 static int indexFreeHead = -1;40 41 /*42 * Convert an RTEMS file descriptor to a BSD socket pointer.43 */44 static struct socket *45 fdToSocket (int fd)46 {47 int i;48 struct socket *s;49 50 if ((fd < 0)51 || (rtems_file_descriptor_type(fd) != RTEMS_FILE_DESCRIPTOR_TYPE_SOCKET)52 || ((i = rtems_file_descriptor_base(fd)) >= fdsockCount)53 || ((s = fdsock[i].sock) == NULL)) {54 errno = EBADF;55 return NULL;56 }57 return s;58 }59 60 /*61 * Enlarge the size of the file-descritor/socket pointer map.62 */63 static int64 enlargeFdMap (void)65 {66 struct fdsock *nfdsock;67 int i;68 69 nfdsock = realloc (fdsock, sizeof *fdsock * (fdsockCount + 20));70 if (nfdsock == NULL) {71 errno = ENFILE;72 return 0;73 }74 fdsock = nfdsock;75 for (i = fdsockCount, fdsockCount += 20 ; i < fdsockCount ; i++) {76 fdsock[i].sock = NULL;77 fdsock[i].indexFreeNext = indexFreeHead;78 indexFreeHead = i;79 }80 return 1;81 }82 83 /*84 * Create a file descriptor for a new socket85 */86 static int87 makeFd (struct socket *s)88 {89 int i;90 91 if ((indexFreeHead < 0) && !enlargeFdMap ())92 return -1;93 i = indexFreeHead;94 indexFreeHead = fdsock[i].indexFreeNext;95 fdsock[i].sock = s;96 return rtems_make_file_descriptor(i,RTEMS_FILE_DESCRIPTOR_TYPE_SOCKET);97 }98 27 99 28 /* … … 129 58 socket (int domain, int type, int protocol) 130 59 { 131 int fd = -1;60 int fd; 132 61 int error; 133 62 struct socket *so; … … 136 65 error = socreate(domain, &so, type, protocol, NULL); 137 66 if (error == 0) { 138 fd = makeFd(so);67 fd = rtems_bsdnet_makeFdForSocket (so); 139 68 if (fd < 0) 140 69 soclose (so); … … 157 86 158 87 rtems_bsdnet_semaphore_obtain (); 159 if ((so = fdToSocket (s)) != NULL) {88 if ((so = rtems_bsdnet_fdToSocket (s)) != NULL) { 160 89 error = sockargstombuf (&nam, name, namelen, MT_SONAME); 161 90 if (error == 0) { … … 184 113 185 114 rtems_bsdnet_semaphore_obtain (); 186 if ((so = fdToSocket (s)) == NULL) {115 if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) { 187 116 rtems_bsdnet_semaphore_release (); 188 117 return -1; … … 234 163 235 164 rtems_bsdnet_semaphore_obtain (); 236 if ((so = fdToSocket (s)) != NULL) {165 if ((so = rtems_bsdnet_fdToSocket (s)) != NULL) { 237 166 error = solisten (so, backlog); 238 167 if (error == 0) … … 253 182 254 183 rtems_bsdnet_semaphore_obtain (); 255 if ((head = fdToSocket (s)) == NULL) {184 if ((head = rtems_bsdnet_fdToSocket (s)) == NULL) { 256 185 rtems_bsdnet_semaphore_release (); 257 186 return -1; … … 285 214 head->so_qlen--; 286 215 287 fd = makeFd(so);216 fd = rtems_bsdnet_makeFdForSocket (so); 288 217 if (fd < 0) { 289 218 TAILQ_INSERT_HEAD(&head->so_comp, so, so_list); … … 326 255 327 256 rtems_bsdnet_semaphore_obtain (); 328 if ((so = fdToSocket (s)) == NULL) {257 if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) { 329 258 rtems_bsdnet_semaphore_release (); 330 259 return -1; … … 429 358 430 359 rtems_bsdnet_semaphore_obtain (); 431 if ((so = fdToSocket (s)) == NULL) {360 if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) { 432 361 rtems_bsdnet_semaphore_release (); 433 362 return -1; … … 548 477 549 478 rtems_bsdnet_semaphore_obtain (); 550 if ((so = fdToSocket (s)) == NULL) {479 if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) { 551 480 rtems_bsdnet_semaphore_release (); 552 481 return -1; … … 585 514 586 515 rtems_bsdnet_semaphore_obtain (); 587 if ((so = fdToSocket (s)) == NULL) {516 if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) { 588 517 rtems_bsdnet_semaphore_release (); 589 518 return -1; … … 627 556 628 557 rtems_bsdnet_semaphore_obtain (); 629 if ((so = fdToSocket (s)) == NULL) {558 if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) { 630 559 rtems_bsdnet_semaphore_release (); 631 560 return -1; … … 677 606 struct socket *so; 678 607 int error; 679 int i; 680 681 rtems_bsdnet_semaphore_obtain (); 682 if ((so = fdToSocket (fd)) == NULL) { 683 rtems_bsdnet_semaphore_release (); 684 return -1; 685 } 686 i = rtems_file_descriptor_base(fd); 687 fdsock[i].indexFreeNext = indexFreeHead;; 688 indexFreeHead = i; 608 609 rtems_bsdnet_semaphore_obtain (); 610 if ((so = rtems_bsdnet_fdToSocket (fd)) == NULL) { 611 rtems_bsdnet_semaphore_release (); 612 return -1; 613 } 689 614 error = soclose (so); 690 615 rtems_bsdnet_semaphore_release (); … … 738 663 739 664 rtems_bsdnet_semaphore_obtain (); 740 if ((so = fdToSocket (fd)) == NULL) {665 if ((so = rtems_bsdnet_fdToSocket (fd)) == NULL) { 741 666 rtems_bsdnet_semaphore_release (); 742 667 return -1; -
c/src/lib/include/rtems/libio.h
r6c980128 rcca4400 394 394 #define LIBIO_FLAGS_READ 0x0002 /* reading */ 395 395 #define LIBIO_FLAGS_WRITE 0x0004 /* writing */ 396 #define LIBIO_FLAGS_LINE_BUFFERED 0x0008 /* line buffered io (^h, ^u, etc) */397 396 #define LIBIO_FLAGS_OPEN 0x0100 /* device is open */ 398 397 #define LIBIO_FLAGS_APPEND 0x0200 /* all writes append */ 399 398 #define LIBIO_FLAGS_CREATE 0x0400 /* create file */ 400 399 #define LIBIO_FLAGS_CLOSE_ON_EXEC 0x0800 /* close on process exec() */ 400 401 #define LIBIO_FLAGS_HANDLER_SHIFT 12 402 #define LIBIO_FLAGS_HANDLER_MASK 0xF000 /* mask for external handler type */ 403 #define LIBIO_FLAGS_HANDLER_RTEMS 0x0000 /* `traditional' RTEMS I/O */ 404 #define LIBIO_FLAGS_HANDLER_SOCK 0x1000 /* BSD socket */ 401 405 402 406 #define LIBIO_FLAGS_READ_WRITE (LIBIO_FLAGS_READ | LIBIO_FLAGS_WRITE) -
c/src/lib/include/rtems/libio_.h
r6c980128 rcca4400 66 66 extern rtems_libio_t *rtems_libio_iops; 67 67 extern rtems_libio_t *rtems_libio_last_iop; 68 extern rtems_libio_t *rtems_libio_iop_freelist; 68 69 69 70 /* -
c/src/lib/include/sys/sockio.h
r6c980128 rcca4400 84 84 #define SIOCGIFMEDIA _IOWR('i', 56, struct ifmediareq) /* get net media */ 85 85 86 87 86 /* 88 87 * RTEMS additions for setting/getting `tap' function on incoming packets. 89 88 */ 90 #define SIOCSIFTAP 91 #define SIOCGIFTAP _IOW R('i', 81, struct ifreq) /* get tap function */89 #define SIOCSIFTAP _IOW('i', 80, struct ifreq) /* set tap function */ 90 #define SIOCGIFTAP _IOW('i', 81, struct ifreq) /* get tap function */ 92 91 93 92 #endif /* !_SYS_SOCKIO_H_ */ -
c/src/lib/libc/close.c
r6c980128 rcca4400 23 23 int status; 24 24 25 if ( rtems_file_descriptor_type( fd ) ) { 25 rtems_libio_check_fd(fd); 26 iop = rtems_libio_iop(fd); 27 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) { 26 28 int (*fp)(int fd); 27 29 28 fp = rtems_libio_handlers[rtems_file_descriptor_type_index(fd)].close; 30 fp = rtems_libio_handlers[ 31 (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].close; 29 32 if ( fp == NULL ) 30 33 set_errno_and_return_minus_one( EBADF ); … … 32 35 return status; 33 36 } 34 iop = rtems_libio_iop(fd);35 rtems_libio_check_fd(fd);36 37 37 38 if ( !iop->handlers ) -
c/src/lib/libc/fchmod.c
r6c980128 rcca4400 28 28 rtems_libio_t *iop; 29 29 30 rtems_libio_check_fd( fd ); 31 iop = rtems_libio_iop( fd ); 32 30 33 /* 31 34 * If this is not a file system based entity, it is an error. 32 35 */ 33 36 34 if ( rtems_file_descriptor_type( fd ))37 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) 35 38 set_errno_and_return_minus_one( EBADF ); 36 39 … … 39 42 */ 40 43 41 iop = rtems_libio_iop( fd );42 rtems_libio_check_fd( fd );43 44 rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE ); 44 45 -
c/src/lib/libc/fcntl.c
r6c980128 rcca4400 33 33 va_start( ap, cmd ); 34 34 35 rtems_libio_check_fd( fd ); 36 iop = rtems_libio_iop( fd ); 37 35 38 /* 36 39 * If this is not a file system based entity, it is an error. 37 40 */ 38 41 39 if ( rtems_file_descriptor_type( fd ))42 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) 40 43 set_errno_and_return_minus_one( EBADF ); 41 44 … … 43 46 * Now process the fcntl(). 44 47 */ 45 46 iop = rtems_libio_iop( fd );47 rtems_libio_check_fd( fd );48 48 49 49 /* -
c/src/lib/libc/fdatasync.c
r6c980128 rcca4400 23 23 rtems_libio_t *iop; 24 24 25 rtems_libio_check_fd( fd ); 26 iop = rtems_libio_iop( fd ); 27 rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE ); 28 25 29 /* 26 30 * If this file descriptor is mapped to an external set of handlers, … … 28 32 */ 29 33 30 if ( rtems_file_descriptor_type( fd ))34 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) 31 35 set_errno_and_return_minus_one( EBADF ); 32 36 … … 35 39 */ 36 40 37 iop = rtems_libio_iop( fd );38 rtems_libio_check_fd( fd );39 rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE );40 41 41 if ( !iop->handlers->fdatasync ) 42 42 set_errno_and_return_minus_one( ENOTSUP ); -
c/src/lib/libc/fpathconf.c
r6c980128 rcca4400 27 27 rtems_filesystem_limits_and_options_t *the_limits; 28 28 29 rtems_libio_check_fd(fd); 30 iop = rtems_libio_iop(fd); 31 rtems_libio_check_permissions(iop, LIBIO_FLAGS_READ); 32 29 33 /* 30 34 * If this file descriptor is mapped to an external set of handlers, … … 33 37 */ 34 38 35 if ( rtems_file_descriptor_type( fd ))39 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) 36 40 set_errno_and_return_minus_one( EBADF ); 37 41 … … 39 43 * Now process the information request. 40 44 */ 41 42 iop = rtems_libio_iop(fd);43 rtems_libio_check_fd(fd);44 rtems_libio_check_permissions(iop, LIBIO_FLAGS_READ);45 45 46 46 the_limits = &iop->pathinfo.mt_entry->pathconf_limits_and_options; -
c/src/lib/libc/fsync.c
r6c980128 rcca4400 23 23 rtems_libio_t *iop; 24 24 25 rtems_libio_check_fd( fd ); 26 iop = rtems_libio_iop( fd ); 27 rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE ); 28 25 29 /* 26 30 * If this file descriptor is mapped to an external set of handlers, … … 28 32 */ 29 33 30 if ( rtems_file_descriptor_type( fd ))34 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) 31 35 set_errno_and_return_minus_one( EBADF ); 32 36 … … 35 39 */ 36 40 37 iop = rtems_libio_iop( fd );38 rtems_libio_check_fd( fd );39 rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE );40 41 41 if ( !iop->handlers->fsync ) 42 42 set_errno_and_return_minus_one( ENOTSUP ); -
c/src/lib/libc/ftruncate.c
r6c980128 rcca4400 26 26 rtems_filesystem_location_info_t loc; 27 27 28 rtems_libio_check_fd( fd ); 29 iop = rtems_libio_iop( fd ); 30 28 31 /* 29 32 * If this is not a file system based entity, it is an error. 30 33 */ 31 34 32 if ( rtems_file_descriptor_type( fd ))35 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) 33 36 set_errno_and_return_minus_one( EBADF ); 34 37 … … 37 40 */ 38 41 39 iop = rtems_libio_iop( fd );40 41 42 /* 42 43 * Make sure we are not working on a directory … … 50 51 set_errno_and_return_minus_one( EISDIR ); 51 52 52 rtems_libio_check_fd( fd );53 53 rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE ); 54 54 -
c/src/lib/libc/ioctl.c
r6c980128 rcca4400 27 27 rtems_libio_t *iop; 28 28 29 rtems_libio_check_fd( fd ); 30 iop = rtems_libio_iop( fd ); 31 29 32 /* 30 33 * If this file descriptor is mapped to an external set of handlers, … … 32 35 */ 33 36 34 if ( rtems_file_descriptor_type( fd )) {37 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) { 35 38 rtems_libio_ioctl_t fp; 36 39 37 fp = rtems_libio_handlers[rtems_file_descriptor_type_index(fd)].ioctl; 40 fp = rtems_libio_handlers[ 41 (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].ioctl; 38 42 if ( fp == NULL ) 39 43 set_errno_and_return_minus_one( EBADF ); … … 46 50 */ 47 51 48 iop = rtems_libio_iop( fd );49 rtems_libio_check_fd( fd );50 51 52 if ( !iop->handlers->ioctl ) 52 53 set_errno_and_return_minus_one( ENOTSUP ); -
c/src/lib/libc/libio.c
r6c980128 rcca4400 4 4 * POSIX system calls like open(), read, fstat(), etc. 5 5 * 6 * This provides the foundation for POSIX compliant IO system calls7 * for RTEMS.8 *9 6 * COPYRIGHT (c) 1989-1998. 10 7 * On-Line Applications Research Corporation (OAR). … … 19 16 20 17 #include "libio_.h" /* libio_.h pulls in rtems */ 21 22 /* 23 * Global variables used to manage the File Descriptor Table. 24 * IOP = IO Pointer. 25 */ 26 27 rtems_id rtems_libio_semaphore; 28 rtems_libio_t *rtems_libio_iops; 29 rtems_libio_t *rtems_libio_last_iop; 18 #include <rtems.h> 19 #include <rtems/assoc.h> /* assoc.h not included by rtems.h */ 20 21 #include <stdio.h> /* O_RDONLY, et.al. */ 22 #include <fcntl.h> /* O_RDONLY, et.al. */ 23 #include <assert.h> 24 #include <errno.h> 25 26 #if ! defined(O_NDELAY) 27 # if defined(solaris2) 28 # define O_NDELAY O_NONBLOCK 29 # elif defined(RTEMS_NEWLIB) 30 # define O_NDELAY _FNBIO 31 # endif 32 #endif 33 34 35 #include <errno.h> 36 #include <string.h> /* strcmp */ 37 #include <unistd.h> 38 #include <stdlib.h> /* calloc() */ 39 40 #include "libio.h" /* libio.h not pulled in by rtems */ 41 42 /* 43 * File descriptor Table Information 44 */ 45 46 extern unsigned32 rtems_libio_number_iops; 47 rtems_id rtems_libio_semaphore; 48 rtems_libio_t *rtems_libio_iops; 49 rtems_libio_t *rtems_libio_last_iop; 50 rtems_libio_t *rtems_libio_iop_freelist; 51 52 /* 53 * External I/O Handlers Table 54 * 55 * Space for all possible handlers is preallocated 56 * to speed up dispatch to external handlers. 57 */ 58 30 59 rtems_libio_handler_t rtems_libio_handlers[15]; 60 61 /* 62 * Default mode for all files. 63 */ 64 65 mode_t rtems_filesystem_umask; 31 66 32 67 /* … … 45 80 ) 46 81 { 47 int handler_index = rtems_file_descriptor_type_index( handler_flag ); 48 82 int handler_index = (handler_flag >> LIBIO_FLAGS_HANDLER_SHIFT) - 1; 49 83 50 84 if ((handler_index < 0) || (handler_index >= 15)) … … 62 96 void rtems_libio_init( void ) 63 97 { 64 rtems_status_code rc; 65 66 /* 67 * Allocate memory for the IOP Table 68 */ 69 70 if ( rtems_libio_number_iops > 0 ) { 71 rtems_libio_iops = 72 (rtems_libio_t *) calloc(rtems_libio_number_iops, sizeof(rtems_libio_t)); 73 74 if (rtems_libio_iops == NULL) 75 rtems_fatal_error_occurred( RTEMS_NO_MEMORY ); 76 77 rtems_libio_last_iop = rtems_libio_iops + (rtems_libio_number_iops - 1); 78 } 98 rtems_status_code rc; 99 int i; 100 rtems_libio_t *iop; 101 102 if (rtems_libio_number_iops > 0) 103 { 104 rtems_libio_iops = (rtems_libio_t *) calloc(rtems_libio_number_iops, 105 sizeof(rtems_libio_t)); 106 if (rtems_libio_iops == NULL) 107 rtems_fatal_error_occurred(RTEMS_NO_MEMORY); 108 109 iop = rtems_libio_iop_freelist = rtems_libio_iops; 110 for (i = 0 ; i < (rtems_libio_number_iops - 1) ; i++, iop++) 111 iop->data1 = iop + 1; 112 iop->data1 = NULL; 113 } 79 114 80 115 /* … … 158 193 rtems_semaphore_obtain( rtems_libio_semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT ); 159 194 160 for (iop = rtems_libio_iops; iop <= rtems_libio_last_iop; iop++) 161 if ((iop->flags & LIBIO_FLAGS_OPEN) == 0) { 162 /* 163 * Got an IOP -- create a semaphore for it. 164 */ 165 166 rc = rtems_semaphore_create( 167 RTEMS_LIBIO_IOP_SEM(iop - rtems_libio_iops), 168 1, 169 RTEMS_BINARY_SEMAPHORE | RTEMS_INHERIT_PRIORITY | RTEMS_PRIORITY, 170 RTEMS_NO_PRIORITY, 171 &iop->sem 172 ); 173 if ( rc != RTEMS_SUCCESSFUL ) 174 goto failed; 175 176 iop->flags = LIBIO_FLAGS_OPEN; 177 goto done; 195 if (rtems_libio_iop_freelist) { 196 iop = rtems_libio_iop_freelist; 197 rc = rtems_semaphore_create( 198 RTEMS_LIBIO_IOP_SEM(iop - rtems_libio_iops), 199 1, 200 RTEMS_BINARY_SEMAPHORE | RTEMS_INHERIT_PRIORITY | RTEMS_PRIORITY, 201 RTEMS_NO_PRIORITY, 202 &iop->sem 203 ); 204 if (rc != RTEMS_SUCCESSFUL) 205 goto failed; 206 rtems_libio_iop_freelist = iop->data1; 207 iop->data1 = 0; 208 iop->flags = LIBIO_FLAGS_OPEN; 209 goto done; 178 210 } 179 211 … … 199 231 rtems_semaphore_obtain( rtems_libio_semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT ); 200 232 201 if (iop->sem) 202 rtems_semaphore_delete(iop->sem); 203 204 (void) memset(iop, 0, sizeof(*iop)); 205 206 rtems_semaphore_release( rtems_libio_semaphore ); 233 if (iop->sem) 234 rtems_semaphore_delete(iop->sem); 235 236 iop->data1 = rtems_libio_iop_freelist; 237 rtems_libio_iop_freelist = iop; 238 239 rtems_semaphore_release(rtems_libio_semaphore); 207 240 } 208 241 … … 211 244 * 212 245 * This routine scans the entire file descriptor table to determine if the 213 * are any active file descriptors that refer to the at least one node in the246 * are any active file descriptors that refer to the at least one node in the 214 247 * file system that we are trying to dismount. 215 248 * … … 226 259 227 260 rtems_semaphore_obtain( rtems_libio_semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT ); 228 261 229 262 /* 230 263 * Look for any active file descriptor entry. 231 */ 232 264 */ 265 233 266 for ( iop=rtems_libio_iops ; iop <= rtems_libio_last_iop ; iop++ ) { 234 267 235 268 if ((iop->flags & LIBIO_FLAGS_OPEN) != 0) { 236 269 237 270 /* 238 271 * Check if this node is under the file system that we 239 272 * are trying to dismount. 240 */ 273 */ 241 274 242 275 if ( iop->pathinfo.mt_entry == fs_mt_entry ) { … … 248 281 249 282 rtems_semaphore_release( rtems_libio_semaphore ); 250 283 251 284 return result; 252 285 } … … 257 290 * This routine scans the entire file descriptor table to determine if the 258 291 * given file refers to an active file descriptor. 259 * 292 * 260 293 * If the given file is open a 1 is returned, otherwise a 0 is returned. 261 294 */ … … 266 299 { 267 300 rtems_libio_t *iop; 268 int result=0; 301 int result=0; 269 302 270 303 rtems_semaphore_obtain( rtems_libio_semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT ); … … 273 306 * Look for any active file descriptor entry. 274 307 */ 275 308 276 309 for ( iop=rtems_libio_iops ; iop <= rtems_libio_last_iop ; iop++ ) { 277 310 278 311 if ((iop->flags & LIBIO_FLAGS_OPEN) != 0) { 279 312 280 313 /* 281 314 * Check if this node is under the file system that we 282 315 * are trying to dismount. 283 */ 316 */ 284 317 285 318 if ( iop->pathinfo.node_access == node_access ) { … … 294 327 return result; 295 328 } 329 330 -
c/src/lib/libc/libio.h
r6c980128 rcca4400 394 394 #define LIBIO_FLAGS_READ 0x0002 /* reading */ 395 395 #define LIBIO_FLAGS_WRITE 0x0004 /* writing */ 396 #define LIBIO_FLAGS_LINE_BUFFERED 0x0008 /* line buffered io (^h, ^u, etc) */397 396 #define LIBIO_FLAGS_OPEN 0x0100 /* device is open */ 398 397 #define LIBIO_FLAGS_APPEND 0x0200 /* all writes append */ 399 398 #define LIBIO_FLAGS_CREATE 0x0400 /* create file */ 400 399 #define LIBIO_FLAGS_CLOSE_ON_EXEC 0x0800 /* close on process exec() */ 400 401 #define LIBIO_FLAGS_HANDLER_SHIFT 12 402 #define LIBIO_FLAGS_HANDLER_MASK 0xF000 /* mask for external handler type */ 403 #define LIBIO_FLAGS_HANDLER_RTEMS 0x0000 /* `traditional' RTEMS I/O */ 404 #define LIBIO_FLAGS_HANDLER_SOCK 0x1000 /* BSD socket */ 401 405 402 406 #define LIBIO_FLAGS_READ_WRITE (LIBIO_FLAGS_READ | LIBIO_FLAGS_WRITE) -
c/src/lib/libc/libio_.h
r6c980128 rcca4400 66 66 extern rtems_libio_t *rtems_libio_iops; 67 67 extern rtems_libio_t *rtems_libio_last_iop; 68 extern rtems_libio_t *rtems_libio_iop_freelist; 68 69 69 70 /* -
c/src/lib/libc/lseek.c
r6c980128 rcca4400 25 25 rtems_libio_t *iop; 26 26 27 rtems_libio_check_fd( fd ); 28 iop = rtems_libio_iop( fd ); 29 27 30 /* 28 31 * If this file descriptor is mapped to an external set of handlers, … … 30 33 */ 31 34 32 if ( rtems_file_descriptor_type( fd )) {35 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) { 33 36 rtems_libio_lseek_t fp; 34 37 35 fp = rtems_libio_handlers[rtems_file_descriptor_type_index(fd)].lseek; 38 fp = rtems_libio_handlers[ 39 (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].lseek; 36 40 if ( fp == NULL ) 37 41 set_errno_and_return_minus_one( EBADF ); … … 43 47 * Now process the lseek(). 44 48 */ 45 46 iop = rtems_libio_iop( fd );47 rtems_libio_check_fd( fd );48 49 49 50 switch ( whence ) { -
c/src/lib/libc/read.c
r6c980128 rcca4400 27 27 rtems_libio_t *iop; 28 28 29 rtems_libio_check_fd( fd ); 30 iop = rtems_libio_iop( fd ); 31 rtems_libio_check_buffer( buffer ); 32 rtems_libio_check_count( count ); 33 rtems_libio_check_permissions( iop, LIBIO_FLAGS_READ ); 34 29 35 /* 30 36 * If this file descriptor is mapped to an external set of handlers, … … 32 38 */ 33 39 34 if ( rtems_file_descriptor_type( fd )) {40 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) { 35 41 rtems_libio_read_t fp; 36 42 37 fp = rtems_libio_handlers[rtems_file_descriptor_type_index(fd)].read; 43 fp = rtems_libio_handlers[ 44 (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].read; 38 45 if ( fp == NULL ) 39 46 set_errno_and_return_minus_one( EBADF ); … … 45 52 * Now process the read(). 46 53 */ 47 48 iop = rtems_libio_iop( fd );49 rtems_libio_check_fd( fd );50 rtems_libio_check_buffer( buffer );51 rtems_libio_check_count( count );52 rtems_libio_check_permissions( iop, LIBIO_FLAGS_READ );53 54 54 55 if ( !iop->handlers->read ) -
c/src/lib/libc/write.c
r6c980128 rcca4400 35 35 rtems_libio_t *iop; 36 36 37 rtems_libio_check_fd( fd ); 38 iop = rtems_libio_iop( fd ); 39 rtems_libio_check_buffer( buffer ); 40 rtems_libio_check_count( count ); 41 rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE ); 42 37 43 /* 38 44 * If this file descriptor is mapped to an external set of handlers, … … 40 46 */ 41 47 42 if ( rtems_file_descriptor_type( fd )) {48 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) { 43 49 rtems_libio_write_t fp; 44 50 45 fp = rtems_libio_handlers[rtems_file_descriptor_type_index(fd)].write; 51 fp = rtems_libio_handlers[ 52 (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].write; 46 53 if ( fp == NULL ) 47 54 set_errno_and_return_minus_one( EBADF ); … … 53 60 * Now process the write() request. 54 61 */ 55 56 iop = rtems_libio_iop( fd );57 rtems_libio_check_fd( fd );58 rtems_libio_check_buffer( buffer );59 rtems_libio_check_count( count );60 rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE );61 62 62 63 if ( !iop->handlers->write ) -
c/src/lib/libnetworking/rtems/Makefile.in
r6c980128 rcca4400 17 17 rtems_showmbuf rtems_showroute \ 18 18 rtems_showifstat rtems_showipstat rtems_showicmpstat \ 19 rtems_showtcpstat rtems_showudpstat 19 rtems_showtcpstat rtems_showudpstat rtems_select 20 20 C_FILES=$(C_PIECES:%=%.c) 21 21 C_O_FILES=$(C_PIECES:%=${ARCH}/%.o) -
c/src/lib/libnetworking/rtems/rtems_glue.c
r6c980128 rcca4400 30 30 #include <net/netisr.h> 31 31 #include <net/route.h> 32 33 /*34 * Events used by networking routines.35 * Everything will break if the application36 * tries to use these events or if the `sleep'37 * events are equal to any of the NETISR * events.38 */39 #define SBWAIT_EVENT RTEMS_EVENT_2440 #define SOSLEEP_EVENT RTEMS_EVENT_2541 #define NETISR_IP_EVENT (1 << NETISR_IP)42 #define NETISR_ARP_EVENT (1 << NETISR_ARP)43 #define NETISR_EVENTS (NETISR_IP_EVENT|NETISR_ARP_EVENT)44 45 32 46 33 /* … … 247 234 * Register as an external I/O handler 248 235 */ 249 rtems_register_libio_handler ( RTEMS_FILE_DESCRIPTOR_TYPE_SOCKET,236 rtems_register_libio_handler (LIBIO_FLAGS_HANDLER_SOCK, 250 237 &rtems_bsdnet_io_handler); 251 238 … … 306 293 * Set this task as the target of the wakeup operation. 307 294 */ 308 if (sb->sb_sel.si_pid)309 rtems_panic ("Another task is already sleeping on that socket buffer");310 295 rtems_task_ident (RTEMS_SELF, 0, &tid); 311 296 sb->sb_sel.si_pid = tid; 312 297 313 298 /* 314 * Mark the socket buffer as waiting.315 */316 sb->sb_flags |= SB_WAIT;317 318 /*319 299 * Release the network semaphore. 320 300 */ … … 330 310 */ 331 311 rtems_bsdnet_semaphore_obtain (); 332 333 /*334 * Relinquish ownership of the socket buffer335 */336 sb->sb_flags &= ~SB_WAIT;337 sb->sb_sel.si_pid = 0;338 312 339 313 /* … … 356 330 register struct sockbuf *sb; 357 331 { 358 if (sb->sb_flags & SB_WAIT) { 359 sb->sb_flags &= ~SB_WAIT; 360 rtems_event_send (sb->sb_sel.si_pid, SBWAIT_EVENT); 332 rtems_id tid; 333 334 if ((tid = sb->sb_sel.si_pid) != 0) { 335 sb->sb_sel.si_pid = 0; 336 rtems_event_send (tid, SBWAIT_EVENT); 361 337 } 362 338 } -
c/src/lib/libnetworking/rtems/rtems_syscall.c
r6c980128 rcca4400 25 25 #include <net/if.h> 26 26 #include <net/route.h> 27 28 /*29 *********************************************************************30 * Map RTEMS file descriptor to BSD socket *31 *********************************************************************32 */33 struct fdsock {34 int indexFreeNext;35 struct socket *sock;36 };37 static struct fdsock *fdsock;38 static int fdsockCount;39 static int indexFreeHead = -1;40 41 /*42 * Convert an RTEMS file descriptor to a BSD socket pointer.43 */44 static struct socket *45 fdToSocket (int fd)46 {47 int i;48 struct socket *s;49 50 if ((fd < 0)51 || (rtems_file_descriptor_type(fd) != RTEMS_FILE_DESCRIPTOR_TYPE_SOCKET)52 || ((i = rtems_file_descriptor_base(fd)) >= fdsockCount)53 || ((s = fdsock[i].sock) == NULL)) {54 errno = EBADF;55 return NULL;56 }57 return s;58 }59 60 /*61 * Enlarge the size of the file-descritor/socket pointer map.62 */63 static int64 enlargeFdMap (void)65 {66 struct fdsock *nfdsock;67 int i;68 69 nfdsock = realloc (fdsock, sizeof *fdsock * (fdsockCount + 20));70 if (nfdsock == NULL) {71 errno = ENFILE;72 return 0;73 }74 fdsock = nfdsock;75 for (i = fdsockCount, fdsockCount += 20 ; i < fdsockCount ; i++) {76 fdsock[i].sock = NULL;77 fdsock[i].indexFreeNext = indexFreeHead;78 indexFreeHead = i;79 }80 return 1;81 }82 83 /*84 * Create a file descriptor for a new socket85 */86 static int87 makeFd (struct socket *s)88 {89 int i;90 91 if ((indexFreeHead < 0) && !enlargeFdMap ())92 return -1;93 i = indexFreeHead;94 indexFreeHead = fdsock[i].indexFreeNext;95 fdsock[i].sock = s;96 return rtems_make_file_descriptor(i,RTEMS_FILE_DESCRIPTOR_TYPE_SOCKET);97 }98 27 99 28 /* … … 129 58 socket (int domain, int type, int protocol) 130 59 { 131 int fd = -1;60 int fd; 132 61 int error; 133 62 struct socket *so; … … 136 65 error = socreate(domain, &so, type, protocol, NULL); 137 66 if (error == 0) { 138 fd = makeFd(so);67 fd = rtems_bsdnet_makeFdForSocket (so); 139 68 if (fd < 0) 140 69 soclose (so); … … 157 86 158 87 rtems_bsdnet_semaphore_obtain (); 159 if ((so = fdToSocket (s)) != NULL) {88 if ((so = rtems_bsdnet_fdToSocket (s)) != NULL) { 160 89 error = sockargstombuf (&nam, name, namelen, MT_SONAME); 161 90 if (error == 0) { … … 184 113 185 114 rtems_bsdnet_semaphore_obtain (); 186 if ((so = fdToSocket (s)) == NULL) {115 if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) { 187 116 rtems_bsdnet_semaphore_release (); 188 117 return -1; … … 234 163 235 164 rtems_bsdnet_semaphore_obtain (); 236 if ((so = fdToSocket (s)) != NULL) {165 if ((so = rtems_bsdnet_fdToSocket (s)) != NULL) { 237 166 error = solisten (so, backlog); 238 167 if (error == 0) … … 253 182 254 183 rtems_bsdnet_semaphore_obtain (); 255 if ((head = fdToSocket (s)) == NULL) {184 if ((head = rtems_bsdnet_fdToSocket (s)) == NULL) { 256 185 rtems_bsdnet_semaphore_release (); 257 186 return -1; … … 285 214 head->so_qlen--; 286 215 287 fd = makeFd(so);216 fd = rtems_bsdnet_makeFdForSocket (so); 288 217 if (fd < 0) { 289 218 TAILQ_INSERT_HEAD(&head->so_comp, so, so_list); … … 326 255 327 256 rtems_bsdnet_semaphore_obtain (); 328 if ((so = fdToSocket (s)) == NULL) {257 if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) { 329 258 rtems_bsdnet_semaphore_release (); 330 259 return -1; … … 429 358 430 359 rtems_bsdnet_semaphore_obtain (); 431 if ((so = fdToSocket (s)) == NULL) {360 if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) { 432 361 rtems_bsdnet_semaphore_release (); 433 362 return -1; … … 548 477 549 478 rtems_bsdnet_semaphore_obtain (); 550 if ((so = fdToSocket (s)) == NULL) {479 if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) { 551 480 rtems_bsdnet_semaphore_release (); 552 481 return -1; … … 585 514 586 515 rtems_bsdnet_semaphore_obtain (); 587 if ((so = fdToSocket (s)) == NULL) {516 if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) { 588 517 rtems_bsdnet_semaphore_release (); 589 518 return -1; … … 627 556 628 557 rtems_bsdnet_semaphore_obtain (); 629 if ((so = fdToSocket (s)) == NULL) {558 if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) { 630 559 rtems_bsdnet_semaphore_release (); 631 560 return -1; … … 677 606 struct socket *so; 678 607 int error; 679 int i; 680 681 rtems_bsdnet_semaphore_obtain (); 682 if ((so = fdToSocket (fd)) == NULL) { 683 rtems_bsdnet_semaphore_release (); 684 return -1; 685 } 686 i = rtems_file_descriptor_base(fd); 687 fdsock[i].indexFreeNext = indexFreeHead;; 688 indexFreeHead = i; 608 609 rtems_bsdnet_semaphore_obtain (); 610 if ((so = rtems_bsdnet_fdToSocket (fd)) == NULL) { 611 rtems_bsdnet_semaphore_release (); 612 return -1; 613 } 689 614 error = soclose (so); 690 615 rtems_bsdnet_semaphore_release (); … … 738 663 739 664 rtems_bsdnet_semaphore_obtain (); 740 if ((so = fdToSocket (fd)) == NULL) {665 if ((so = rtems_bsdnet_fdToSocket (fd)) == NULL) { 741 666 rtems_bsdnet_semaphore_release (); 742 667 return -1; -
c/src/lib/libnetworking/sys/sockio.h
r6c980128 rcca4400 84 84 #define SIOCGIFMEDIA _IOWR('i', 56, struct ifmediareq) /* get net media */ 85 85 86 87 86 /* 88 87 * RTEMS additions for setting/getting `tap' function on incoming packets. 89 88 */ 90 #define SIOCSIFTAP 91 #define SIOCGIFTAP _IOW R('i', 81, struct ifreq) /* get tap function */89 #define SIOCSIFTAP _IOW('i', 80, struct ifreq) /* set tap function */ 90 #define SIOCGIFTAP _IOW('i', 81, struct ifreq) /* get tap function */ 92 91 93 92 #endif /* !_SYS_SOCKIO_H_ */ -
c/src/libnetworking/rtems/Makefile.in
r6c980128 rcca4400 17 17 rtems_showmbuf rtems_showroute \ 18 18 rtems_showifstat rtems_showipstat rtems_showicmpstat \ 19 rtems_showtcpstat rtems_showudpstat 19 rtems_showtcpstat rtems_showudpstat rtems_select 20 20 C_FILES=$(C_PIECES:%=%.c) 21 21 C_O_FILES=$(C_PIECES:%=${ARCH}/%.o) -
c/src/libnetworking/rtems/rtems_glue.c
r6c980128 rcca4400 30 30 #include <net/netisr.h> 31 31 #include <net/route.h> 32 33 /*34 * Events used by networking routines.35 * Everything will break if the application36 * tries to use these events or if the `sleep'37 * events are equal to any of the NETISR * events.38 */39 #define SBWAIT_EVENT RTEMS_EVENT_2440 #define SOSLEEP_EVENT RTEMS_EVENT_2541 #define NETISR_IP_EVENT (1 << NETISR_IP)42 #define NETISR_ARP_EVENT (1 << NETISR_ARP)43 #define NETISR_EVENTS (NETISR_IP_EVENT|NETISR_ARP_EVENT)44 45 32 46 33 /* … … 247 234 * Register as an external I/O handler 248 235 */ 249 rtems_register_libio_handler ( RTEMS_FILE_DESCRIPTOR_TYPE_SOCKET,236 rtems_register_libio_handler (LIBIO_FLAGS_HANDLER_SOCK, 250 237 &rtems_bsdnet_io_handler); 251 238 … … 306 293 * Set this task as the target of the wakeup operation. 307 294 */ 308 if (sb->sb_sel.si_pid)309 rtems_panic ("Another task is already sleeping on that socket buffer");310 295 rtems_task_ident (RTEMS_SELF, 0, &tid); 311 296 sb->sb_sel.si_pid = tid; 312 297 313 298 /* 314 * Mark the socket buffer as waiting.315 */316 sb->sb_flags |= SB_WAIT;317 318 /*319 299 * Release the network semaphore. 320 300 */ … … 330 310 */ 331 311 rtems_bsdnet_semaphore_obtain (); 332 333 /*334 * Relinquish ownership of the socket buffer335 */336 sb->sb_flags &= ~SB_WAIT;337 sb->sb_sel.si_pid = 0;338 312 339 313 /* … … 356 330 register struct sockbuf *sb; 357 331 { 358 if (sb->sb_flags & SB_WAIT) { 359 sb->sb_flags &= ~SB_WAIT; 360 rtems_event_send (sb->sb_sel.si_pid, SBWAIT_EVENT); 332 rtems_id tid; 333 334 if ((tid = sb->sb_sel.si_pid) != 0) { 335 sb->sb_sel.si_pid = 0; 336 rtems_event_send (tid, SBWAIT_EVENT); 361 337 } 362 338 } -
c/src/libnetworking/rtems/rtems_syscall.c
r6c980128 rcca4400 25 25 #include <net/if.h> 26 26 #include <net/route.h> 27 28 /*29 *********************************************************************30 * Map RTEMS file descriptor to BSD socket *31 *********************************************************************32 */33 struct fdsock {34 int indexFreeNext;35 struct socket *sock;36 };37 static struct fdsock *fdsock;38 static int fdsockCount;39 static int indexFreeHead = -1;40 41 /*42 * Convert an RTEMS file descriptor to a BSD socket pointer.43 */44 static struct socket *45 fdToSocket (int fd)46 {47 int i;48 struct socket *s;49 50 if ((fd < 0)51 || (rtems_file_descriptor_type(fd) != RTEMS_FILE_DESCRIPTOR_TYPE_SOCKET)52 || ((i = rtems_file_descriptor_base(fd)) >= fdsockCount)53 || ((s = fdsock[i].sock) == NULL)) {54 errno = EBADF;55 return NULL;56 }57 return s;58 }59 60 /*61 * Enlarge the size of the file-descritor/socket pointer map.62 */63 static int64 enlargeFdMap (void)65 {66 struct fdsock *nfdsock;67 int i;68 69 nfdsock = realloc (fdsock, sizeof *fdsock * (fdsockCount + 20));70 if (nfdsock == NULL) {71 errno = ENFILE;72 return 0;73 }74 fdsock = nfdsock;75 for (i = fdsockCount, fdsockCount += 20 ; i < fdsockCount ; i++) {76 fdsock[i].sock = NULL;77 fdsock[i].indexFreeNext = indexFreeHead;78 indexFreeHead = i;79 }80 return 1;81 }82 83 /*84 * Create a file descriptor for a new socket85 */86 static int87 makeFd (struct socket *s)88 {89 int i;90 91 if ((indexFreeHead < 0) && !enlargeFdMap ())92 return -1;93 i = indexFreeHead;94 indexFreeHead = fdsock[i].indexFreeNext;95 fdsock[i].sock = s;96 return rtems_make_file_descriptor(i,RTEMS_FILE_DESCRIPTOR_TYPE_SOCKET);97 }98 27 99 28 /* … … 129 58 socket (int domain, int type, int protocol) 130 59 { 131 int fd = -1;60 int fd; 132 61 int error; 133 62 struct socket *so; … … 136 65 error = socreate(domain, &so, type, protocol, NULL); 137 66 if (error == 0) { 138 fd = makeFd(so);67 fd = rtems_bsdnet_makeFdForSocket (so); 139 68 if (fd < 0) 140 69 soclose (so); … … 157 86 158 87 rtems_bsdnet_semaphore_obtain (); 159 if ((so = fdToSocket (s)) != NULL) {88 if ((so = rtems_bsdnet_fdToSocket (s)) != NULL) { 160 89 error = sockargstombuf (&nam, name, namelen, MT_SONAME); 161 90 if (error == 0) { … … 184 113 185 114 rtems_bsdnet_semaphore_obtain (); 186 if ((so = fdToSocket (s)) == NULL) {115 if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) { 187 116 rtems_bsdnet_semaphore_release (); 188 117 return -1; … … 234 163 235 164 rtems_bsdnet_semaphore_obtain (); 236 if ((so = fdToSocket (s)) != NULL) {165 if ((so = rtems_bsdnet_fdToSocket (s)) != NULL) { 237 166 error = solisten (so, backlog); 238 167 if (error == 0) … … 253 182 254 183 rtems_bsdnet_semaphore_obtain (); 255 if ((head = fdToSocket (s)) == NULL) {184 if ((head = rtems_bsdnet_fdToSocket (s)) == NULL) { 256 185 rtems_bsdnet_semaphore_release (); 257 186 return -1; … … 285 214 head->so_qlen--; 286 215 287 fd = makeFd(so);216 fd = rtems_bsdnet_makeFdForSocket (so); 288 217 if (fd < 0) { 289 218 TAILQ_INSERT_HEAD(&head->so_comp, so, so_list); … … 326 255 327 256 rtems_bsdnet_semaphore_obtain (); 328 if ((so = fdToSocket (s)) == NULL) {257 if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) { 329 258 rtems_bsdnet_semaphore_release (); 330 259 return -1; … … 429 358 430 359 rtems_bsdnet_semaphore_obtain (); 431 if ((so = fdToSocket (s)) == NULL) {360 if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) { 432 361 rtems_bsdnet_semaphore_release (); 433 362 return -1; … … 548 477 549 478 rtems_bsdnet_semaphore_obtain (); 550 if ((so = fdToSocket (s)) == NULL) {479 if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) { 551 480 rtems_bsdnet_semaphore_release (); 552 481 return -1; … … 585 514 586 515 rtems_bsdnet_semaphore_obtain (); 587 if ((so = fdToSocket (s)) == NULL) {516 if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) { 588 517 rtems_bsdnet_semaphore_release (); 589 518 return -1; … … 627 556 628 557 rtems_bsdnet_semaphore_obtain (); 629 if ((so = fdToSocket (s)) == NULL) {558 if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) { 630 559 rtems_bsdnet_semaphore_release (); 631 560 return -1; … … 677 606 struct socket *so; 678 607 int error; 679 int i; 680 681 rtems_bsdnet_semaphore_obtain (); 682 if ((so = fdToSocket (fd)) == NULL) { 683 rtems_bsdnet_semaphore_release (); 684 return -1; 685 } 686 i = rtems_file_descriptor_base(fd); 687 fdsock[i].indexFreeNext = indexFreeHead;; 688 indexFreeHead = i; 608 609 rtems_bsdnet_semaphore_obtain (); 610 if ((so = rtems_bsdnet_fdToSocket (fd)) == NULL) { 611 rtems_bsdnet_semaphore_release (); 612 return -1; 613 } 689 614 error = soclose (so); 690 615 rtems_bsdnet_semaphore_release (); … … 738 663 739 664 rtems_bsdnet_semaphore_obtain (); 740 if ((so = fdToSocket (fd)) == NULL) {665 if ((so = rtems_bsdnet_fdToSocket (fd)) == NULL) { 741 666 rtems_bsdnet_semaphore_release (); 742 667 return -1; -
c/src/libnetworking/sys/sockio.h
r6c980128 rcca4400 84 84 #define SIOCGIFMEDIA _IOWR('i', 56, struct ifmediareq) /* get net media */ 85 85 86 87 86 /* 88 87 * RTEMS additions for setting/getting `tap' function on incoming packets. 89 88 */ 90 #define SIOCSIFTAP 91 #define SIOCGIFTAP _IOW R('i', 81, struct ifreq) /* get tap function */89 #define SIOCSIFTAP _IOW('i', 80, struct ifreq) /* set tap function */ 90 #define SIOCGIFTAP _IOW('i', 81, struct ifreq) /* get tap function */ 92 91 93 92 #endif /* !_SYS_SOCKIO_H_ */ -
configure
r6c980128 rcca4400 807 807 esac 808 808 else 809 RTEMS_HAS_RDBG= yes809 RTEMS_HAS_RDBG=no 810 810 fi 811 811 -
configure.in
r6c980128 rcca4400 50 50 no) RTEMS_HAS_RDBG=no ;; 51 51 *) AC_MSG_ERROR(bad value ${enableval} for enable-rdbg option) ;; 52 esac],[RTEMS_HAS_RDBG= yes])52 esac],[RTEMS_HAS_RDBG=no]) 53 53 54 54 AC_ARG_ENABLE(rtems-inlines, \ -
cpukit/include/rtems/libio_.h
r6c980128 rcca4400 66 66 extern rtems_libio_t *rtems_libio_iops; 67 67 extern rtems_libio_t *rtems_libio_last_iop; 68 extern rtems_libio_t *rtems_libio_iop_freelist; 68 69 69 70 /* -
cpukit/libcsupport/include/rtems/libio.h
r6c980128 rcca4400 394 394 #define LIBIO_FLAGS_READ 0x0002 /* reading */ 395 395 #define LIBIO_FLAGS_WRITE 0x0004 /* writing */ 396 #define LIBIO_FLAGS_LINE_BUFFERED 0x0008 /* line buffered io (^h, ^u, etc) */397 396 #define LIBIO_FLAGS_OPEN 0x0100 /* device is open */ 398 397 #define LIBIO_FLAGS_APPEND 0x0200 /* all writes append */ 399 398 #define LIBIO_FLAGS_CREATE 0x0400 /* create file */ 400 399 #define LIBIO_FLAGS_CLOSE_ON_EXEC 0x0800 /* close on process exec() */ 400 401 #define LIBIO_FLAGS_HANDLER_SHIFT 12 402 #define LIBIO_FLAGS_HANDLER_MASK 0xF000 /* mask for external handler type */ 403 #define LIBIO_FLAGS_HANDLER_RTEMS 0x0000 /* `traditional' RTEMS I/O */ 404 #define LIBIO_FLAGS_HANDLER_SOCK 0x1000 /* BSD socket */ 401 405 402 406 #define LIBIO_FLAGS_READ_WRITE (LIBIO_FLAGS_READ | LIBIO_FLAGS_WRITE) -
cpukit/libcsupport/include/rtems/libio_.h
r6c980128 rcca4400 66 66 extern rtems_libio_t *rtems_libio_iops; 67 67 extern rtems_libio_t *rtems_libio_last_iop; 68 extern rtems_libio_t *rtems_libio_iop_freelist; 68 69 69 70 /* -
cpukit/libcsupport/include/sys/sockio.h
r6c980128 rcca4400 84 84 #define SIOCGIFMEDIA _IOWR('i', 56, struct ifmediareq) /* get net media */ 85 85 86 87 86 /* 88 87 * RTEMS additions for setting/getting `tap' function on incoming packets. 89 88 */ 90 #define SIOCSIFTAP 91 #define SIOCGIFTAP _IOW R('i', 81, struct ifreq) /* get tap function */89 #define SIOCSIFTAP _IOW('i', 80, struct ifreq) /* set tap function */ 90 #define SIOCGIFTAP _IOW('i', 81, struct ifreq) /* get tap function */ 92 91 93 92 #endif /* !_SYS_SOCKIO_H_ */ -
cpukit/libcsupport/src/close.c
r6c980128 rcca4400 23 23 int status; 24 24 25 if ( rtems_file_descriptor_type( fd ) ) { 25 rtems_libio_check_fd(fd); 26 iop = rtems_libio_iop(fd); 27 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) { 26 28 int (*fp)(int fd); 27 29 28 fp = rtems_libio_handlers[rtems_file_descriptor_type_index(fd)].close; 30 fp = rtems_libio_handlers[ 31 (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].close; 29 32 if ( fp == NULL ) 30 33 set_errno_and_return_minus_one( EBADF ); … … 32 35 return status; 33 36 } 34 iop = rtems_libio_iop(fd);35 rtems_libio_check_fd(fd);36 37 37 38 if ( !iop->handlers ) -
cpukit/libcsupport/src/fchmod.c
r6c980128 rcca4400 28 28 rtems_libio_t *iop; 29 29 30 rtems_libio_check_fd( fd ); 31 iop = rtems_libio_iop( fd ); 32 30 33 /* 31 34 * If this is not a file system based entity, it is an error. 32 35 */ 33 36 34 if ( rtems_file_descriptor_type( fd ))37 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) 35 38 set_errno_and_return_minus_one( EBADF ); 36 39 … … 39 42 */ 40 43 41 iop = rtems_libio_iop( fd );42 rtems_libio_check_fd( fd );43 44 rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE ); 44 45 -
cpukit/libcsupport/src/fcntl.c
r6c980128 rcca4400 33 33 va_start( ap, cmd ); 34 34 35 rtems_libio_check_fd( fd ); 36 iop = rtems_libio_iop( fd ); 37 35 38 /* 36 39 * If this is not a file system based entity, it is an error. 37 40 */ 38 41 39 if ( rtems_file_descriptor_type( fd ))42 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) 40 43 set_errno_and_return_minus_one( EBADF ); 41 44 … … 43 46 * Now process the fcntl(). 44 47 */ 45 46 iop = rtems_libio_iop( fd );47 rtems_libio_check_fd( fd );48 48 49 49 /* -
cpukit/libcsupport/src/fdatasync.c
r6c980128 rcca4400 23 23 rtems_libio_t *iop; 24 24 25 rtems_libio_check_fd( fd ); 26 iop = rtems_libio_iop( fd ); 27 rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE ); 28 25 29 /* 26 30 * If this file descriptor is mapped to an external set of handlers, … … 28 32 */ 29 33 30 if ( rtems_file_descriptor_type( fd ))34 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) 31 35 set_errno_and_return_minus_one( EBADF ); 32 36 … … 35 39 */ 36 40 37 iop = rtems_libio_iop( fd );38 rtems_libio_check_fd( fd );39 rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE );40 41 41 if ( !iop->handlers->fdatasync ) 42 42 set_errno_and_return_minus_one( ENOTSUP ); -
cpukit/libcsupport/src/fpathconf.c
r6c980128 rcca4400 27 27 rtems_filesystem_limits_and_options_t *the_limits; 28 28 29 rtems_libio_check_fd(fd); 30 iop = rtems_libio_iop(fd); 31 rtems_libio_check_permissions(iop, LIBIO_FLAGS_READ); 32 29 33 /* 30 34 * If this file descriptor is mapped to an external set of handlers, … … 33 37 */ 34 38 35 if ( rtems_file_descriptor_type( fd ))39 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) 36 40 set_errno_and_return_minus_one( EBADF ); 37 41 … … 39 43 * Now process the information request. 40 44 */ 41 42 iop = rtems_libio_iop(fd);43 rtems_libio_check_fd(fd);44 rtems_libio_check_permissions(iop, LIBIO_FLAGS_READ);45 45 46 46 the_limits = &iop->pathinfo.mt_entry->pathconf_limits_and_options; -
cpukit/libcsupport/src/fsync.c
r6c980128 rcca4400 23 23 rtems_libio_t *iop; 24 24 25 rtems_libio_check_fd( fd ); 26 iop = rtems_libio_iop( fd ); 27 rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE ); 28 25 29 /* 26 30 * If this file descriptor is mapped to an external set of handlers, … … 28 32 */ 29 33 30 if ( rtems_file_descriptor_type( fd ))34 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) 31 35 set_errno_and_return_minus_one( EBADF ); 32 36 … … 35 39 */ 36 40 37 iop = rtems_libio_iop( fd );38 rtems_libio_check_fd( fd );39 rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE );40 41 41 if ( !iop->handlers->fsync ) 42 42 set_errno_and_return_minus_one( ENOTSUP ); -
cpukit/libcsupport/src/ftruncate.c
r6c980128 rcca4400 26 26 rtems_filesystem_location_info_t loc; 27 27 28 rtems_libio_check_fd( fd ); 29 iop = rtems_libio_iop( fd ); 30 28 31 /* 29 32 * If this is not a file system based entity, it is an error. 30 33 */ 31 34 32 if ( rtems_file_descriptor_type( fd ))35 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) 33 36 set_errno_and_return_minus_one( EBADF ); 34 37 … … 37 40 */ 38 41 39 iop = rtems_libio_iop( fd );40 41 42 /* 42 43 * Make sure we are not working on a directory … … 50 51 set_errno_and_return_minus_one( EISDIR ); 51 52 52 rtems_libio_check_fd( fd );53 53 rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE ); 54 54 -
cpukit/libcsupport/src/ioctl.c
r6c980128 rcca4400 27 27 rtems_libio_t *iop; 28 28 29 rtems_libio_check_fd( fd ); 30 iop = rtems_libio_iop( fd ); 31 29 32 /* 30 33 * If this file descriptor is mapped to an external set of handlers, … … 32 35 */ 33 36 34 if ( rtems_file_descriptor_type( fd )) {37 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) { 35 38 rtems_libio_ioctl_t fp; 36 39 37 fp = rtems_libio_handlers[rtems_file_descriptor_type_index(fd)].ioctl; 40 fp = rtems_libio_handlers[ 41 (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].ioctl; 38 42 if ( fp == NULL ) 39 43 set_errno_and_return_minus_one( EBADF ); … … 46 50 */ 47 51 48 iop = rtems_libio_iop( fd );49 rtems_libio_check_fd( fd );50 51 52 if ( !iop->handlers->ioctl ) 52 53 set_errno_and_return_minus_one( ENOTSUP ); -
cpukit/libcsupport/src/libio.c
r6c980128 rcca4400 4 4 * POSIX system calls like open(), read, fstat(), etc. 5 5 * 6 * This provides the foundation for POSIX compliant IO system calls7 * for RTEMS.8 *9 6 * COPYRIGHT (c) 1989-1998. 10 7 * On-Line Applications Research Corporation (OAR). … … 19 16 20 17 #include "libio_.h" /* libio_.h pulls in rtems */ 21 22 /* 23 * Global variables used to manage the File Descriptor Table. 24 * IOP = IO Pointer. 25 */ 26 27 rtems_id rtems_libio_semaphore; 28 rtems_libio_t *rtems_libio_iops; 29 rtems_libio_t *rtems_libio_last_iop; 18 #include <rtems.h> 19 #include <rtems/assoc.h> /* assoc.h not included by rtems.h */ 20 21 #include <stdio.h> /* O_RDONLY, et.al. */ 22 #include <fcntl.h> /* O_RDONLY, et.al. */ 23 #include <assert.h> 24 #include <errno.h> 25 26 #if ! defined(O_NDELAY) 27 # if defined(solaris2) 28 # define O_NDELAY O_NONBLOCK 29 # elif defined(RTEMS_NEWLIB) 30 # define O_NDELAY _FNBIO 31 # endif 32 #endif 33 34 35 #include <errno.h> 36 #include <string.h> /* strcmp */ 37 #include <unistd.h> 38 #include <stdlib.h> /* calloc() */ 39 40 #include "libio.h" /* libio.h not pulled in by rtems */ 41 42 /* 43 * File descriptor Table Information 44 */ 45 46 extern unsigned32 rtems_libio_number_iops; 47 rtems_id rtems_libio_semaphore; 48 rtems_libio_t *rtems_libio_iops; 49 rtems_libio_t *rtems_libio_last_iop; 50 rtems_libio_t *rtems_libio_iop_freelist; 51 52 /* 53 * External I/O Handlers Table 54 * 55 * Space for all possible handlers is preallocated 56 * to speed up dispatch to external handlers. 57 */ 58 30 59 rtems_libio_handler_t rtems_libio_handlers[15]; 60 61 /* 62 * Default mode for all files. 63 */ 64 65 mode_t rtems_filesystem_umask; 31 66 32 67 /* … … 45 80 ) 46 81 { 47 int handler_index = rtems_file_descriptor_type_index( handler_flag ); 48 82 int handler_index = (handler_flag >> LIBIO_FLAGS_HANDLER_SHIFT) - 1; 49 83 50 84 if ((handler_index < 0) || (handler_index >= 15)) … … 62 96 void rtems_libio_init( void ) 63 97 { 64 rtems_status_code rc; 65 66 /* 67 * Allocate memory for the IOP Table 68 */ 69 70 if ( rtems_libio_number_iops > 0 ) { 71 rtems_libio_iops = 72 (rtems_libio_t *) calloc(rtems_libio_number_iops, sizeof(rtems_libio_t)); 73 74 if (rtems_libio_iops == NULL) 75 rtems_fatal_error_occurred( RTEMS_NO_MEMORY ); 76 77 rtems_libio_last_iop = rtems_libio_iops + (rtems_libio_number_iops - 1); 78 } 98 rtems_status_code rc; 99 int i; 100 rtems_libio_t *iop; 101 102 if (rtems_libio_number_iops > 0) 103 { 104 rtems_libio_iops = (rtems_libio_t *) calloc(rtems_libio_number_iops, 105 sizeof(rtems_libio_t)); 106 if (rtems_libio_iops == NULL) 107 rtems_fatal_error_occurred(RTEMS_NO_MEMORY); 108 109 iop = rtems_libio_iop_freelist = rtems_libio_iops; 110 for (i = 0 ; i < (rtems_libio_number_iops - 1) ; i++, iop++) 111 iop->data1 = iop + 1; 112 iop->data1 = NULL; 113 } 79 114 80 115 /* … … 158 193 rtems_semaphore_obtain( rtems_libio_semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT ); 159 194 160 for (iop = rtems_libio_iops; iop <= rtems_libio_last_iop; iop++) 161 if ((iop->flags & LIBIO_FLAGS_OPEN) == 0) { 162 /* 163 * Got an IOP -- create a semaphore for it. 164 */ 165 166 rc = rtems_semaphore_create( 167 RTEMS_LIBIO_IOP_SEM(iop - rtems_libio_iops), 168 1, 169 RTEMS_BINARY_SEMAPHORE | RTEMS_INHERIT_PRIORITY | RTEMS_PRIORITY, 170 RTEMS_NO_PRIORITY, 171 &iop->sem 172 ); 173 if ( rc != RTEMS_SUCCESSFUL ) 174 goto failed; 175 176 iop->flags = LIBIO_FLAGS_OPEN; 177 goto done; 195 if (rtems_libio_iop_freelist) { 196 iop = rtems_libio_iop_freelist; 197 rc = rtems_semaphore_create( 198 RTEMS_LIBIO_IOP_SEM(iop - rtems_libio_iops), 199 1, 200 RTEMS_BINARY_SEMAPHORE | RTEMS_INHERIT_PRIORITY | RTEMS_PRIORITY, 201 RTEMS_NO_PRIORITY, 202 &iop->sem 203 ); 204 if (rc != RTEMS_SUCCESSFUL) 205 goto failed; 206 rtems_libio_iop_freelist = iop->data1; 207 iop->data1 = 0; 208 iop->flags = LIBIO_FLAGS_OPEN; 209 goto done; 178 210 } 179 211 … … 199 231 rtems_semaphore_obtain( rtems_libio_semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT ); 200 232 201 if (iop->sem) 202 rtems_semaphore_delete(iop->sem); 203 204 (void) memset(iop, 0, sizeof(*iop)); 205 206 rtems_semaphore_release( rtems_libio_semaphore ); 233 if (iop->sem) 234 rtems_semaphore_delete(iop->sem); 235 236 iop->data1 = rtems_libio_iop_freelist; 237 rtems_libio_iop_freelist = iop; 238 239 rtems_semaphore_release(rtems_libio_semaphore); 207 240 } 208 241 … … 211 244 * 212 245 * This routine scans the entire file descriptor table to determine if the 213 * are any active file descriptors that refer to the at least one node in the246 * are any active file descriptors that refer to the at least one node in the 214 247 * file system that we are trying to dismount. 215 248 * … … 226 259 227 260 rtems_semaphore_obtain( rtems_libio_semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT ); 228 261 229 262 /* 230 263 * Look for any active file descriptor entry. 231 */ 232 264 */ 265 233 266 for ( iop=rtems_libio_iops ; iop <= rtems_libio_last_iop ; iop++ ) { 234 267 235 268 if ((iop->flags & LIBIO_FLAGS_OPEN) != 0) { 236 269 237 270 /* 238 271 * Check if this node is under the file system that we 239 272 * are trying to dismount. 240 */ 273 */ 241 274 242 275 if ( iop->pathinfo.mt_entry == fs_mt_entry ) { … … 248 281 249 282 rtems_semaphore_release( rtems_libio_semaphore ); 250 283 251 284 return result; 252 285 } … … 257 290 * This routine scans the entire file descriptor table to determine if the 258 291 * given file refers to an active file descriptor. 259 * 292 * 260 293 * If the given file is open a 1 is returned, otherwise a 0 is returned. 261 294 */ … … 266 299 { 267 300 rtems_libio_t *iop; 268 int result=0; 301 int result=0; 269 302 270 303 rtems_semaphore_obtain( rtems_libio_semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT ); … … 273 306 * Look for any active file descriptor entry. 274 307 */ 275 308 276 309 for ( iop=rtems_libio_iops ; iop <= rtems_libio_last_iop ; iop++ ) { 277 310 278 311 if ((iop->flags & LIBIO_FLAGS_OPEN) != 0) { 279 312 280 313 /* 281 314 * Check if this node is under the file system that we 282 315 * are trying to dismount. 283 */ 316 */ 284 317 285 318 if ( iop->pathinfo.node_access == node_access ) { … … 294 327 return result; 295 328 } 329 330 -
cpukit/libcsupport/src/lseek.c
r6c980128 rcca4400 25 25 rtems_libio_t *iop; 26 26 27 rtems_libio_check_fd( fd ); 28 iop = rtems_libio_iop( fd ); 29 27 30 /* 28 31 * If this file descriptor is mapped to an external set of handlers, … … 30 33 */ 31 34 32 if ( rtems_file_descriptor_type( fd )) {35 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) { 33 36 rtems_libio_lseek_t fp; 34 37 35 fp = rtems_libio_handlers[rtems_file_descriptor_type_index(fd)].lseek; 38 fp = rtems_libio_handlers[ 39 (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].lseek; 36 40 if ( fp == NULL ) 37 41 set_errno_and_return_minus_one( EBADF ); … … 43 47 * Now process the lseek(). 44 48 */ 45 46 iop = rtems_libio_iop( fd );47 rtems_libio_check_fd( fd );48 49 49 50 switch ( whence ) { -
cpukit/libcsupport/src/read.c
r6c980128 rcca4400 27 27 rtems_libio_t *iop; 28 28 29 rtems_libio_check_fd( fd ); 30 iop = rtems_libio_iop( fd ); 31 rtems_libio_check_buffer( buffer ); 32 rtems_libio_check_count( count ); 33 rtems_libio_check_permissions( iop, LIBIO_FLAGS_READ ); 34 29 35 /* 30 36 * If this file descriptor is mapped to an external set of handlers, … … 32 38 */ 33 39 34 if ( rtems_file_descriptor_type( fd )) {40 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) { 35 41 rtems_libio_read_t fp; 36 42 37 fp = rtems_libio_handlers[rtems_file_descriptor_type_index(fd)].read; 43 fp = rtems_libio_handlers[ 44 (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].read; 38 45 if ( fp == NULL ) 39 46 set_errno_and_return_minus_one( EBADF ); … … 45 52 * Now process the read(). 46 53 */ 47 48 iop = rtems_libio_iop( fd );49 rtems_libio_check_fd( fd );50 rtems_libio_check_buffer( buffer );51 rtems_libio_check_count( count );52 rtems_libio_check_permissions( iop, LIBIO_FLAGS_READ );53 54 54 55 if ( !iop->handlers->read ) -
cpukit/libcsupport/src/write.c
r6c980128 rcca4400 35 35 rtems_libio_t *iop; 36 36 37 rtems_libio_check_fd( fd ); 38 iop = rtems_libio_iop( fd ); 39 rtems_libio_check_buffer( buffer ); 40 rtems_libio_check_count( count ); 41 rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE ); 42 37 43 /* 38 44 * If this file descriptor is mapped to an external set of handlers, … … 40 46 */ 41 47 42 if ( rtems_file_descriptor_type( fd )) {48 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) { 43 49 rtems_libio_write_t fp; 44 50 45 fp = rtems_libio_handlers[rtems_file_descriptor_type_index(fd)].write; 51 fp = rtems_libio_handlers[ 52 (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].write; 46 53 if ( fp == NULL ) 47 54 set_errno_and_return_minus_one( EBADF ); … … 53 60 * Now process the write() request. 54 61 */ 55 56 iop = rtems_libio_iop( fd );57 rtems_libio_check_fd( fd );58 rtems_libio_check_buffer( buffer );59 rtems_libio_check_count( count );60 rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE );61 62 62 63 if ( !iop->handlers->write ) -
cpukit/libnetworking/rtems/rtems_glue.c
r6c980128 rcca4400 30 30 #include <net/netisr.h> 31 31 #include <net/route.h> 32 33 /*34 * Events used by networking routines.35 * Everything will break if the application36 * tries to use these events or if the `sleep'37 * events are equal to any of the NETISR * events.38 */39 #define SBWAIT_EVENT RTEMS_EVENT_2440 #define SOSLEEP_EVENT RTEMS_EVENT_2541 #define NETISR_IP_EVENT (1 << NETISR_IP)42 #define NETISR_ARP_EVENT (1 << NETISR_ARP)43 #define NETISR_EVENTS (NETISR_IP_EVENT|NETISR_ARP_EVENT)44 45 32 46 33 /* … … 247 234 * Register as an external I/O handler 248 235 */ 249 rtems_register_libio_handler ( RTEMS_FILE_DESCRIPTOR_TYPE_SOCKET,236 rtems_register_libio_handler (LIBIO_FLAGS_HANDLER_SOCK, 250 237 &rtems_bsdnet_io_handler); 251 238 … … 306 293 * Set this task as the target of the wakeup operation. 307 294 */ 308 if (sb->sb_sel.si_pid)309 rtems_panic ("Another task is already sleeping on that socket buffer");310 295 rtems_task_ident (RTEMS_SELF, 0, &tid); 311 296 sb->sb_sel.si_pid = tid; 312 297 313 298 /* 314 * Mark the socket buffer as waiting.315 */316 sb->sb_flags |= SB_WAIT;317 318 /*319 299 * Release the network semaphore. 320 300 */ … … 330 310 */ 331 311 rtems_bsdnet_semaphore_obtain (); 332 333 /*334 * Relinquish ownership of the socket buffer335 */336 sb->sb_flags &= ~SB_WAIT;337 sb->sb_sel.si_pid = 0;338 312 339 313 /* … … 356 330 register struct sockbuf *sb; 357 331 { 358 if (sb->sb_flags & SB_WAIT) { 359 sb->sb_flags &= ~SB_WAIT; 360 rtems_event_send (sb->sb_sel.si_pid, SBWAIT_EVENT); 332 rtems_id tid; 333 334 if ((tid = sb->sb_sel.si_pid) != 0) { 335 sb->sb_sel.si_pid = 0; 336 rtems_event_send (tid, SBWAIT_EVENT); 361 337 } 362 338 } -
cpukit/libnetworking/rtems/rtems_syscall.c
r6c980128 rcca4400 25 25 #include <net/if.h> 26 26 #include <net/route.h> 27 28 /*29 *********************************************************************30 * Map RTEMS file descriptor to BSD socket *31 *********************************************************************32 */33 struct fdsock {34 int indexFreeNext;35 struct socket *sock;36 };37 static struct fdsock *fdsock;38 static int fdsockCount;39 static int indexFreeHead = -1;40 41 /*42 * Convert an RTEMS file descriptor to a BSD socket pointer.43 */44 static struct socket *45 fdToSocket (int fd)46 {47 int i;48 struct socket *s;49 50 if ((fd < 0)51 || (rtems_file_descriptor_type(fd) != RTEMS_FILE_DESCRIPTOR_TYPE_SOCKET)52 || ((i = rtems_file_descriptor_base(fd)) >= fdsockCount)53 || ((s = fdsock[i].sock) == NULL)) {54 errno = EBADF;55 return NULL;56 }57 return s;58 }59 60 /*61 * Enlarge the size of the file-descritor/socket pointer map.62 */63 static int64 enlargeFdMap (void)65 {66 struct fdsock *nfdsock;67 int i;68 69 nfdsock = realloc (fdsock, sizeof *fdsock * (fdsockCount + 20));70 if (nfdsock == NULL) {71 errno = ENFILE;72 return 0;73 }74 fdsock = nfdsock;75 for (i = fdsockCount, fdsockCount += 20 ; i < fdsockCount ; i++) {76 fdsock[i].sock = NULL;77 fdsock[i].indexFreeNext = indexFreeHead;78 indexFreeHead = i;79 }80 return 1;81 }82 83 /*84 * Create a file descriptor for a new socket85 */86 static int87 makeFd (struct socket *s)88 {89 int i;90 91 if ((indexFreeHead < 0) && !enlargeFdMap ())92 return -1;93 i = indexFreeHead;94 indexFreeHead = fdsock[i].indexFreeNext;95 fdsock[i].sock = s;96 return rtems_make_file_descriptor(i,RTEMS_FILE_DESCRIPTOR_TYPE_SOCKET);97 }98 27 99 28 /* … … 129 58 socket (int domain, int type, int protocol) 130 59 { 131 int fd = -1;60 int fd; 132 61 int error; 133 62 struct socket *so; … … 136 65 error = socreate(domain, &so, type, protocol, NULL); 137 66 if (error == 0) { 138 fd = makeFd(so);67 fd = rtems_bsdnet_makeFdForSocket (so); 139 68 if (fd < 0) 140 69 soclose (so); … … 157 86 158 87 rtems_bsdnet_semaphore_obtain (); 159 if ((so = fdToSocket (s)) != NULL) {88 if ((so = rtems_bsdnet_fdToSocket (s)) != NULL) { 160 89 error = sockargstombuf (&nam, name, namelen, MT_SONAME); 161 90 if (error == 0) { … … 184 113 185 114 rtems_bsdnet_semaphore_obtain (); 186 if ((so = fdToSocket (s)) == NULL) {115 if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) { 187 116 rtems_bsdnet_semaphore_release (); 188 117 return -1; … … 234 163 235 164 rtems_bsdnet_semaphore_obtain (); 236 if ((so = fdToSocket (s)) != NULL) {165 if ((so = rtems_bsdnet_fdToSocket (s)) != NULL) { 237 166 error = solisten (so, backlog); 238 167 if (error == 0) … … 253 182 254 183 rtems_bsdnet_semaphore_obtain (); 255 if ((head = fdToSocket (s)) == NULL) {184 if ((head = rtems_bsdnet_fdToSocket (s)) == NULL) { 256 185 rtems_bsdnet_semaphore_release (); 257 186 return -1; … … 285 214 head->so_qlen--; 286 215 287 fd = makeFd(so);216 fd = rtems_bsdnet_makeFdForSocket (so); 288 217 if (fd < 0) { 289 218 TAILQ_INSERT_HEAD(&head->so_comp, so, so_list); … … 326 255 327 256 rtems_bsdnet_semaphore_obtain (); 328 if ((so = fdToSocket (s)) == NULL) {257 if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) { 329 258 rtems_bsdnet_semaphore_release (); 330 259 return -1; … … 429 358 430 359 rtems_bsdnet_semaphore_obtain (); 431 if ((so = fdToSocket (s)) == NULL) {360 if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) { 432 361 rtems_bsdnet_semaphore_release (); 433 362 return -1; … … 548 477 549 478 rtems_bsdnet_semaphore_obtain (); 550 if ((so = fdToSocket (s)) == NULL) {479 if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) { 551 480 rtems_bsdnet_semaphore_release (); 552 481 return -1; … … 585 514 586 515 rtems_bsdnet_semaphore_obtain (); 587 if ((so = fdToSocket (s)) == NULL) {516 if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) { 588 517 rtems_bsdnet_semaphore_release (); 589 518 return -1; … … 627 556 628 557 rtems_bsdnet_semaphore_obtain (); 629 if ((so = fdToSocket (s)) == NULL) {558 if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) { 630 559 rtems_bsdnet_semaphore_release (); 631 560 return -1; … … 677 606 struct socket *so; 678 607 int error; 679 int i; 680 681 rtems_bsdnet_semaphore_obtain (); 682 if ((so = fdToSocket (fd)) == NULL) { 683 rtems_bsdnet_semaphore_release (); 684 return -1; 685 } 686 i = rtems_file_descriptor_base(fd); 687 fdsock[i].indexFreeNext = indexFreeHead;; 688 indexFreeHead = i; 608 609 rtems_bsdnet_semaphore_obtain (); 610 if ((so = rtems_bsdnet_fdToSocket (fd)) == NULL) { 611 rtems_bsdnet_semaphore_release (); 612 return -1; 613 } 689 614 error = soclose (so); 690 615 rtems_bsdnet_semaphore_release (); … … 738 663 739 664 rtems_bsdnet_semaphore_obtain (); 740 if ((so = fdToSocket (fd)) == NULL) {665 if ((so = rtems_bsdnet_fdToSocket (fd)) == NULL) { 741 666 rtems_bsdnet_semaphore_release (); 742 667 return -1;
Note: See TracChangeset
for help on using the changeset viewer.