Changeset 73f6236 in rtems
- Timestamp:
- 03/01/99 22:40:08 (25 years ago)
- Branches:
- 4.10, 4.11, 4.8, 4.9, 5, master
- Children:
- 9d81380
- Parents:
- e069cdc3
- Files:
-
- 68 edited
Legend:
- Unmodified
- Added
- Removed
-
c/src/exec/include/rtems/libio_.h
re069cdc3 r73f6236 67 67 extern rtems_libio_t *rtems_libio_last_iop; 68 68 extern rtems_libio_t *rtems_libio_iop_freelist; 69 70 /*71 * External I/O Handlers Table72 *73 * Space for all possible handlers is preallocated74 * to speed up dispatch to external handlers.75 */76 77 extern rtems_libio_handler_t rtems_libio_handlers[15];78 69 79 70 /* -
c/src/exec/libcsupport/include/rtems/libio.h
re069cdc3 r73f6236 398 398 #define LIBIO_FLAGS_CREATE 0x0400 /* create file */ 399 399 #define LIBIO_FLAGS_CLOSE_ON_EXEC 0x0800 /* close on process exec() */ 400 401 #define LIBIO_FLAGS_HANDLER_SHIFT 12402 #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 */405 406 400 #define LIBIO_FLAGS_READ_WRITE (LIBIO_FLAGS_READ | LIBIO_FLAGS_WRITE) 407 408 401 409 402 void rtems_libio_init(void); … … 446 439 int whence 447 440 ); 448 449 typedef struct {450 rtems_libio_open_t open;451 rtems_libio_close_t close;452 rtems_libio_read_t read;453 rtems_libio_write_t write;454 rtems_libio_ioctl_t ioctl;455 rtems_libio_lseek_t lseek;456 } rtems_libio_handler_t;457 458 /*459 * Register a set of external handlers460 */461 462 void rtems_register_libio_handler(463 int handler_flag,464 const rtems_libio_handler_t *handler465 );466 467 /*468 * Macros to assist in management of external IO handlers.469 */470 471 #define RTEMS_FILE_DESCRIPTOR_TYPE_FILE 0x0000472 #define RTEMS_FILE_DESCRIPTOR_TYPE_SOCKET 0x1000473 #define rtems_make_file_descriptor(fd,flags) ((fd)|(flags))474 #define rtems_file_descriptor_base(fd) ((fd) & 0x0FFF)475 #define rtems_file_descriptor_type(fd) ((fd) & 0xF000)476 #define rtems_file_descriptor_type_index(fd) ((((fd) & 0xF000) >> 12) - 1)477 441 478 442 /* -
c/src/exec/libcsupport/include/rtems/libio_.h
re069cdc3 r73f6236 67 67 extern rtems_libio_t *rtems_libio_last_iop; 68 68 extern rtems_libio_t *rtems_libio_iop_freelist; 69 70 /*71 * External I/O Handlers Table72 *73 * Space for all possible handlers is preallocated74 * to speed up dispatch to external handlers.75 */76 77 extern rtems_libio_handler_t rtems_libio_handlers[15];78 69 79 70 /* -
c/src/exec/libcsupport/src/close.c
re069cdc3 r73f6236 21 21 rtems_libio_t *iop; 22 22 rtems_status_code rc; 23 int status;24 23 25 24 rtems_libio_check_fd(fd); 26 25 iop = rtems_libio_iop(fd); 27 26 rtems_libio_check_is_open(iop); 28 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) {29 int (*fp)(int fd);30 27 31 fp = rtems_libio_handlers[ 32 (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].close; 33 if ( fp == NULL ) 34 set_errno_and_return_minus_one( EBADF ); 35 status = (*fp)( fd ); 36 return status; 37 } 38 39 if ( !iop->handlers ) 40 set_errno_and_return_minus_one( EBADF ); 41 42 if ( !iop->handlers->close ) 43 set_errno_and_return_minus_one( ENOTSUP ); 44 45 rc = (*iop->handlers->close)( iop ); 28 rc = RTEMS_SUCCESSFUL; 29 if ( iop->handlers->close ) 30 rc = (*iop->handlers->close)( iop ); 46 31 47 32 rtems_libio_free( iop ); 48 49 if (rc != RTEMS_SUCCESSFUL)50 set_errno_and_return_minus_one( rc );51 33 52 34 return rc; -
c/src/exec/libcsupport/src/fchmod.c
re069cdc3 r73f6236 33 33 34 34 /* 35 * If this is not a file system based entity, it is an error.36 */37 38 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK )39 set_errno_and_return_minus_one( EBADF );40 41 /*42 35 * Now process the fchmod(). 43 36 */ -
c/src/exec/libcsupport/src/fcntl.c
re069cdc3 r73f6236 36 36 iop = rtems_libio_iop( fd ); 37 37 rtems_libio_check_is_open(iop); 38 39 /*40 * If this is not a file system based entity, it is an error.41 */42 43 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK )44 set_errno_and_return_minus_one( EBADF );45 38 46 39 /* -
c/src/exec/libcsupport/src/fdatasync.c
re069cdc3 r73f6236 29 29 30 30 /* 31 * If this file descriptor is mapped to an external set of handlers,32 * then pass the request on to them.33 */34 35 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK )36 set_errno_and_return_minus_one( EBADF );37 38 /*39 31 * Now process the fdatasync(). 40 32 */ -
c/src/exec/libcsupport/src/fpathconf.c
re069cdc3 r73f6236 31 31 rtems_libio_check_is_open(iop); 32 32 rtems_libio_check_permissions(iop, LIBIO_FLAGS_READ); 33 34 /*35 * If this file descriptor is mapped to an external set of handlers,36 * then it is an error since fpathconf() is not included in the37 * set.38 */39 40 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK )41 set_errno_and_return_minus_one( EBADF );42 33 43 34 /* -
c/src/exec/libcsupport/src/fstat.c
re069cdc3 r73f6236 34 34 35 35 /* 36 * Zero out the stat structure so the various support37 * versions of stat don't have to.38 */39 40 memset( sbuf, 0, sizeof(struct stat) );41 42 /*43 * If this file descriptor is mapped to an external set of handlers,44 * then pass the request on to them.45 */46 47 if (rtems_file_descriptor_type(fd)) {48 switch (rtems_file_descriptor_type (fd)) {49 case RTEMS_FILE_DESCRIPTOR_TYPE_FILE:50 break;51 52 case RTEMS_FILE_DESCRIPTOR_TYPE_SOCKET:53 #if !defined(__GO32__)54 sbuf->st_mode = S_IFSOCK;55 break;56 #endif57 58 default:59 set_errno_and_return_minus_one( EBADF );60 }61 }62 63 /*64 36 * Now process the stat() request. 65 37 */ … … 69 41 rtems_libio_check_is_open(iop); 70 42 43 if ( !iop->handlers ) 44 set_errno_and_return_minus_one( EBADF ); 45 71 46 if ( !iop->handlers->fstat ) 72 47 set_errno_and_return_minus_one( ENOTSUP ); 48 49 /* 50 * Zero out the stat structure so the various support 51 * versions of stat don't have to. 52 */ 53 memset( sbuf, 0, sizeof(struct stat) ); 73 54 74 55 return (*iop->handlers->fstat)( &iop->pathinfo, sbuf ); -
c/src/exec/libcsupport/src/fsync.c
re069cdc3 r73f6236 29 29 30 30 /* 31 * If this file descriptor is mapped to an external set of handlers,32 * then pass the request on to them.33 */34 35 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK )36 set_errno_and_return_minus_one( EBADF );37 38 /*39 31 * Now process the fsync(). 40 32 */ -
c/src/exec/libcsupport/src/ftruncate.c
re069cdc3 r73f6236 31 31 32 32 /* 33 * If this is not a file system based entity, it is an error.34 */35 36 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK )37 set_errno_and_return_minus_one( EBADF );38 39 /*40 33 * Now process the ftruncate() request. 41 34 */ -
c/src/exec/libcsupport/src/ioctl.c
re069cdc3 r73f6236 32 32 33 33 /* 34 * If this file descriptor is mapped to an external set of handlers,35 * then pass the request on to them.36 */37 38 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) {39 rtems_libio_ioctl_t fp;40 41 fp = rtems_libio_handlers[42 (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].ioctl;43 if ( fp == NULL )44 set_errno_and_return_minus_one( EBADF );45 46 return (*fp)( fd, command, buffer );47 }48 49 /*50 34 * Now process the ioctl(). 51 35 */ -
c/src/exec/libcsupport/src/libio.c
re069cdc3 r73f6236 51 51 52 52 /* 53 * External I/O Handlers Table54 *55 * Space for all possible handlers is preallocated56 * to speed up dispatch to external handlers.57 */58 59 rtems_libio_handler_t rtems_libio_handlers[15];60 61 /*62 53 * Default mode for all files. 63 54 */ 64 55 65 56 mode_t rtems_filesystem_umask; 66 67 /*68 * rtems_register_libio_handler69 *70 * This function registers an external IO handler set. This lets71 * other subsystems have their own versions of many of the system72 * calls. For example, the networking code registers handlers which73 * map the system calls for read() and write() to socket calls.74 *75 */76 77 void rtems_register_libio_handler(78 int handler_flag,79 const rtems_libio_handler_t *handler80 )81 {82 int handler_index = (handler_flag >> LIBIO_FLAGS_HANDLER_SHIFT) - 1;83 84 if ((handler_index < 0) || (handler_index >= 15))85 rtems_fatal_error_occurred( RTEMS_INVALID_NUMBER );86 87 rtems_libio_handlers[handler_index] = *handler;88 }89 57 90 58 /* -
c/src/exec/libcsupport/src/libio_sockets.c
re069cdc3 r73f6236 19 19 #include <errno.h> 20 20 21 22 21 /* 23 22 * Convert an RTEMS file descriptor to a BSD socket pointer. … … 30 29 rtems_libio_t *iop; 31 30 32 if ((unsigned32)fd >= rtems_libio_number_iops) 33 return NULL; 31 if ((unsigned32)fd >= rtems_libio_number_iops) { 32 errno = EBADF; 33 return NULL; 34 } 34 35 iop = &rtems_libio_iops[fd]; 35 if ( (iop->flags & LIBIO_FLAGS_HANDLER_MASK) != LIBIO_FLAGS_HANDLER_SOCK)36 return NULL;36 if (iop->data1 == NULL) 37 errno = EBADF; 37 38 return iop->data1; 38 39 } … … 43 44 44 45 int rtems_bsdnet_makeFdForSocket( 45 void *so 46 void *so, 47 const rtems_filesystem_file_handlers_r *h 46 48 ) 47 49 { 48 50 rtems_libio_t *iop; 51 int fd; 49 52 50 53 iop = rtems_libio_allocate(); … … 53 56 return -1; 54 57 } 55 iop->flags |= LIBIO_FLAGS_HANDLER_SOCK | LIBIO_FLAGS_WRITE | LIBIO_FLAGS_READ; 58 fd = iop - rtems_libio_iops; 59 iop->flags |= LIBIO_FLAGS_WRITE | LIBIO_FLAGS_READ; 60 iop->data0 = fd; 56 61 iop->data1 = so; 57 return iop - rtems_libio_iops; 62 iop->handlers = h; 63 return fd; 58 64 } -
c/src/exec/libcsupport/src/lseek.c
re069cdc3 r73f6236 28 28 iop = rtems_libio_iop( fd ); 29 29 rtems_libio_check_is_open(iop); 30 31 /*32 * If this file descriptor is mapped to an external set of handlers,33 * then pass the request on to them.34 */35 36 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) {37 rtems_libio_lseek_t fp;38 39 fp = rtems_libio_handlers[40 (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].lseek;41 if ( fp == NULL )42 set_errno_and_return_minus_one( EBADF );43 44 return (*fp)( fd, offset, whence );45 }46 30 47 31 /* -
c/src/exec/libcsupport/src/read.c
re069cdc3 r73f6236 30 30 rtems_libio_check_count( count ); 31 31 rtems_libio_check_permissions( iop, LIBIO_FLAGS_READ ); 32 33 /*34 * If this file descriptor is mapped to an external set of handlers,35 * then pass the request on to them.36 */37 38 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) {39 rtems_libio_read_t fp;40 41 fp = rtems_libio_handlers[42 (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].read;43 if ( fp == NULL )44 set_errno_and_return_minus_one( EBADF );45 46 return (*fp)( fd, buffer, count );47 }48 32 49 33 /* -
c/src/exec/libcsupport/src/write.c
re069cdc3 r73f6236 40 40 41 41 /* 42 * If this file descriptor is mapped to an external set of handlers,43 * then pass the request on to them.44 */45 46 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) {47 rtems_libio_write_t fp;48 49 fp = rtems_libio_handlers[50 (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].write;51 if ( fp == NULL )52 set_errno_and_return_minus_one( EBADF );53 54 return (*fp)( fd, buffer, count );55 }56 57 /*58 42 * Now process the write() request. 59 43 */ -
c/src/exec/libnetworking/rtems/rtems_bsdnet_internal.h
re069cdc3 r73f6236 175 175 int socket (int, int, int); 176 176 int ioctl (int, unsigned long, ...); 177 struct socket *rtems_bsdnet_fdToSocket (int fd);178 int rtems_bsdnet_makeFdForSocket (void *);179 177 180 178 /* -
c/src/exec/libnetworking/rtems/rtems_glue.c
re069cdc3 r73f6236 78 78 sizeof rtems_bsdnet_config.name_server[0]]; 79 79 int rtems_bsdnet_nameserver_count; 80 81 extern rtems_libio_handler_t rtems_bsdnet_io_handler;82 80 83 81 /* … … 230 228 */ 231 229 networkDaemonTid = rtems_bsdnet_newproc ("ntwk", 4096, networkDaemon, NULL); 232 233 /*234 * Register as an external I/O handler235 */236 rtems_register_libio_handler (LIBIO_FLAGS_HANDLER_SOCK,237 &rtems_bsdnet_io_handler);238 230 239 231 /* -
c/src/exec/libnetworking/rtems/rtems_select.c
re069cdc3 r73f6236 47 47 48 48 static __inline int imin(int a, int b) { return (a < b ? a : b); } 49 struct socket *rtems_bsdnet_fdToSocket(int fd); 49 50 50 51 static int -
c/src/exec/libnetworking/rtems/rtems_syscall.c
re069cdc3 r73f6236 25 25 #include <net/if.h> 26 26 #include <net/route.h> 27 28 /* 29 * Hooks to RTEMS I/O system 30 */ 31 static const rtems_filesystem_file_handlers_r socket_handlers; 32 int rtems_bsdnet_makeFdForSocket(void *so, const rtems_filesystem_file_handlers_r *h); 33 struct socket *rtems_bsdnet_fdToSocket(int fd); 27 34 28 35 /* … … 65 72 error = socreate(domain, &so, type, protocol, NULL); 66 73 if (error == 0) { 67 fd = rtems_bsdnet_makeFdForSocket (so );74 fd = rtems_bsdnet_makeFdForSocket (so, &socket_handlers); 68 75 if (fd < 0) 69 76 soclose (so); … … 214 221 head->so_qlen--; 215 222 216 fd = rtems_bsdnet_makeFdForSocket (so );223 fd = rtems_bsdnet_makeFdForSocket (so, &socket_handlers); 217 224 if (fd < 0) { 218 225 TAILQ_INSERT_HEAD(&head->so_comp, so, so_list); … … 601 608 /* 602 609 ************************************************************************ 603 * RTEMS EXTERNAL I/O HANDLER ROUTINES*610 * RTEMS I/O HANDLER ROUTINES * 604 611 ************************************************************************ 605 612 */ 606 613 static int 607 rtems_bsdnet_close (int fd) 608 { 609 struct socket *so; 610 int error; 611 612 rtems_bsdnet_semaphore_obtain (); 613 if ((so = rtems_bsdnet_fdToSocket (fd)) == NULL) { 614 rtems_bsdnet_close (rtems_libio_t *iop) 615 { 616 struct socket *so; 617 int error; 618 619 rtems_bsdnet_semaphore_obtain (); 620 if ((so = iop->data1) == NULL) { 621 errno = EBADF; 614 622 rtems_bsdnet_semaphore_release (); 615 623 return -1; … … 625 633 626 634 static int 627 rtems_bsdnet_read ( int fd, void *buffer, unsigned32 count)628 { 629 return recv ( fd, buffer, count, 0);635 rtems_bsdnet_read (rtems_libio_t *iop, void *buffer, unsigned32 count) 636 { 637 return recv (iop->data0, buffer, count, 0); 630 638 } 631 639 632 640 static int 633 rtems_bsdnet_write ( int fd, const void *buffer, unsigned32 count)634 { 635 return send ( fd, buffer, count, 0);641 rtems_bsdnet_write (rtems_libio_t *iop, const void *buffer, unsigned32 count) 642 { 643 return send (iop->data0, buffer, count, 0); 636 644 } 637 645 … … 660 668 661 669 static int 662 rtems_bsdnet_ioctl (int fd, unsigned32 command, void *buffer) 663 { 664 struct socket *so; 665 int error; 666 667 rtems_bsdnet_semaphore_obtain (); 668 if ((so = rtems_bsdnet_fdToSocket (fd)) == NULL) { 670 rtems_bsdnet_ioctl (rtems_libio_t *iop, unsigned32 command, void *buffer) 671 { 672 struct socket *so; 673 int error; 674 675 rtems_bsdnet_semaphore_obtain (); 676 if ((so = iop->data1) == NULL) { 677 errno = EBADF; 669 678 rtems_bsdnet_semaphore_release (); 670 679 return -1; … … 679 688 } 680 689 681 rtems_libio_handler_t rtems_bsdnet_io_handler = { 690 static int 691 rtems_bsdnet_fstat (rtems_filesystem_location_info_t *loc, struct stat *sp) 692 { 693 sp->st_mode = S_IFSOCK; 694 return 0; 695 } 696 697 static const rtems_filesystem_file_handlers_r socket_handlers = { 682 698 NULL, /* open */ 683 699 rtems_bsdnet_close, /* close */ … … 686 702 rtems_bsdnet_ioctl, /* ioctl */ 687 703 NULL, /* lseek */ 704 rtems_bsdnet_fstat, /* fstat */ 705 NULL, /* fchmod */ 706 NULL, /* ftruncate */ 707 NULL, /* fpathconf */ 708 NULL, /* fsync */ 709 NULL, /* fdatasync */ 688 710 }; 689 -
c/src/lib/include/rtems/libio.h
re069cdc3 r73f6236 398 398 #define LIBIO_FLAGS_CREATE 0x0400 /* create file */ 399 399 #define LIBIO_FLAGS_CLOSE_ON_EXEC 0x0800 /* close on process exec() */ 400 401 #define LIBIO_FLAGS_HANDLER_SHIFT 12402 #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 */405 406 400 #define LIBIO_FLAGS_READ_WRITE (LIBIO_FLAGS_READ | LIBIO_FLAGS_WRITE) 407 408 401 409 402 void rtems_libio_init(void); … … 446 439 int whence 447 440 ); 448 449 typedef struct {450 rtems_libio_open_t open;451 rtems_libio_close_t close;452 rtems_libio_read_t read;453 rtems_libio_write_t write;454 rtems_libio_ioctl_t ioctl;455 rtems_libio_lseek_t lseek;456 } rtems_libio_handler_t;457 458 /*459 * Register a set of external handlers460 */461 462 void rtems_register_libio_handler(463 int handler_flag,464 const rtems_libio_handler_t *handler465 );466 467 /*468 * Macros to assist in management of external IO handlers.469 */470 471 #define RTEMS_FILE_DESCRIPTOR_TYPE_FILE 0x0000472 #define RTEMS_FILE_DESCRIPTOR_TYPE_SOCKET 0x1000473 #define rtems_make_file_descriptor(fd,flags) ((fd)|(flags))474 #define rtems_file_descriptor_base(fd) ((fd) & 0x0FFF)475 #define rtems_file_descriptor_type(fd) ((fd) & 0xF000)476 #define rtems_file_descriptor_type_index(fd) ((((fd) & 0xF000) >> 12) - 1)477 441 478 442 /* -
c/src/lib/include/rtems/libio_.h
re069cdc3 r73f6236 67 67 extern rtems_libio_t *rtems_libio_last_iop; 68 68 extern rtems_libio_t *rtems_libio_iop_freelist; 69 70 /*71 * External I/O Handlers Table72 *73 * Space for all possible handlers is preallocated74 * to speed up dispatch to external handlers.75 */76 77 extern rtems_libio_handler_t rtems_libio_handlers[15];78 69 79 70 /* -
c/src/lib/libc/close.c
re069cdc3 r73f6236 21 21 rtems_libio_t *iop; 22 22 rtems_status_code rc; 23 int status;24 23 25 24 rtems_libio_check_fd(fd); 26 25 iop = rtems_libio_iop(fd); 27 26 rtems_libio_check_is_open(iop); 28 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) {29 int (*fp)(int fd);30 27 31 fp = rtems_libio_handlers[ 32 (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].close; 33 if ( fp == NULL ) 34 set_errno_and_return_minus_one( EBADF ); 35 status = (*fp)( fd ); 36 return status; 37 } 38 39 if ( !iop->handlers ) 40 set_errno_and_return_minus_one( EBADF ); 41 42 if ( !iop->handlers->close ) 43 set_errno_and_return_minus_one( ENOTSUP ); 44 45 rc = (*iop->handlers->close)( iop ); 28 rc = RTEMS_SUCCESSFUL; 29 if ( iop->handlers->close ) 30 rc = (*iop->handlers->close)( iop ); 46 31 47 32 rtems_libio_free( iop ); 48 49 if (rc != RTEMS_SUCCESSFUL)50 set_errno_and_return_minus_one( rc );51 33 52 34 return rc; -
c/src/lib/libc/fchmod.c
re069cdc3 r73f6236 33 33 34 34 /* 35 * If this is not a file system based entity, it is an error.36 */37 38 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK )39 set_errno_and_return_minus_one( EBADF );40 41 /*42 35 * Now process the fchmod(). 43 36 */ -
c/src/lib/libc/fcntl.c
re069cdc3 r73f6236 36 36 iop = rtems_libio_iop( fd ); 37 37 rtems_libio_check_is_open(iop); 38 39 /*40 * If this is not a file system based entity, it is an error.41 */42 43 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK )44 set_errno_and_return_minus_one( EBADF );45 38 46 39 /* -
c/src/lib/libc/fdatasync.c
re069cdc3 r73f6236 29 29 30 30 /* 31 * If this file descriptor is mapped to an external set of handlers,32 * then pass the request on to them.33 */34 35 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK )36 set_errno_and_return_minus_one( EBADF );37 38 /*39 31 * Now process the fdatasync(). 40 32 */ -
c/src/lib/libc/fpathconf.c
re069cdc3 r73f6236 31 31 rtems_libio_check_is_open(iop); 32 32 rtems_libio_check_permissions(iop, LIBIO_FLAGS_READ); 33 34 /*35 * If this file descriptor is mapped to an external set of handlers,36 * then it is an error since fpathconf() is not included in the37 * set.38 */39 40 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK )41 set_errno_and_return_minus_one( EBADF );42 33 43 34 /* -
c/src/lib/libc/fstat.c
re069cdc3 r73f6236 34 34 35 35 /* 36 * Zero out the stat structure so the various support37 * versions of stat don't have to.38 */39 40 memset( sbuf, 0, sizeof(struct stat) );41 42 /*43 * If this file descriptor is mapped to an external set of handlers,44 * then pass the request on to them.45 */46 47 if (rtems_file_descriptor_type(fd)) {48 switch (rtems_file_descriptor_type (fd)) {49 case RTEMS_FILE_DESCRIPTOR_TYPE_FILE:50 break;51 52 case RTEMS_FILE_DESCRIPTOR_TYPE_SOCKET:53 #if !defined(__GO32__)54 sbuf->st_mode = S_IFSOCK;55 break;56 #endif57 58 default:59 set_errno_and_return_minus_one( EBADF );60 }61 }62 63 /*64 36 * Now process the stat() request. 65 37 */ … … 69 41 rtems_libio_check_is_open(iop); 70 42 43 if ( !iop->handlers ) 44 set_errno_and_return_minus_one( EBADF ); 45 71 46 if ( !iop->handlers->fstat ) 72 47 set_errno_and_return_minus_one( ENOTSUP ); 48 49 /* 50 * Zero out the stat structure so the various support 51 * versions of stat don't have to. 52 */ 53 memset( sbuf, 0, sizeof(struct stat) ); 73 54 74 55 return (*iop->handlers->fstat)( &iop->pathinfo, sbuf ); -
c/src/lib/libc/fsync.c
re069cdc3 r73f6236 29 29 30 30 /* 31 * If this file descriptor is mapped to an external set of handlers,32 * then pass the request on to them.33 */34 35 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK )36 set_errno_and_return_minus_one( EBADF );37 38 /*39 31 * Now process the fsync(). 40 32 */ -
c/src/lib/libc/ftruncate.c
re069cdc3 r73f6236 31 31 32 32 /* 33 * If this is not a file system based entity, it is an error.34 */35 36 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK )37 set_errno_and_return_minus_one( EBADF );38 39 /*40 33 * Now process the ftruncate() request. 41 34 */ -
c/src/lib/libc/ioctl.c
re069cdc3 r73f6236 32 32 33 33 /* 34 * If this file descriptor is mapped to an external set of handlers,35 * then pass the request on to them.36 */37 38 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) {39 rtems_libio_ioctl_t fp;40 41 fp = rtems_libio_handlers[42 (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].ioctl;43 if ( fp == NULL )44 set_errno_and_return_minus_one( EBADF );45 46 return (*fp)( fd, command, buffer );47 }48 49 /*50 34 * Now process the ioctl(). 51 35 */ -
c/src/lib/libc/libio.c
re069cdc3 r73f6236 51 51 52 52 /* 53 * External I/O Handlers Table54 *55 * Space for all possible handlers is preallocated56 * to speed up dispatch to external handlers.57 */58 59 rtems_libio_handler_t rtems_libio_handlers[15];60 61 /*62 53 * Default mode for all files. 63 54 */ 64 55 65 56 mode_t rtems_filesystem_umask; 66 67 /*68 * rtems_register_libio_handler69 *70 * This function registers an external IO handler set. This lets71 * other subsystems have their own versions of many of the system72 * calls. For example, the networking code registers handlers which73 * map the system calls for read() and write() to socket calls.74 *75 */76 77 void rtems_register_libio_handler(78 int handler_flag,79 const rtems_libio_handler_t *handler80 )81 {82 int handler_index = (handler_flag >> LIBIO_FLAGS_HANDLER_SHIFT) - 1;83 84 if ((handler_index < 0) || (handler_index >= 15))85 rtems_fatal_error_occurred( RTEMS_INVALID_NUMBER );86 87 rtems_libio_handlers[handler_index] = *handler;88 }89 57 90 58 /* -
c/src/lib/libc/libio.h
re069cdc3 r73f6236 398 398 #define LIBIO_FLAGS_CREATE 0x0400 /* create file */ 399 399 #define LIBIO_FLAGS_CLOSE_ON_EXEC 0x0800 /* close on process exec() */ 400 401 #define LIBIO_FLAGS_HANDLER_SHIFT 12402 #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 */405 406 400 #define LIBIO_FLAGS_READ_WRITE (LIBIO_FLAGS_READ | LIBIO_FLAGS_WRITE) 407 408 401 409 402 void rtems_libio_init(void); … … 446 439 int whence 447 440 ); 448 449 typedef struct {450 rtems_libio_open_t open;451 rtems_libio_close_t close;452 rtems_libio_read_t read;453 rtems_libio_write_t write;454 rtems_libio_ioctl_t ioctl;455 rtems_libio_lseek_t lseek;456 } rtems_libio_handler_t;457 458 /*459 * Register a set of external handlers460 */461 462 void rtems_register_libio_handler(463 int handler_flag,464 const rtems_libio_handler_t *handler465 );466 467 /*468 * Macros to assist in management of external IO handlers.469 */470 471 #define RTEMS_FILE_DESCRIPTOR_TYPE_FILE 0x0000472 #define RTEMS_FILE_DESCRIPTOR_TYPE_SOCKET 0x1000473 #define rtems_make_file_descriptor(fd,flags) ((fd)|(flags))474 #define rtems_file_descriptor_base(fd) ((fd) & 0x0FFF)475 #define rtems_file_descriptor_type(fd) ((fd) & 0xF000)476 #define rtems_file_descriptor_type_index(fd) ((((fd) & 0xF000) >> 12) - 1)477 441 478 442 /* -
c/src/lib/libc/libio_.h
re069cdc3 r73f6236 67 67 extern rtems_libio_t *rtems_libio_last_iop; 68 68 extern rtems_libio_t *rtems_libio_iop_freelist; 69 70 /*71 * External I/O Handlers Table72 *73 * Space for all possible handlers is preallocated74 * to speed up dispatch to external handlers.75 */76 77 extern rtems_libio_handler_t rtems_libio_handlers[15];78 69 79 70 /* -
c/src/lib/libc/libio_sockets.c
re069cdc3 r73f6236 19 19 #include <errno.h> 20 20 21 22 21 /* 23 22 * Convert an RTEMS file descriptor to a BSD socket pointer. … … 30 29 rtems_libio_t *iop; 31 30 32 if ((unsigned32)fd >= rtems_libio_number_iops) 33 return NULL; 31 if ((unsigned32)fd >= rtems_libio_number_iops) { 32 errno = EBADF; 33 return NULL; 34 } 34 35 iop = &rtems_libio_iops[fd]; 35 if ( (iop->flags & LIBIO_FLAGS_HANDLER_MASK) != LIBIO_FLAGS_HANDLER_SOCK)36 return NULL;36 if (iop->data1 == NULL) 37 errno = EBADF; 37 38 return iop->data1; 38 39 } … … 43 44 44 45 int rtems_bsdnet_makeFdForSocket( 45 void *so 46 void *so, 47 const rtems_filesystem_file_handlers_r *h 46 48 ) 47 49 { 48 50 rtems_libio_t *iop; 51 int fd; 49 52 50 53 iop = rtems_libio_allocate(); … … 53 56 return -1; 54 57 } 55 iop->flags |= LIBIO_FLAGS_HANDLER_SOCK | LIBIO_FLAGS_WRITE | LIBIO_FLAGS_READ; 58 fd = iop - rtems_libio_iops; 59 iop->flags |= LIBIO_FLAGS_WRITE | LIBIO_FLAGS_READ; 60 iop->data0 = fd; 56 61 iop->data1 = so; 57 return iop - rtems_libio_iops; 62 iop->handlers = h; 63 return fd; 58 64 } -
c/src/lib/libc/lseek.c
re069cdc3 r73f6236 28 28 iop = rtems_libio_iop( fd ); 29 29 rtems_libio_check_is_open(iop); 30 31 /*32 * If this file descriptor is mapped to an external set of handlers,33 * then pass the request on to them.34 */35 36 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) {37 rtems_libio_lseek_t fp;38 39 fp = rtems_libio_handlers[40 (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].lseek;41 if ( fp == NULL )42 set_errno_and_return_minus_one( EBADF );43 44 return (*fp)( fd, offset, whence );45 }46 30 47 31 /* -
c/src/lib/libc/read.c
re069cdc3 r73f6236 30 30 rtems_libio_check_count( count ); 31 31 rtems_libio_check_permissions( iop, LIBIO_FLAGS_READ ); 32 33 /*34 * If this file descriptor is mapped to an external set of handlers,35 * then pass the request on to them.36 */37 38 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) {39 rtems_libio_read_t fp;40 41 fp = rtems_libio_handlers[42 (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].read;43 if ( fp == NULL )44 set_errno_and_return_minus_one( EBADF );45 46 return (*fp)( fd, buffer, count );47 }48 32 49 33 /* -
c/src/lib/libc/write.c
re069cdc3 r73f6236 40 40 41 41 /* 42 * If this file descriptor is mapped to an external set of handlers,43 * then pass the request on to them.44 */45 46 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) {47 rtems_libio_write_t fp;48 49 fp = rtems_libio_handlers[50 (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].write;51 if ( fp == NULL )52 set_errno_and_return_minus_one( EBADF );53 54 return (*fp)( fd, buffer, count );55 }56 57 /*58 42 * Now process the write() request. 59 43 */ -
c/src/lib/libnetworking/rtems/rtems_bsdnet_internal.h
re069cdc3 r73f6236 175 175 int socket (int, int, int); 176 176 int ioctl (int, unsigned long, ...); 177 struct socket *rtems_bsdnet_fdToSocket (int fd);178 int rtems_bsdnet_makeFdForSocket (void *);179 177 180 178 /* -
c/src/lib/libnetworking/rtems/rtems_glue.c
re069cdc3 r73f6236 78 78 sizeof rtems_bsdnet_config.name_server[0]]; 79 79 int rtems_bsdnet_nameserver_count; 80 81 extern rtems_libio_handler_t rtems_bsdnet_io_handler;82 80 83 81 /* … … 230 228 */ 231 229 networkDaemonTid = rtems_bsdnet_newproc ("ntwk", 4096, networkDaemon, NULL); 232 233 /*234 * Register as an external I/O handler235 */236 rtems_register_libio_handler (LIBIO_FLAGS_HANDLER_SOCK,237 &rtems_bsdnet_io_handler);238 230 239 231 /* -
c/src/lib/libnetworking/rtems/rtems_select.c
re069cdc3 r73f6236 47 47 48 48 static __inline int imin(int a, int b) { return (a < b ? a : b); } 49 struct socket *rtems_bsdnet_fdToSocket(int fd); 49 50 50 51 static int -
c/src/lib/libnetworking/rtems/rtems_syscall.c
re069cdc3 r73f6236 25 25 #include <net/if.h> 26 26 #include <net/route.h> 27 28 /* 29 * Hooks to RTEMS I/O system 30 */ 31 static const rtems_filesystem_file_handlers_r socket_handlers; 32 int rtems_bsdnet_makeFdForSocket(void *so, const rtems_filesystem_file_handlers_r *h); 33 struct socket *rtems_bsdnet_fdToSocket(int fd); 27 34 28 35 /* … … 65 72 error = socreate(domain, &so, type, protocol, NULL); 66 73 if (error == 0) { 67 fd = rtems_bsdnet_makeFdForSocket (so );74 fd = rtems_bsdnet_makeFdForSocket (so, &socket_handlers); 68 75 if (fd < 0) 69 76 soclose (so); … … 214 221 head->so_qlen--; 215 222 216 fd = rtems_bsdnet_makeFdForSocket (so );223 fd = rtems_bsdnet_makeFdForSocket (so, &socket_handlers); 217 224 if (fd < 0) { 218 225 TAILQ_INSERT_HEAD(&head->so_comp, so, so_list); … … 601 608 /* 602 609 ************************************************************************ 603 * RTEMS EXTERNAL I/O HANDLER ROUTINES*610 * RTEMS I/O HANDLER ROUTINES * 604 611 ************************************************************************ 605 612 */ 606 613 static int 607 rtems_bsdnet_close (int fd) 608 { 609 struct socket *so; 610 int error; 611 612 rtems_bsdnet_semaphore_obtain (); 613 if ((so = rtems_bsdnet_fdToSocket (fd)) == NULL) { 614 rtems_bsdnet_close (rtems_libio_t *iop) 615 { 616 struct socket *so; 617 int error; 618 619 rtems_bsdnet_semaphore_obtain (); 620 if ((so = iop->data1) == NULL) { 621 errno = EBADF; 614 622 rtems_bsdnet_semaphore_release (); 615 623 return -1; … … 625 633 626 634 static int 627 rtems_bsdnet_read ( int fd, void *buffer, unsigned32 count)628 { 629 return recv ( fd, buffer, count, 0);635 rtems_bsdnet_read (rtems_libio_t *iop, void *buffer, unsigned32 count) 636 { 637 return recv (iop->data0, buffer, count, 0); 630 638 } 631 639 632 640 static int 633 rtems_bsdnet_write ( int fd, const void *buffer, unsigned32 count)634 { 635 return send ( fd, buffer, count, 0);641 rtems_bsdnet_write (rtems_libio_t *iop, const void *buffer, unsigned32 count) 642 { 643 return send (iop->data0, buffer, count, 0); 636 644 } 637 645 … … 660 668 661 669 static int 662 rtems_bsdnet_ioctl (int fd, unsigned32 command, void *buffer) 663 { 664 struct socket *so; 665 int error; 666 667 rtems_bsdnet_semaphore_obtain (); 668 if ((so = rtems_bsdnet_fdToSocket (fd)) == NULL) { 670 rtems_bsdnet_ioctl (rtems_libio_t *iop, unsigned32 command, void *buffer) 671 { 672 struct socket *so; 673 int error; 674 675 rtems_bsdnet_semaphore_obtain (); 676 if ((so = iop->data1) == NULL) { 677 errno = EBADF; 669 678 rtems_bsdnet_semaphore_release (); 670 679 return -1; … … 679 688 } 680 689 681 rtems_libio_handler_t rtems_bsdnet_io_handler = { 690 static int 691 rtems_bsdnet_fstat (rtems_filesystem_location_info_t *loc, struct stat *sp) 692 { 693 sp->st_mode = S_IFSOCK; 694 return 0; 695 } 696 697 static const rtems_filesystem_file_handlers_r socket_handlers = { 682 698 NULL, /* open */ 683 699 rtems_bsdnet_close, /* close */ … … 686 702 rtems_bsdnet_ioctl, /* ioctl */ 687 703 NULL, /* lseek */ 704 rtems_bsdnet_fstat, /* fstat */ 705 NULL, /* fchmod */ 706 NULL, /* ftruncate */ 707 NULL, /* fpathconf */ 708 NULL, /* fsync */ 709 NULL, /* fdatasync */ 688 710 }; 689 -
c/src/libnetworking/rtems/rtems_bsdnet_internal.h
re069cdc3 r73f6236 175 175 int socket (int, int, int); 176 176 int ioctl (int, unsigned long, ...); 177 struct socket *rtems_bsdnet_fdToSocket (int fd);178 int rtems_bsdnet_makeFdForSocket (void *);179 177 180 178 /* -
c/src/libnetworking/rtems/rtems_glue.c
re069cdc3 r73f6236 78 78 sizeof rtems_bsdnet_config.name_server[0]]; 79 79 int rtems_bsdnet_nameserver_count; 80 81 extern rtems_libio_handler_t rtems_bsdnet_io_handler;82 80 83 81 /* … … 230 228 */ 231 229 networkDaemonTid = rtems_bsdnet_newproc ("ntwk", 4096, networkDaemon, NULL); 232 233 /*234 * Register as an external I/O handler235 */236 rtems_register_libio_handler (LIBIO_FLAGS_HANDLER_SOCK,237 &rtems_bsdnet_io_handler);238 230 239 231 /* -
c/src/libnetworking/rtems/rtems_select.c
re069cdc3 r73f6236 47 47 48 48 static __inline int imin(int a, int b) { return (a < b ? a : b); } 49 struct socket *rtems_bsdnet_fdToSocket(int fd); 49 50 50 51 static int -
c/src/libnetworking/rtems/rtems_syscall.c
re069cdc3 r73f6236 25 25 #include <net/if.h> 26 26 #include <net/route.h> 27 28 /* 29 * Hooks to RTEMS I/O system 30 */ 31 static const rtems_filesystem_file_handlers_r socket_handlers; 32 int rtems_bsdnet_makeFdForSocket(void *so, const rtems_filesystem_file_handlers_r *h); 33 struct socket *rtems_bsdnet_fdToSocket(int fd); 27 34 28 35 /* … … 65 72 error = socreate(domain, &so, type, protocol, NULL); 66 73 if (error == 0) { 67 fd = rtems_bsdnet_makeFdForSocket (so );74 fd = rtems_bsdnet_makeFdForSocket (so, &socket_handlers); 68 75 if (fd < 0) 69 76 soclose (so); … … 214 221 head->so_qlen--; 215 222 216 fd = rtems_bsdnet_makeFdForSocket (so );223 fd = rtems_bsdnet_makeFdForSocket (so, &socket_handlers); 217 224 if (fd < 0) { 218 225 TAILQ_INSERT_HEAD(&head->so_comp, so, so_list); … … 601 608 /* 602 609 ************************************************************************ 603 * RTEMS EXTERNAL I/O HANDLER ROUTINES*610 * RTEMS I/O HANDLER ROUTINES * 604 611 ************************************************************************ 605 612 */ 606 613 static int 607 rtems_bsdnet_close (int fd) 608 { 609 struct socket *so; 610 int error; 611 612 rtems_bsdnet_semaphore_obtain (); 613 if ((so = rtems_bsdnet_fdToSocket (fd)) == NULL) { 614 rtems_bsdnet_close (rtems_libio_t *iop) 615 { 616 struct socket *so; 617 int error; 618 619 rtems_bsdnet_semaphore_obtain (); 620 if ((so = iop->data1) == NULL) { 621 errno = EBADF; 614 622 rtems_bsdnet_semaphore_release (); 615 623 return -1; … … 625 633 626 634 static int 627 rtems_bsdnet_read ( int fd, void *buffer, unsigned32 count)628 { 629 return recv ( fd, buffer, count, 0);635 rtems_bsdnet_read (rtems_libio_t *iop, void *buffer, unsigned32 count) 636 { 637 return recv (iop->data0, buffer, count, 0); 630 638 } 631 639 632 640 static int 633 rtems_bsdnet_write ( int fd, const void *buffer, unsigned32 count)634 { 635 return send ( fd, buffer, count, 0);641 rtems_bsdnet_write (rtems_libio_t *iop, const void *buffer, unsigned32 count) 642 { 643 return send (iop->data0, buffer, count, 0); 636 644 } 637 645 … … 660 668 661 669 static int 662 rtems_bsdnet_ioctl (int fd, unsigned32 command, void *buffer) 663 { 664 struct socket *so; 665 int error; 666 667 rtems_bsdnet_semaphore_obtain (); 668 if ((so = rtems_bsdnet_fdToSocket (fd)) == NULL) { 670 rtems_bsdnet_ioctl (rtems_libio_t *iop, unsigned32 command, void *buffer) 671 { 672 struct socket *so; 673 int error; 674 675 rtems_bsdnet_semaphore_obtain (); 676 if ((so = iop->data1) == NULL) { 677 errno = EBADF; 669 678 rtems_bsdnet_semaphore_release (); 670 679 return -1; … … 679 688 } 680 689 681 rtems_libio_handler_t rtems_bsdnet_io_handler = { 690 static int 691 rtems_bsdnet_fstat (rtems_filesystem_location_info_t *loc, struct stat *sp) 692 { 693 sp->st_mode = S_IFSOCK; 694 return 0; 695 } 696 697 static const rtems_filesystem_file_handlers_r socket_handlers = { 682 698 NULL, /* open */ 683 699 rtems_bsdnet_close, /* close */ … … 686 702 rtems_bsdnet_ioctl, /* ioctl */ 687 703 NULL, /* lseek */ 704 rtems_bsdnet_fstat, /* fstat */ 705 NULL, /* fchmod */ 706 NULL, /* ftruncate */ 707 NULL, /* fpathconf */ 708 NULL, /* fsync */ 709 NULL, /* fdatasync */ 688 710 }; 689 -
cpukit/include/rtems/libio_.h
re069cdc3 r73f6236 67 67 extern rtems_libio_t *rtems_libio_last_iop; 68 68 extern rtems_libio_t *rtems_libio_iop_freelist; 69 70 /*71 * External I/O Handlers Table72 *73 * Space for all possible handlers is preallocated74 * to speed up dispatch to external handlers.75 */76 77 extern rtems_libio_handler_t rtems_libio_handlers[15];78 69 79 70 /* -
cpukit/libcsupport/include/rtems/libio.h
re069cdc3 r73f6236 398 398 #define LIBIO_FLAGS_CREATE 0x0400 /* create file */ 399 399 #define LIBIO_FLAGS_CLOSE_ON_EXEC 0x0800 /* close on process exec() */ 400 401 #define LIBIO_FLAGS_HANDLER_SHIFT 12402 #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 */405 406 400 #define LIBIO_FLAGS_READ_WRITE (LIBIO_FLAGS_READ | LIBIO_FLAGS_WRITE) 407 408 401 409 402 void rtems_libio_init(void); … … 446 439 int whence 447 440 ); 448 449 typedef struct {450 rtems_libio_open_t open;451 rtems_libio_close_t close;452 rtems_libio_read_t read;453 rtems_libio_write_t write;454 rtems_libio_ioctl_t ioctl;455 rtems_libio_lseek_t lseek;456 } rtems_libio_handler_t;457 458 /*459 * Register a set of external handlers460 */461 462 void rtems_register_libio_handler(463 int handler_flag,464 const rtems_libio_handler_t *handler465 );466 467 /*468 * Macros to assist in management of external IO handlers.469 */470 471 #define RTEMS_FILE_DESCRIPTOR_TYPE_FILE 0x0000472 #define RTEMS_FILE_DESCRIPTOR_TYPE_SOCKET 0x1000473 #define rtems_make_file_descriptor(fd,flags) ((fd)|(flags))474 #define rtems_file_descriptor_base(fd) ((fd) & 0x0FFF)475 #define rtems_file_descriptor_type(fd) ((fd) & 0xF000)476 #define rtems_file_descriptor_type_index(fd) ((((fd) & 0xF000) >> 12) - 1)477 441 478 442 /* -
cpukit/libcsupport/include/rtems/libio_.h
re069cdc3 r73f6236 67 67 extern rtems_libio_t *rtems_libio_last_iop; 68 68 extern rtems_libio_t *rtems_libio_iop_freelist; 69 70 /*71 * External I/O Handlers Table72 *73 * Space for all possible handlers is preallocated74 * to speed up dispatch to external handlers.75 */76 77 extern rtems_libio_handler_t rtems_libio_handlers[15];78 69 79 70 /* -
cpukit/libcsupport/src/close.c
re069cdc3 r73f6236 21 21 rtems_libio_t *iop; 22 22 rtems_status_code rc; 23 int status;24 23 25 24 rtems_libio_check_fd(fd); 26 25 iop = rtems_libio_iop(fd); 27 26 rtems_libio_check_is_open(iop); 28 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) {29 int (*fp)(int fd);30 27 31 fp = rtems_libio_handlers[ 32 (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].close; 33 if ( fp == NULL ) 34 set_errno_and_return_minus_one( EBADF ); 35 status = (*fp)( fd ); 36 return status; 37 } 38 39 if ( !iop->handlers ) 40 set_errno_and_return_minus_one( EBADF ); 41 42 if ( !iop->handlers->close ) 43 set_errno_and_return_minus_one( ENOTSUP ); 44 45 rc = (*iop->handlers->close)( iop ); 28 rc = RTEMS_SUCCESSFUL; 29 if ( iop->handlers->close ) 30 rc = (*iop->handlers->close)( iop ); 46 31 47 32 rtems_libio_free( iop ); 48 49 if (rc != RTEMS_SUCCESSFUL)50 set_errno_and_return_minus_one( rc );51 33 52 34 return rc; -
cpukit/libcsupport/src/fchmod.c
re069cdc3 r73f6236 33 33 34 34 /* 35 * If this is not a file system based entity, it is an error.36 */37 38 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK )39 set_errno_and_return_minus_one( EBADF );40 41 /*42 35 * Now process the fchmod(). 43 36 */ -
cpukit/libcsupport/src/fcntl.c
re069cdc3 r73f6236 36 36 iop = rtems_libio_iop( fd ); 37 37 rtems_libio_check_is_open(iop); 38 39 /*40 * If this is not a file system based entity, it is an error.41 */42 43 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK )44 set_errno_and_return_minus_one( EBADF );45 38 46 39 /* -
cpukit/libcsupport/src/fdatasync.c
re069cdc3 r73f6236 29 29 30 30 /* 31 * If this file descriptor is mapped to an external set of handlers,32 * then pass the request on to them.33 */34 35 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK )36 set_errno_and_return_minus_one( EBADF );37 38 /*39 31 * Now process the fdatasync(). 40 32 */ -
cpukit/libcsupport/src/fpathconf.c
re069cdc3 r73f6236 31 31 rtems_libio_check_is_open(iop); 32 32 rtems_libio_check_permissions(iop, LIBIO_FLAGS_READ); 33 34 /*35 * If this file descriptor is mapped to an external set of handlers,36 * then it is an error since fpathconf() is not included in the37 * set.38 */39 40 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK )41 set_errno_and_return_minus_one( EBADF );42 33 43 34 /* -
cpukit/libcsupport/src/fstat.c
re069cdc3 r73f6236 34 34 35 35 /* 36 * Zero out the stat structure so the various support37 * versions of stat don't have to.38 */39 40 memset( sbuf, 0, sizeof(struct stat) );41 42 /*43 * If this file descriptor is mapped to an external set of handlers,44 * then pass the request on to them.45 */46 47 if (rtems_file_descriptor_type(fd)) {48 switch (rtems_file_descriptor_type (fd)) {49 case RTEMS_FILE_DESCRIPTOR_TYPE_FILE:50 break;51 52 case RTEMS_FILE_DESCRIPTOR_TYPE_SOCKET:53 #if !defined(__GO32__)54 sbuf->st_mode = S_IFSOCK;55 break;56 #endif57 58 default:59 set_errno_and_return_minus_one( EBADF );60 }61 }62 63 /*64 36 * Now process the stat() request. 65 37 */ … … 69 41 rtems_libio_check_is_open(iop); 70 42 43 if ( !iop->handlers ) 44 set_errno_and_return_minus_one( EBADF ); 45 71 46 if ( !iop->handlers->fstat ) 72 47 set_errno_and_return_minus_one( ENOTSUP ); 48 49 /* 50 * Zero out the stat structure so the various support 51 * versions of stat don't have to. 52 */ 53 memset( sbuf, 0, sizeof(struct stat) ); 73 54 74 55 return (*iop->handlers->fstat)( &iop->pathinfo, sbuf ); -
cpukit/libcsupport/src/fsync.c
re069cdc3 r73f6236 29 29 30 30 /* 31 * If this file descriptor is mapped to an external set of handlers,32 * then pass the request on to them.33 */34 35 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK )36 set_errno_and_return_minus_one( EBADF );37 38 /*39 31 * Now process the fsync(). 40 32 */ -
cpukit/libcsupport/src/ftruncate.c
re069cdc3 r73f6236 31 31 32 32 /* 33 * If this is not a file system based entity, it is an error.34 */35 36 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK )37 set_errno_and_return_minus_one( EBADF );38 39 /*40 33 * Now process the ftruncate() request. 41 34 */ -
cpukit/libcsupport/src/ioctl.c
re069cdc3 r73f6236 32 32 33 33 /* 34 * If this file descriptor is mapped to an external set of handlers,35 * then pass the request on to them.36 */37 38 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) {39 rtems_libio_ioctl_t fp;40 41 fp = rtems_libio_handlers[42 (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].ioctl;43 if ( fp == NULL )44 set_errno_and_return_minus_one( EBADF );45 46 return (*fp)( fd, command, buffer );47 }48 49 /*50 34 * Now process the ioctl(). 51 35 */ -
cpukit/libcsupport/src/libio.c
re069cdc3 r73f6236 51 51 52 52 /* 53 * External I/O Handlers Table54 *55 * Space for all possible handlers is preallocated56 * to speed up dispatch to external handlers.57 */58 59 rtems_libio_handler_t rtems_libio_handlers[15];60 61 /*62 53 * Default mode for all files. 63 54 */ 64 55 65 56 mode_t rtems_filesystem_umask; 66 67 /*68 * rtems_register_libio_handler69 *70 * This function registers an external IO handler set. This lets71 * other subsystems have their own versions of many of the system72 * calls. For example, the networking code registers handlers which73 * map the system calls for read() and write() to socket calls.74 *75 */76 77 void rtems_register_libio_handler(78 int handler_flag,79 const rtems_libio_handler_t *handler80 )81 {82 int handler_index = (handler_flag >> LIBIO_FLAGS_HANDLER_SHIFT) - 1;83 84 if ((handler_index < 0) || (handler_index >= 15))85 rtems_fatal_error_occurred( RTEMS_INVALID_NUMBER );86 87 rtems_libio_handlers[handler_index] = *handler;88 }89 57 90 58 /* -
cpukit/libcsupport/src/libio_sockets.c
re069cdc3 r73f6236 19 19 #include <errno.h> 20 20 21 22 21 /* 23 22 * Convert an RTEMS file descriptor to a BSD socket pointer. … … 30 29 rtems_libio_t *iop; 31 30 32 if ((unsigned32)fd >= rtems_libio_number_iops) 33 return NULL; 31 if ((unsigned32)fd >= rtems_libio_number_iops) { 32 errno = EBADF; 33 return NULL; 34 } 34 35 iop = &rtems_libio_iops[fd]; 35 if ( (iop->flags & LIBIO_FLAGS_HANDLER_MASK) != LIBIO_FLAGS_HANDLER_SOCK)36 return NULL;36 if (iop->data1 == NULL) 37 errno = EBADF; 37 38 return iop->data1; 38 39 } … … 43 44 44 45 int rtems_bsdnet_makeFdForSocket( 45 void *so 46 void *so, 47 const rtems_filesystem_file_handlers_r *h 46 48 ) 47 49 { 48 50 rtems_libio_t *iop; 51 int fd; 49 52 50 53 iop = rtems_libio_allocate(); … … 53 56 return -1; 54 57 } 55 iop->flags |= LIBIO_FLAGS_HANDLER_SOCK | LIBIO_FLAGS_WRITE | LIBIO_FLAGS_READ; 58 fd = iop - rtems_libio_iops; 59 iop->flags |= LIBIO_FLAGS_WRITE | LIBIO_FLAGS_READ; 60 iop->data0 = fd; 56 61 iop->data1 = so; 57 return iop - rtems_libio_iops; 62 iop->handlers = h; 63 return fd; 58 64 } -
cpukit/libcsupport/src/lseek.c
re069cdc3 r73f6236 28 28 iop = rtems_libio_iop( fd ); 29 29 rtems_libio_check_is_open(iop); 30 31 /*32 * If this file descriptor is mapped to an external set of handlers,33 * then pass the request on to them.34 */35 36 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) {37 rtems_libio_lseek_t fp;38 39 fp = rtems_libio_handlers[40 (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].lseek;41 if ( fp == NULL )42 set_errno_and_return_minus_one( EBADF );43 44 return (*fp)( fd, offset, whence );45 }46 30 47 31 /* -
cpukit/libcsupport/src/read.c
re069cdc3 r73f6236 30 30 rtems_libio_check_count( count ); 31 31 rtems_libio_check_permissions( iop, LIBIO_FLAGS_READ ); 32 33 /*34 * If this file descriptor is mapped to an external set of handlers,35 * then pass the request on to them.36 */37 38 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) {39 rtems_libio_read_t fp;40 41 fp = rtems_libio_handlers[42 (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].read;43 if ( fp == NULL )44 set_errno_and_return_minus_one( EBADF );45 46 return (*fp)( fd, buffer, count );47 }48 32 49 33 /* -
cpukit/libcsupport/src/write.c
re069cdc3 r73f6236 40 40 41 41 /* 42 * If this file descriptor is mapped to an external set of handlers,43 * then pass the request on to them.44 */45 46 if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) {47 rtems_libio_write_t fp;48 49 fp = rtems_libio_handlers[50 (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].write;51 if ( fp == NULL )52 set_errno_and_return_minus_one( EBADF );53 54 return (*fp)( fd, buffer, count );55 }56 57 /*58 42 * Now process the write() request. 59 43 */ -
cpukit/libnetworking/rtems/rtems_bsdnet_internal.h
re069cdc3 r73f6236 175 175 int socket (int, int, int); 176 176 int ioctl (int, unsigned long, ...); 177 struct socket *rtems_bsdnet_fdToSocket (int fd);178 int rtems_bsdnet_makeFdForSocket (void *);179 177 180 178 /* -
cpukit/libnetworking/rtems/rtems_glue.c
re069cdc3 r73f6236 78 78 sizeof rtems_bsdnet_config.name_server[0]]; 79 79 int rtems_bsdnet_nameserver_count; 80 81 extern rtems_libio_handler_t rtems_bsdnet_io_handler;82 80 83 81 /* … … 230 228 */ 231 229 networkDaemonTid = rtems_bsdnet_newproc ("ntwk", 4096, networkDaemon, NULL); 232 233 /*234 * Register as an external I/O handler235 */236 rtems_register_libio_handler (LIBIO_FLAGS_HANDLER_SOCK,237 &rtems_bsdnet_io_handler);238 230 239 231 /* -
cpukit/libnetworking/rtems/rtems_select.c
re069cdc3 r73f6236 47 47 48 48 static __inline int imin(int a, int b) { return (a < b ? a : b); } 49 struct socket *rtems_bsdnet_fdToSocket(int fd); 49 50 50 51 static int -
cpukit/libnetworking/rtems/rtems_syscall.c
re069cdc3 r73f6236 25 25 #include <net/if.h> 26 26 #include <net/route.h> 27 28 /* 29 * Hooks to RTEMS I/O system 30 */ 31 static const rtems_filesystem_file_handlers_r socket_handlers; 32 int rtems_bsdnet_makeFdForSocket(void *so, const rtems_filesystem_file_handlers_r *h); 33 struct socket *rtems_bsdnet_fdToSocket(int fd); 27 34 28 35 /* … … 65 72 error = socreate(domain, &so, type, protocol, NULL); 66 73 if (error == 0) { 67 fd = rtems_bsdnet_makeFdForSocket (so );74 fd = rtems_bsdnet_makeFdForSocket (so, &socket_handlers); 68 75 if (fd < 0) 69 76 soclose (so); … … 214 221 head->so_qlen--; 215 222 216 fd = rtems_bsdnet_makeFdForSocket (so );223 fd = rtems_bsdnet_makeFdForSocket (so, &socket_handlers); 217 224 if (fd < 0) { 218 225 TAILQ_INSERT_HEAD(&head->so_comp, so, so_list); … … 601 608 /* 602 609 ************************************************************************ 603 * RTEMS EXTERNAL I/O HANDLER ROUTINES*610 * RTEMS I/O HANDLER ROUTINES * 604 611 ************************************************************************ 605 612 */ 606 613 static int 607 rtems_bsdnet_close (int fd) 608 { 609 struct socket *so; 610 int error; 611 612 rtems_bsdnet_semaphore_obtain (); 613 if ((so = rtems_bsdnet_fdToSocket (fd)) == NULL) { 614 rtems_bsdnet_close (rtems_libio_t *iop) 615 { 616 struct socket *so; 617 int error; 618 619 rtems_bsdnet_semaphore_obtain (); 620 if ((so = iop->data1) == NULL) { 621 errno = EBADF; 614 622 rtems_bsdnet_semaphore_release (); 615 623 return -1; … … 625 633 626 634 static int 627 rtems_bsdnet_read ( int fd, void *buffer, unsigned32 count)628 { 629 return recv ( fd, buffer, count, 0);635 rtems_bsdnet_read (rtems_libio_t *iop, void *buffer, unsigned32 count) 636 { 637 return recv (iop->data0, buffer, count, 0); 630 638 } 631 639 632 640 static int 633 rtems_bsdnet_write ( int fd, const void *buffer, unsigned32 count)634 { 635 return send ( fd, buffer, count, 0);641 rtems_bsdnet_write (rtems_libio_t *iop, const void *buffer, unsigned32 count) 642 { 643 return send (iop->data0, buffer, count, 0); 636 644 } 637 645 … … 660 668 661 669 static int 662 rtems_bsdnet_ioctl (int fd, unsigned32 command, void *buffer) 663 { 664 struct socket *so; 665 int error; 666 667 rtems_bsdnet_semaphore_obtain (); 668 if ((so = rtems_bsdnet_fdToSocket (fd)) == NULL) { 670 rtems_bsdnet_ioctl (rtems_libio_t *iop, unsigned32 command, void *buffer) 671 { 672 struct socket *so; 673 int error; 674 675 rtems_bsdnet_semaphore_obtain (); 676 if ((so = iop->data1) == NULL) { 677 errno = EBADF; 669 678 rtems_bsdnet_semaphore_release (); 670 679 return -1; … … 679 688 } 680 689 681 rtems_libio_handler_t rtems_bsdnet_io_handler = { 690 static int 691 rtems_bsdnet_fstat (rtems_filesystem_location_info_t *loc, struct stat *sp) 692 { 693 sp->st_mode = S_IFSOCK; 694 return 0; 695 } 696 697 static const rtems_filesystem_file_handlers_r socket_handlers = { 682 698 NULL, /* open */ 683 699 rtems_bsdnet_close, /* close */ … … 686 702 rtems_bsdnet_ioctl, /* ioctl */ 687 703 NULL, /* lseek */ 704 rtems_bsdnet_fstat, /* fstat */ 705 NULL, /* fchmod */ 706 NULL, /* ftruncate */ 707 NULL, /* fpathconf */ 708 NULL, /* fsync */ 709 NULL, /* fdatasync */ 688 710 }; 689
Note: See TracChangeset
for help on using the changeset viewer.