diff options
author | Joel Sherrill <joel.sherrill@OARcorp.com> | 1999-03-01 22:40:08 +0000 |
---|---|---|
committer | Joel Sherrill <joel.sherrill@OARcorp.com> | 1999-03-01 22:40:08 +0000 |
commit | 73f6236bc09b3cadf0aa030e16396154421f3e30 (patch) | |
tree | 30c344abe6e8091d860d583e0a1342af575ae791 /c | |
parent | Part of the automake VI patch from Ralf Corsepius <corsepiu@faw.uni-ulm.de>: (diff) | |
download | rtems-73f6236bc09b3cadf0aa030e16396154421f3e30.tar.bz2 |
Patch from Eric Norum <eric@skatter.usask.ca> to eliminate external
IO handlers scheme that was implemented originally just to support
sockets. The file system IO switch is more general and works fine.
Diffstat (limited to 'c')
47 files changed, 157 insertions, 611 deletions
diff --git a/c/src/exec/include/rtems/libio_.h b/c/src/exec/include/rtems/libio_.h index 995809b6d5..16dc708f53 100644 --- a/c/src/exec/include/rtems/libio_.h +++ b/c/src/exec/include/rtems/libio_.h @@ -68,15 +68,6 @@ extern rtems_libio_t *rtems_libio_last_iop; extern rtems_libio_t *rtems_libio_iop_freelist; /* - * External I/O Handlers Table - * - * Space for all possible handlers is preallocated - * to speed up dispatch to external handlers. - */ - -extern rtems_libio_handler_t rtems_libio_handlers[15]; - -/* * Default mode for all files. */ diff --git a/c/src/exec/libcsupport/include/rtems/libio.h b/c/src/exec/libcsupport/include/rtems/libio.h index 740574f303..1cbfef383b 100644 --- a/c/src/exec/libcsupport/include/rtems/libio.h +++ b/c/src/exec/libcsupport/include/rtems/libio.h @@ -397,15 +397,8 @@ typedef struct { #define LIBIO_FLAGS_APPEND 0x0200 /* all writes append */ #define LIBIO_FLAGS_CREATE 0x0400 /* create file */ #define LIBIO_FLAGS_CLOSE_ON_EXEC 0x0800 /* close on process exec() */ - -#define LIBIO_FLAGS_HANDLER_SHIFT 12 -#define LIBIO_FLAGS_HANDLER_MASK 0xF000 /* mask for external handler type */ -#define LIBIO_FLAGS_HANDLER_RTEMS 0x0000 /* `traditional' RTEMS I/O */ -#define LIBIO_FLAGS_HANDLER_SOCK 0x1000 /* BSD socket */ - #define LIBIO_FLAGS_READ_WRITE (LIBIO_FLAGS_READ | LIBIO_FLAGS_WRITE) - void rtems_libio_init(void); /* @@ -446,35 +439,6 @@ typedef int (*rtems_libio_lseek_t)( int whence ); -typedef struct { - rtems_libio_open_t open; - rtems_libio_close_t close; - rtems_libio_read_t read; - rtems_libio_write_t write; - rtems_libio_ioctl_t ioctl; - rtems_libio_lseek_t lseek; -} rtems_libio_handler_t; - -/* - * Register a set of external handlers - */ - -void rtems_register_libio_handler( - int handler_flag, - const rtems_libio_handler_t *handler -); - -/* - * Macros to assist in management of external IO handlers. - */ - -#define RTEMS_FILE_DESCRIPTOR_TYPE_FILE 0x0000 -#define RTEMS_FILE_DESCRIPTOR_TYPE_SOCKET 0x1000 -#define rtems_make_file_descriptor(fd,flags) ((fd)|(flags)) -#define rtems_file_descriptor_base(fd) ((fd) & 0x0FFF) -#define rtems_file_descriptor_type(fd) ((fd) & 0xF000) -#define rtems_file_descriptor_type_index(fd) ((((fd) & 0xF000) >> 12) - 1) - /* * IOCTL values */ diff --git a/c/src/exec/libcsupport/include/rtems/libio_.h b/c/src/exec/libcsupport/include/rtems/libio_.h index 995809b6d5..16dc708f53 100644 --- a/c/src/exec/libcsupport/include/rtems/libio_.h +++ b/c/src/exec/libcsupport/include/rtems/libio_.h @@ -68,15 +68,6 @@ extern rtems_libio_t *rtems_libio_last_iop; extern rtems_libio_t *rtems_libio_iop_freelist; /* - * External I/O Handlers Table - * - * Space for all possible handlers is preallocated - * to speed up dispatch to external handlers. - */ - -extern rtems_libio_handler_t rtems_libio_handlers[15]; - -/* * Default mode for all files. */ diff --git a/c/src/exec/libcsupport/src/close.c b/c/src/exec/libcsupport/src/close.c index 04c269664b..ba69847533 100644 --- a/c/src/exec/libcsupport/src/close.c +++ b/c/src/exec/libcsupport/src/close.c @@ -20,35 +20,17 @@ int close( { rtems_libio_t *iop; rtems_status_code rc; - int status; rtems_libio_check_fd(fd); iop = rtems_libio_iop(fd); rtems_libio_check_is_open(iop); - if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) { - int (*fp)(int fd); - fp = rtems_libio_handlers[ - (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].close; - if ( fp == NULL ) - set_errno_and_return_minus_one( EBADF ); - status = (*fp)( fd ); - return status; - } - - if ( !iop->handlers ) - set_errno_and_return_minus_one( EBADF ); - - if ( !iop->handlers->close ) - set_errno_and_return_minus_one( ENOTSUP ); - - rc = (*iop->handlers->close)( iop ); + rc = RTEMS_SUCCESSFUL; + if ( iop->handlers->close ) + rc = (*iop->handlers->close)( iop ); rtems_libio_free( iop ); - if (rc != RTEMS_SUCCESSFUL) - set_errno_and_return_minus_one( rc ); - return rc; } diff --git a/c/src/exec/libcsupport/src/fchmod.c b/c/src/exec/libcsupport/src/fchmod.c index 46c64cd6f7..a964c737ea 100644 --- a/c/src/exec/libcsupport/src/fchmod.c +++ b/c/src/exec/libcsupport/src/fchmod.c @@ -32,13 +32,6 @@ int fchmod( rtems_libio_check_is_open(iop); /* - * If this is not a file system based entity, it is an error. - */ - - if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) - set_errno_and_return_minus_one( EBADF ); - - /* * Now process the fchmod(). */ diff --git a/c/src/exec/libcsupport/src/fcntl.c b/c/src/exec/libcsupport/src/fcntl.c index a89306c9fc..7673049a58 100644 --- a/c/src/exec/libcsupport/src/fcntl.c +++ b/c/src/exec/libcsupport/src/fcntl.c @@ -37,13 +37,6 @@ int fcntl( rtems_libio_check_is_open(iop); /* - * If this is not a file system based entity, it is an error. - */ - - if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) - set_errno_and_return_minus_one( EBADF ); - - /* * Now process the fcntl(). */ diff --git a/c/src/exec/libcsupport/src/fdatasync.c b/c/src/exec/libcsupport/src/fdatasync.c index 7de28ce38a..e1f47848bf 100644 --- a/c/src/exec/libcsupport/src/fdatasync.c +++ b/c/src/exec/libcsupport/src/fdatasync.c @@ -28,14 +28,6 @@ int fdatasync( rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE ); /* - * If this file descriptor is mapped to an external set of handlers, - * then pass the request on to them. - */ - - if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) - set_errno_and_return_minus_one( EBADF ); - - /* * Now process the fdatasync(). */ diff --git a/c/src/exec/libcsupport/src/fpathconf.c b/c/src/exec/libcsupport/src/fpathconf.c index 97c392b5af..b8cede80ff 100644 --- a/c/src/exec/libcsupport/src/fpathconf.c +++ b/c/src/exec/libcsupport/src/fpathconf.c @@ -32,15 +32,6 @@ long fpathconf( rtems_libio_check_permissions(iop, LIBIO_FLAGS_READ); /* - * If this file descriptor is mapped to an external set of handlers, - * then it is an error since fpathconf() is not included in the - * set. - */ - - if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) - set_errno_and_return_minus_one( EBADF ); - - /* * Now process the information request. */ diff --git a/c/src/exec/libcsupport/src/fstat.c b/c/src/exec/libcsupport/src/fstat.c index 0399518532..7fdc2a4b8a 100644 --- a/c/src/exec/libcsupport/src/fstat.c +++ b/c/src/exec/libcsupport/src/fstat.c @@ -33,34 +33,6 @@ int fstat( set_errno_and_return_minus_one( EFAULT ); /* - * Zero out the stat structure so the various support - * versions of stat don't have to. - */ - - memset( sbuf, 0, sizeof(struct stat) ); - - /* - * If this file descriptor is mapped to an external set of handlers, - * then pass the request on to them. - */ - - if (rtems_file_descriptor_type(fd)) { - switch (rtems_file_descriptor_type (fd)) { - case RTEMS_FILE_DESCRIPTOR_TYPE_FILE: - break; - - case RTEMS_FILE_DESCRIPTOR_TYPE_SOCKET: -#if !defined(__GO32__) - sbuf->st_mode = S_IFSOCK; - break; -#endif - - default: - set_errno_and_return_minus_one( EBADF ); - } - } - - /* * Now process the stat() request. */ @@ -68,9 +40,18 @@ int fstat( rtems_libio_check_fd( fd ); rtems_libio_check_is_open(iop); + if ( !iop->handlers ) + set_errno_and_return_minus_one( EBADF ); + if ( !iop->handlers->fstat ) set_errno_and_return_minus_one( ENOTSUP ); + /* + * Zero out the stat structure so the various support + * versions of stat don't have to. + */ + memset( sbuf, 0, sizeof(struct stat) ); + return (*iop->handlers->fstat)( &iop->pathinfo, sbuf ); } diff --git a/c/src/exec/libcsupport/src/fsync.c b/c/src/exec/libcsupport/src/fsync.c index eef1f85171..e2bad3bb2e 100644 --- a/c/src/exec/libcsupport/src/fsync.c +++ b/c/src/exec/libcsupport/src/fsync.c @@ -28,14 +28,6 @@ int fsync( rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE ); /* - * If this file descriptor is mapped to an external set of handlers, - * then pass the request on to them. - */ - - if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) - set_errno_and_return_minus_one( EBADF ); - - /* * Now process the fsync(). */ diff --git a/c/src/exec/libcsupport/src/ftruncate.c b/c/src/exec/libcsupport/src/ftruncate.c index 0e90db5c79..0112817981 100644 --- a/c/src/exec/libcsupport/src/ftruncate.c +++ b/c/src/exec/libcsupport/src/ftruncate.c @@ -30,13 +30,6 @@ int ftruncate( rtems_libio_check_is_open(iop); /* - * If this is not a file system based entity, it is an error. - */ - - if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) - set_errno_and_return_minus_one( EBADF ); - - /* * Now process the ftruncate() request. */ diff --git a/c/src/exec/libcsupport/src/ioctl.c b/c/src/exec/libcsupport/src/ioctl.c index 5ac530b6e0..0e8072588b 100644 --- a/c/src/exec/libcsupport/src/ioctl.c +++ b/c/src/exec/libcsupport/src/ioctl.c @@ -31,22 +31,6 @@ int ioctl( rtems_libio_check_is_open(iop); /* - * If this file descriptor is mapped to an external set of handlers, - * then pass the request on to them. - */ - - if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) { - rtems_libio_ioctl_t fp; - - fp = rtems_libio_handlers[ - (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].ioctl; - if ( fp == NULL ) - set_errno_and_return_minus_one( EBADF ); - - return (*fp)( fd, command, buffer ); - } - - /* * Now process the ioctl(). */ diff --git a/c/src/exec/libcsupport/src/libio.c b/c/src/exec/libcsupport/src/libio.c index 88aea9b62f..59b7086a03 100644 --- a/c/src/exec/libcsupport/src/libio.c +++ b/c/src/exec/libcsupport/src/libio.c @@ -50,44 +50,12 @@ rtems_libio_t *rtems_libio_last_iop; rtems_libio_t *rtems_libio_iop_freelist; /* - * External I/O Handlers Table - * - * Space for all possible handlers is preallocated - * to speed up dispatch to external handlers. - */ - -rtems_libio_handler_t rtems_libio_handlers[15]; - -/* * Default mode for all files. */ mode_t rtems_filesystem_umask; /* - * rtems_register_libio_handler - * - * This function registers an external IO handler set. This lets - * other subsystems have their own versions of many of the system - * calls. For example, the networking code registers handlers which - * map the system calls for read() and write() to socket calls. - * - */ - -void rtems_register_libio_handler( - int handler_flag, - const rtems_libio_handler_t *handler -) -{ - int handler_index = (handler_flag >> LIBIO_FLAGS_HANDLER_SHIFT) - 1; - - if ((handler_index < 0) || (handler_index >= 15)) - rtems_fatal_error_occurred( RTEMS_INVALID_NUMBER ); - - rtems_libio_handlers[handler_index] = *handler; -} - -/* * rtems_libio_init * * Called by BSP startup code to initialize the libio subsystem. diff --git a/c/src/exec/libcsupport/src/libio_sockets.c b/c/src/exec/libcsupport/src/libio_sockets.c index cb1d5a7bdd..8d21120f3d 100644 --- a/c/src/exec/libcsupport/src/libio_sockets.c +++ b/c/src/exec/libcsupport/src/libio_sockets.c @@ -18,7 +18,6 @@ #include <errno.h> - /* * Convert an RTEMS file descriptor to a BSD socket pointer. */ @@ -29,11 +28,13 @@ struct socket *rtems_bsdnet_fdToSocket( { rtems_libio_t *iop; - if ((unsigned32)fd >= rtems_libio_number_iops) - return NULL; + if ((unsigned32)fd >= rtems_libio_number_iops) { + errno = EBADF; + return NULL; + } iop = &rtems_libio_iops[fd]; - if ((iop->flags & LIBIO_FLAGS_HANDLER_MASK) != LIBIO_FLAGS_HANDLER_SOCK) - return NULL; + if (iop->data1 == NULL) + errno = EBADF; return iop->data1; } @@ -42,17 +43,22 @@ struct socket *rtems_bsdnet_fdToSocket( */ int rtems_bsdnet_makeFdForSocket( - void *so + void *so, + const rtems_filesystem_file_handlers_r *h ) { rtems_libio_t *iop; + int fd; iop = rtems_libio_allocate(); if (iop == 0) { errno = ENFILE; return -1; } - iop->flags |= LIBIO_FLAGS_HANDLER_SOCK | LIBIO_FLAGS_WRITE | LIBIO_FLAGS_READ; + fd = iop - rtems_libio_iops; + iop->flags |= LIBIO_FLAGS_WRITE | LIBIO_FLAGS_READ; + iop->data0 = fd; iop->data1 = so; - return iop - rtems_libio_iops; + iop->handlers = h; + return fd; } diff --git a/c/src/exec/libcsupport/src/lseek.c b/c/src/exec/libcsupport/src/lseek.c index 3e586bbc31..6f37f3c294 100644 --- a/c/src/exec/libcsupport/src/lseek.c +++ b/c/src/exec/libcsupport/src/lseek.c @@ -29,22 +29,6 @@ off_t lseek( rtems_libio_check_is_open(iop); /* - * If this file descriptor is mapped to an external set of handlers, - * then pass the request on to them. - */ - - if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) { - rtems_libio_lseek_t fp; - - fp = rtems_libio_handlers[ - (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].lseek; - if ( fp == NULL ) - set_errno_and_return_minus_one( EBADF ); - - return (*fp)( fd, offset, whence ); - } - - /* * Now process the lseek(). */ diff --git a/c/src/exec/libcsupport/src/read.c b/c/src/exec/libcsupport/src/read.c index e2866744a4..360fc75f66 100644 --- a/c/src/exec/libcsupport/src/read.c +++ b/c/src/exec/libcsupport/src/read.c @@ -31,22 +31,6 @@ ssize_t read( rtems_libio_check_permissions( iop, LIBIO_FLAGS_READ ); /* - * If this file descriptor is mapped to an external set of handlers, - * then pass the request on to them. - */ - - if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) { - rtems_libio_read_t fp; - - fp = rtems_libio_handlers[ - (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].read; - if ( fp == NULL ) - set_errno_and_return_minus_one( EBADF ); - - return (*fp)( fd, buffer, count ); - } - - /* * Now process the read(). */ diff --git a/c/src/exec/libcsupport/src/write.c b/c/src/exec/libcsupport/src/write.c index 13dc90bb89..a3eca4eccd 100644 --- a/c/src/exec/libcsupport/src/write.c +++ b/c/src/exec/libcsupport/src/write.c @@ -39,22 +39,6 @@ ssize_t write( rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE ); /* - * If this file descriptor is mapped to an external set of handlers, - * then pass the request on to them. - */ - - if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) { - rtems_libio_write_t fp; - - fp = rtems_libio_handlers[ - (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].write; - if ( fp == NULL ) - set_errno_and_return_minus_one( EBADF ); - - return (*fp)( fd, buffer, count ); - } - - /* * Now process the write() request. */ diff --git a/c/src/exec/libnetworking/rtems/rtems_bsdnet_internal.h b/c/src/exec/libnetworking/rtems/rtems_bsdnet_internal.h index 8cbba180d6..adaecbd5f9 100644 --- a/c/src/exec/libnetworking/rtems/rtems_bsdnet_internal.h +++ b/c/src/exec/libnetworking/rtems/rtems_bsdnet_internal.h @@ -174,8 +174,6 @@ void arpintr (void); void bootpc_init(void); int socket (int, int, int); int ioctl (int, unsigned long, ...); -struct socket *rtems_bsdnet_fdToSocket (int fd); -int rtems_bsdnet_makeFdForSocket (void *); /* * Events used by networking routines. diff --git a/c/src/exec/libnetworking/rtems/rtems_glue.c b/c/src/exec/libnetworking/rtems/rtems_glue.c index 5eb885e70e..0601e5659f 100644 --- a/c/src/exec/libnetworking/rtems/rtems_glue.c +++ b/c/src/exec/libnetworking/rtems/rtems_glue.c @@ -78,8 +78,6 @@ struct in_addr rtems_bsdnet_nameserver[sizeof rtems_bsdnet_config.name_server / sizeof rtems_bsdnet_config.name_server[0]]; int rtems_bsdnet_nameserver_count; -extern rtems_libio_handler_t rtems_bsdnet_io_handler; - /* * Perform FreeBSD memory allocation. * FIXME: This should be modified to keep memory allocation statistics. @@ -231,12 +229,6 @@ rtems_bsdnet_initialize (void) networkDaemonTid = rtems_bsdnet_newproc ("ntwk", 4096, networkDaemon, NULL); /* - * Register as an external I/O handler - */ - rtems_register_libio_handler (LIBIO_FLAGS_HANDLER_SOCK, - &rtems_bsdnet_io_handler); - - /* * Let other network tasks begin */ rtems_bsdnet_semaphore_release (); diff --git a/c/src/exec/libnetworking/rtems/rtems_select.c b/c/src/exec/libnetworking/rtems/rtems_select.c index 2487edf9fc..972bf2d650 100644 --- a/c/src/exec/libnetworking/rtems/rtems_select.c +++ b/c/src/exec/libnetworking/rtems/rtems_select.c @@ -46,6 +46,7 @@ */ static __inline int imin(int a, int b) { return (a < b ? a : b); } +struct socket *rtems_bsdnet_fdToSocket(int fd); static int socket_select (struct socket *so, int which, rtems_id tid) diff --git a/c/src/exec/libnetworking/rtems/rtems_syscall.c b/c/src/exec/libnetworking/rtems/rtems_syscall.c index 4a871f78fb..141b7ceeba 100644 --- a/c/src/exec/libnetworking/rtems/rtems_syscall.c +++ b/c/src/exec/libnetworking/rtems/rtems_syscall.c @@ -26,6 +26,13 @@ #include <net/route.h> /* + * Hooks to RTEMS I/O system + */ +static const rtems_filesystem_file_handlers_r socket_handlers; +int rtems_bsdnet_makeFdForSocket(void *so, const rtems_filesystem_file_handlers_r *h); +struct socket *rtems_bsdnet_fdToSocket(int fd); + +/* * Package system call argument into mbuf. */ static int @@ -64,7 +71,7 @@ socket (int domain, int type, int protocol) rtems_bsdnet_semaphore_obtain (); error = socreate(domain, &so, type, protocol, NULL); if (error == 0) { - fd = rtems_bsdnet_makeFdForSocket (so); + fd = rtems_bsdnet_makeFdForSocket (so, &socket_handlers); if (fd < 0) soclose (so); } @@ -213,7 +220,7 @@ accept (int s, struct sockaddr *name, int *namelen) TAILQ_REMOVE(&head->so_comp, so, so_list); head->so_qlen--; - fd = rtems_bsdnet_makeFdForSocket (so); + fd = rtems_bsdnet_makeFdForSocket (so, &socket_handlers); if (fd < 0) { TAILQ_INSERT_HEAD(&head->so_comp, so, so_list); head->so_qlen++; @@ -600,17 +607,18 @@ getsockname (int s, struct sockaddr *name, int *namelen) /* ************************************************************************ - * RTEMS EXTERNAL I/O HANDLER ROUTINES * + * RTEMS I/O HANDLER ROUTINES * ************************************************************************ */ static int -rtems_bsdnet_close (int fd) +rtems_bsdnet_close (rtems_libio_t *iop) { struct socket *so; int error; rtems_bsdnet_semaphore_obtain (); - if ((so = rtems_bsdnet_fdToSocket (fd)) == NULL) { + if ((so = iop->data1) == NULL) { + errno = EBADF; rtems_bsdnet_semaphore_release (); return -1; } @@ -624,15 +632,15 @@ rtems_bsdnet_close (int fd) } static int -rtems_bsdnet_read (int fd, void *buffer, unsigned32 count) +rtems_bsdnet_read (rtems_libio_t *iop, void *buffer, unsigned32 count) { - return recv (fd, buffer, count, 0); + return recv (iop->data0, buffer, count, 0); } static int -rtems_bsdnet_write (int fd, const void *buffer, unsigned32 count) +rtems_bsdnet_write (rtems_libio_t *iop, const void *buffer, unsigned32 count) { - return send (fd, buffer, count, 0); + return send (iop->data0, buffer, count, 0); } static int @@ -659,13 +667,14 @@ so_ioctl (struct socket *so, unsigned32 command, void *buffer) } static int -rtems_bsdnet_ioctl (int fd, unsigned32 command, void *buffer) +rtems_bsdnet_ioctl (rtems_libio_t *iop, unsigned32 command, void *buffer) { struct socket *so; int error; rtems_bsdnet_semaphore_obtain (); - if ((so = rtems_bsdnet_fdToSocket (fd)) == NULL) { + if ((so = iop->data1) == NULL) { + errno = EBADF; rtems_bsdnet_semaphore_release (); return -1; } @@ -678,12 +687,24 @@ rtems_bsdnet_ioctl (int fd, unsigned32 command, void *buffer) return 0; } -rtems_libio_handler_t rtems_bsdnet_io_handler = { +static int +rtems_bsdnet_fstat (rtems_filesystem_location_info_t *loc, struct stat *sp) +{ + sp->st_mode = S_IFSOCK; + return 0; +} + +static const rtems_filesystem_file_handlers_r socket_handlers = { NULL, /* open */ rtems_bsdnet_close, /* close */ rtems_bsdnet_read, /* read */ rtems_bsdnet_write, /* write */ rtems_bsdnet_ioctl, /* ioctl */ NULL, /* lseek */ + rtems_bsdnet_fstat, /* fstat */ + NULL, /* fchmod */ + NULL, /* ftruncate */ + NULL, /* fpathconf */ + NULL, /* fsync */ + NULL, /* fdatasync */ }; - diff --git a/c/src/lib/include/rtems/libio.h b/c/src/lib/include/rtems/libio.h index 740574f303..1cbfef383b 100644 --- a/c/src/lib/include/rtems/libio.h +++ b/c/src/lib/include/rtems/libio.h @@ -397,15 +397,8 @@ typedef struct { #define LIBIO_FLAGS_APPEND 0x0200 /* all writes append */ #define LIBIO_FLAGS_CREATE 0x0400 /* create file */ #define LIBIO_FLAGS_CLOSE_ON_EXEC 0x0800 /* close on process exec() */ - -#define LIBIO_FLAGS_HANDLER_SHIFT 12 -#define LIBIO_FLAGS_HANDLER_MASK 0xF000 /* mask for external handler type */ -#define LIBIO_FLAGS_HANDLER_RTEMS 0x0000 /* `traditional' RTEMS I/O */ -#define LIBIO_FLAGS_HANDLER_SOCK 0x1000 /* BSD socket */ - #define LIBIO_FLAGS_READ_WRITE (LIBIO_FLAGS_READ | LIBIO_FLAGS_WRITE) - void rtems_libio_init(void); /* @@ -446,35 +439,6 @@ typedef int (*rtems_libio_lseek_t)( int whence ); -typedef struct { - rtems_libio_open_t open; - rtems_libio_close_t close; - rtems_libio_read_t read; - rtems_libio_write_t write; - rtems_libio_ioctl_t ioctl; - rtems_libio_lseek_t lseek; -} rtems_libio_handler_t; - -/* - * Register a set of external handlers - */ - -void rtems_register_libio_handler( - int handler_flag, - const rtems_libio_handler_t *handler -); - -/* - * Macros to assist in management of external IO handlers. - */ - -#define RTEMS_FILE_DESCRIPTOR_TYPE_FILE 0x0000 -#define RTEMS_FILE_DESCRIPTOR_TYPE_SOCKET 0x1000 -#define rtems_make_file_descriptor(fd,flags) ((fd)|(flags)) -#define rtems_file_descriptor_base(fd) ((fd) & 0x0FFF) -#define rtems_file_descriptor_type(fd) ((fd) & 0xF000) -#define rtems_file_descriptor_type_index(fd) ((((fd) & 0xF000) >> 12) - 1) - /* * IOCTL values */ diff --git a/c/src/lib/include/rtems/libio_.h b/c/src/lib/include/rtems/libio_.h index 995809b6d5..16dc708f53 100644 --- a/c/src/lib/include/rtems/libio_.h +++ b/c/src/lib/include/rtems/libio_.h @@ -68,15 +68,6 @@ extern rtems_libio_t *rtems_libio_last_iop; extern rtems_libio_t *rtems_libio_iop_freelist; /* - * External I/O Handlers Table - * - * Space for all possible handlers is preallocated - * to speed up dispatch to external handlers. - */ - -extern rtems_libio_handler_t rtems_libio_handlers[15]; - -/* * Default mode for all files. */ diff --git a/c/src/lib/libc/close.c b/c/src/lib/libc/close.c index 04c269664b..ba69847533 100644 --- a/c/src/lib/libc/close.c +++ b/c/src/lib/libc/close.c @@ -20,35 +20,17 @@ int close( { rtems_libio_t *iop; rtems_status_code rc; - int status; rtems_libio_check_fd(fd); iop = rtems_libio_iop(fd); rtems_libio_check_is_open(iop); - if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) { - int (*fp)(int fd); - fp = rtems_libio_handlers[ - (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].close; - if ( fp == NULL ) - set_errno_and_return_minus_one( EBADF ); - status = (*fp)( fd ); - return status; - } - - if ( !iop->handlers ) - set_errno_and_return_minus_one( EBADF ); - - if ( !iop->handlers->close ) - set_errno_and_return_minus_one( ENOTSUP ); - - rc = (*iop->handlers->close)( iop ); + rc = RTEMS_SUCCESSFUL; + if ( iop->handlers->close ) + rc = (*iop->handlers->close)( iop ); rtems_libio_free( iop ); - if (rc != RTEMS_SUCCESSFUL) - set_errno_and_return_minus_one( rc ); - return rc; } diff --git a/c/src/lib/libc/fchmod.c b/c/src/lib/libc/fchmod.c index 46c64cd6f7..a964c737ea 100644 --- a/c/src/lib/libc/fchmod.c +++ b/c/src/lib/libc/fchmod.c @@ -32,13 +32,6 @@ int fchmod( rtems_libio_check_is_open(iop); /* - * If this is not a file system based entity, it is an error. - */ - - if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) - set_errno_and_return_minus_one( EBADF ); - - /* * Now process the fchmod(). */ diff --git a/c/src/lib/libc/fcntl.c b/c/src/lib/libc/fcntl.c index a89306c9fc..7673049a58 100644 --- a/c/src/lib/libc/fcntl.c +++ b/c/src/lib/libc/fcntl.c @@ -37,13 +37,6 @@ int fcntl( rtems_libio_check_is_open(iop); /* - * If this is not a file system based entity, it is an error. - */ - - if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) - set_errno_and_return_minus_one( EBADF ); - - /* * Now process the fcntl(). */ diff --git a/c/src/lib/libc/fdatasync.c b/c/src/lib/libc/fdatasync.c index 7de28ce38a..e1f47848bf 100644 --- a/c/src/lib/libc/fdatasync.c +++ b/c/src/lib/libc/fdatasync.c @@ -28,14 +28,6 @@ int fdatasync( rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE ); /* - * If this file descriptor is mapped to an external set of handlers, - * then pass the request on to them. - */ - - if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) - set_errno_and_return_minus_one( EBADF ); - - /* * Now process the fdatasync(). */ diff --git a/c/src/lib/libc/fpathconf.c b/c/src/lib/libc/fpathconf.c index 97c392b5af..b8cede80ff 100644 --- a/c/src/lib/libc/fpathconf.c +++ b/c/src/lib/libc/fpathconf.c @@ -32,15 +32,6 @@ long fpathconf( rtems_libio_check_permissions(iop, LIBIO_FLAGS_READ); /* - * If this file descriptor is mapped to an external set of handlers, - * then it is an error since fpathconf() is not included in the - * set. - */ - - if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) - set_errno_and_return_minus_one( EBADF ); - - /* * Now process the information request. */ diff --git a/c/src/lib/libc/fstat.c b/c/src/lib/libc/fstat.c index 0399518532..7fdc2a4b8a 100644 --- a/c/src/lib/libc/fstat.c +++ b/c/src/lib/libc/fstat.c @@ -33,34 +33,6 @@ int fstat( set_errno_and_return_minus_one( EFAULT ); /* - * Zero out the stat structure so the various support - * versions of stat don't have to. - */ - - memset( sbuf, 0, sizeof(struct stat) ); - - /* - * If this file descriptor is mapped to an external set of handlers, - * then pass the request on to them. - */ - - if (rtems_file_descriptor_type(fd)) { - switch (rtems_file_descriptor_type (fd)) { - case RTEMS_FILE_DESCRIPTOR_TYPE_FILE: - break; - - case RTEMS_FILE_DESCRIPTOR_TYPE_SOCKET: -#if !defined(__GO32__) - sbuf->st_mode = S_IFSOCK; - break; -#endif - - default: - set_errno_and_return_minus_one( EBADF ); - } - } - - /* * Now process the stat() request. */ @@ -68,9 +40,18 @@ int fstat( rtems_libio_check_fd( fd ); rtems_libio_check_is_open(iop); + if ( !iop->handlers ) + set_errno_and_return_minus_one( EBADF ); + if ( !iop->handlers->fstat ) set_errno_and_return_minus_one( ENOTSUP ); + /* + * Zero out the stat structure so the various support + * versions of stat don't have to. + */ + memset( sbuf, 0, sizeof(struct stat) ); + return (*iop->handlers->fstat)( &iop->pathinfo, sbuf ); } diff --git a/c/src/lib/libc/fsync.c b/c/src/lib/libc/fsync.c index eef1f85171..e2bad3bb2e 100644 --- a/c/src/lib/libc/fsync.c +++ b/c/src/lib/libc/fsync.c @@ -28,14 +28,6 @@ int fsync( rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE ); /* - * If this file descriptor is mapped to an external set of handlers, - * then pass the request on to them. - */ - - if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) - set_errno_and_return_minus_one( EBADF ); - - /* * Now process the fsync(). */ diff --git a/c/src/lib/libc/ftruncate.c b/c/src/lib/libc/ftruncate.c index 0e90db5c79..0112817981 100644 --- a/c/src/lib/libc/ftruncate.c +++ b/c/src/lib/libc/ftruncate.c @@ -30,13 +30,6 @@ int ftruncate( rtems_libio_check_is_open(iop); /* - * If this is not a file system based entity, it is an error. - */ - - if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) - set_errno_and_return_minus_one( EBADF ); - - /* * Now process the ftruncate() request. */ diff --git a/c/src/lib/libc/ioctl.c b/c/src/lib/libc/ioctl.c index 5ac530b6e0..0e8072588b 100644 --- a/c/src/lib/libc/ioctl.c +++ b/c/src/lib/libc/ioctl.c @@ -31,22 +31,6 @@ int ioctl( rtems_libio_check_is_open(iop); /* - * If this file descriptor is mapped to an external set of handlers, - * then pass the request on to them. - */ - - if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) { - rtems_libio_ioctl_t fp; - - fp = rtems_libio_handlers[ - (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].ioctl; - if ( fp == NULL ) - set_errno_and_return_minus_one( EBADF ); - - return (*fp)( fd, command, buffer ); - } - - /* * Now process the ioctl(). */ diff --git a/c/src/lib/libc/libio.c b/c/src/lib/libc/libio.c index 88aea9b62f..59b7086a03 100644 --- a/c/src/lib/libc/libio.c +++ b/c/src/lib/libc/libio.c @@ -50,44 +50,12 @@ rtems_libio_t *rtems_libio_last_iop; rtems_libio_t *rtems_libio_iop_freelist; /* - * External I/O Handlers Table - * - * Space for all possible handlers is preallocated - * to speed up dispatch to external handlers. - */ - -rtems_libio_handler_t rtems_libio_handlers[15]; - -/* * Default mode for all files. */ mode_t rtems_filesystem_umask; /* - * rtems_register_libio_handler - * - * This function registers an external IO handler set. This lets - * other subsystems have their own versions of many of the system - * calls. For example, the networking code registers handlers which - * map the system calls for read() and write() to socket calls. - * - */ - -void rtems_register_libio_handler( - int handler_flag, - const rtems_libio_handler_t *handler -) -{ - int handler_index = (handler_flag >> LIBIO_FLAGS_HANDLER_SHIFT) - 1; - - if ((handler_index < 0) || (handler_index >= 15)) - rtems_fatal_error_occurred( RTEMS_INVALID_NUMBER ); - - rtems_libio_handlers[handler_index] = *handler; -} - -/* * rtems_libio_init * * Called by BSP startup code to initialize the libio subsystem. diff --git a/c/src/lib/libc/libio.h b/c/src/lib/libc/libio.h index 740574f303..1cbfef383b 100644 --- a/c/src/lib/libc/libio.h +++ b/c/src/lib/libc/libio.h @@ -397,15 +397,8 @@ typedef struct { #define LIBIO_FLAGS_APPEND 0x0200 /* all writes append */ #define LIBIO_FLAGS_CREATE 0x0400 /* create file */ #define LIBIO_FLAGS_CLOSE_ON_EXEC 0x0800 /* close on process exec() */ - -#define LIBIO_FLAGS_HANDLER_SHIFT 12 -#define LIBIO_FLAGS_HANDLER_MASK 0xF000 /* mask for external handler type */ -#define LIBIO_FLAGS_HANDLER_RTEMS 0x0000 /* `traditional' RTEMS I/O */ -#define LIBIO_FLAGS_HANDLER_SOCK 0x1000 /* BSD socket */ - #define LIBIO_FLAGS_READ_WRITE (LIBIO_FLAGS_READ | LIBIO_FLAGS_WRITE) - void rtems_libio_init(void); /* @@ -446,35 +439,6 @@ typedef int (*rtems_libio_lseek_t)( int whence ); -typedef struct { - rtems_libio_open_t open; - rtems_libio_close_t close; - rtems_libio_read_t read; - rtems_libio_write_t write; - rtems_libio_ioctl_t ioctl; - rtems_libio_lseek_t lseek; -} rtems_libio_handler_t; - -/* - * Register a set of external handlers - */ - -void rtems_register_libio_handler( - int handler_flag, - const rtems_libio_handler_t *handler -); - -/* - * Macros to assist in management of external IO handlers. - */ - -#define RTEMS_FILE_DESCRIPTOR_TYPE_FILE 0x0000 -#define RTEMS_FILE_DESCRIPTOR_TYPE_SOCKET 0x1000 -#define rtems_make_file_descriptor(fd,flags) ((fd)|(flags)) -#define rtems_file_descriptor_base(fd) ((fd) & 0x0FFF) -#define rtems_file_descriptor_type(fd) ((fd) & 0xF000) -#define rtems_file_descriptor_type_index(fd) ((((fd) & 0xF000) >> 12) - 1) - /* * IOCTL values */ diff --git a/c/src/lib/libc/libio_.h b/c/src/lib/libc/libio_.h index 995809b6d5..16dc708f53 100644 --- a/c/src/lib/libc/libio_.h +++ b/c/src/lib/libc/libio_.h @@ -68,15 +68,6 @@ extern rtems_libio_t *rtems_libio_last_iop; extern rtems_libio_t *rtems_libio_iop_freelist; /* - * External I/O Handlers Table - * - * Space for all possible handlers is preallocated - * to speed up dispatch to external handlers. - */ - -extern rtems_libio_handler_t rtems_libio_handlers[15]; - -/* * Default mode for all files. */ diff --git a/c/src/lib/libc/libio_sockets.c b/c/src/lib/libc/libio_sockets.c index cb1d5a7bdd..8d21120f3d 100644 --- a/c/src/lib/libc/libio_sockets.c +++ b/c/src/lib/libc/libio_sockets.c @@ -18,7 +18,6 @@ #include <errno.h> - /* * Convert an RTEMS file descriptor to a BSD socket pointer. */ @@ -29,11 +28,13 @@ struct socket *rtems_bsdnet_fdToSocket( { rtems_libio_t *iop; - if ((unsigned32)fd >= rtems_libio_number_iops) - return NULL; + if ((unsigned32)fd >= rtems_libio_number_iops) { + errno = EBADF; + return NULL; + } iop = &rtems_libio_iops[fd]; - if ((iop->flags & LIBIO_FLAGS_HANDLER_MASK) != LIBIO_FLAGS_HANDLER_SOCK) - return NULL; + if (iop->data1 == NULL) + errno = EBADF; return iop->data1; } @@ -42,17 +43,22 @@ struct socket *rtems_bsdnet_fdToSocket( */ int rtems_bsdnet_makeFdForSocket( - void *so + void *so, + const rtems_filesystem_file_handlers_r *h ) { rtems_libio_t *iop; + int fd; iop = rtems_libio_allocate(); if (iop == 0) { errno = ENFILE; return -1; } - iop->flags |= LIBIO_FLAGS_HANDLER_SOCK | LIBIO_FLAGS_WRITE | LIBIO_FLAGS_READ; + fd = iop - rtems_libio_iops; + iop->flags |= LIBIO_FLAGS_WRITE | LIBIO_FLAGS_READ; + iop->data0 = fd; iop->data1 = so; - return iop - rtems_libio_iops; + iop->handlers = h; + return fd; } diff --git a/c/src/lib/libc/lseek.c b/c/src/lib/libc/lseek.c index 3e586bbc31..6f37f3c294 100644 --- a/c/src/lib/libc/lseek.c +++ b/c/src/lib/libc/lseek.c @@ -29,22 +29,6 @@ off_t lseek( rtems_libio_check_is_open(iop); /* - * If this file descriptor is mapped to an external set of handlers, - * then pass the request on to them. - */ - - if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) { - rtems_libio_lseek_t fp; - - fp = rtems_libio_handlers[ - (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].lseek; - if ( fp == NULL ) - set_errno_and_return_minus_one( EBADF ); - - return (*fp)( fd, offset, whence ); - } - - /* * Now process the lseek(). */ diff --git a/c/src/lib/libc/read.c b/c/src/lib/libc/read.c index e2866744a4..360fc75f66 100644 --- a/c/src/lib/libc/read.c +++ b/c/src/lib/libc/read.c @@ -31,22 +31,6 @@ ssize_t read( rtems_libio_check_permissions( iop, LIBIO_FLAGS_READ ); /* - * If this file descriptor is mapped to an external set of handlers, - * then pass the request on to them. - */ - - if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) { - rtems_libio_read_t fp; - - fp = rtems_libio_handlers[ - (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].read; - if ( fp == NULL ) - set_errno_and_return_minus_one( EBADF ); - - return (*fp)( fd, buffer, count ); - } - - /* * Now process the read(). */ diff --git a/c/src/lib/libc/write.c b/c/src/lib/libc/write.c index 13dc90bb89..a3eca4eccd 100644 --- a/c/src/lib/libc/write.c +++ b/c/src/lib/libc/write.c @@ -39,22 +39,6 @@ ssize_t write( rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE ); /* - * If this file descriptor is mapped to an external set of handlers, - * then pass the request on to them. - */ - - if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) { - rtems_libio_write_t fp; - - fp = rtems_libio_handlers[ - (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].write; - if ( fp == NULL ) - set_errno_and_return_minus_one( EBADF ); - - return (*fp)( fd, buffer, count ); - } - - /* * Now process the write() request. */ diff --git a/c/src/lib/libnetworking/rtems/rtems_bsdnet_internal.h b/c/src/lib/libnetworking/rtems/rtems_bsdnet_internal.h index 8cbba180d6..adaecbd5f9 100644 --- a/c/src/lib/libnetworking/rtems/rtems_bsdnet_internal.h +++ b/c/src/lib/libnetworking/rtems/rtems_bsdnet_internal.h @@ -174,8 +174,6 @@ void arpintr (void); void bootpc_init(void); int socket (int, int, int); int ioctl (int, unsigned long, ...); -struct socket *rtems_bsdnet_fdToSocket (int fd); -int rtems_bsdnet_makeFdForSocket (void *); /* * Events used by networking routines. diff --git a/c/src/lib/libnetworking/rtems/rtems_glue.c b/c/src/lib/libnetworking/rtems/rtems_glue.c index 5eb885e70e..0601e5659f 100644 --- a/c/src/lib/libnetworking/rtems/rtems_glue.c +++ b/c/src/lib/libnetworking/rtems/rtems_glue.c @@ -78,8 +78,6 @@ struct in_addr rtems_bsdnet_nameserver[sizeof rtems_bsdnet_config.name_server / sizeof rtems_bsdnet_config.name_server[0]]; int rtems_bsdnet_nameserver_count; -extern rtems_libio_handler_t rtems_bsdnet_io_handler; - /* * Perform FreeBSD memory allocation. * FIXME: This should be modified to keep memory allocation statistics. @@ -231,12 +229,6 @@ rtems_bsdnet_initialize (void) networkDaemonTid = rtems_bsdnet_newproc ("ntwk", 4096, networkDaemon, NULL); /* - * Register as an external I/O handler - */ - rtems_register_libio_handler (LIBIO_FLAGS_HANDLER_SOCK, - &rtems_bsdnet_io_handler); - - /* * Let other network tasks begin */ rtems_bsdnet_semaphore_release (); diff --git a/c/src/lib/libnetworking/rtems/rtems_select.c b/c/src/lib/libnetworking/rtems/rtems_select.c index 2487edf9fc..972bf2d650 100644 --- a/c/src/lib/libnetworking/rtems/rtems_select.c +++ b/c/src/lib/libnetworking/rtems/rtems_select.c @@ -46,6 +46,7 @@ */ static __inline int imin(int a, int b) { return (a < b ? a : b); } +struct socket *rtems_bsdnet_fdToSocket(int fd); static int socket_select (struct socket *so, int which, rtems_id tid) diff --git a/c/src/lib/libnetworking/rtems/rtems_syscall.c b/c/src/lib/libnetworking/rtems/rtems_syscall.c index 4a871f78fb..141b7ceeba 100644 --- a/c/src/lib/libnetworking/rtems/rtems_syscall.c +++ b/c/src/lib/libnetworking/rtems/rtems_syscall.c @@ -26,6 +26,13 @@ #include <net/route.h> /* + * Hooks to RTEMS I/O system + */ +static const rtems_filesystem_file_handlers_r socket_handlers; +int rtems_bsdnet_makeFdForSocket(void *so, const rtems_filesystem_file_handlers_r *h); +struct socket *rtems_bsdnet_fdToSocket(int fd); + +/* * Package system call argument into mbuf. */ static int @@ -64,7 +71,7 @@ socket (int domain, int type, int protocol) rtems_bsdnet_semaphore_obtain (); error = socreate(domain, &so, type, protocol, NULL); if (error == 0) { - fd = rtems_bsdnet_makeFdForSocket (so); + fd = rtems_bsdnet_makeFdForSocket (so, &socket_handlers); if (fd < 0) soclose (so); } @@ -213,7 +220,7 @@ accept (int s, struct sockaddr *name, int *namelen) TAILQ_REMOVE(&head->so_comp, so, so_list); head->so_qlen--; - fd = rtems_bsdnet_makeFdForSocket (so); + fd = rtems_bsdnet_makeFdForSocket (so, &socket_handlers); if (fd < 0) { TAILQ_INSERT_HEAD(&head->so_comp, so, so_list); head->so_qlen++; @@ -600,17 +607,18 @@ getsockname (int s, struct sockaddr *name, int *namelen) /* ************************************************************************ - * RTEMS EXTERNAL I/O HANDLER ROUTINES * + * RTEMS I/O HANDLER ROUTINES * ************************************************************************ */ static int -rtems_bsdnet_close (int fd) +rtems_bsdnet_close (rtems_libio_t *iop) { struct socket *so; int error; rtems_bsdnet_semaphore_obtain (); - if ((so = rtems_bsdnet_fdToSocket (fd)) == NULL) { + if ((so = iop->data1) == NULL) { + errno = EBADF; rtems_bsdnet_semaphore_release (); return -1; } @@ -624,15 +632,15 @@ rtems_bsdnet_close (int fd) } static int -rtems_bsdnet_read (int fd, void *buffer, unsigned32 count) +rtems_bsdnet_read (rtems_libio_t *iop, void *buffer, unsigned32 count) { - return recv (fd, buffer, count, 0); + return recv (iop->data0, buffer, count, 0); } static int -rtems_bsdnet_write (int fd, const void *buffer, unsigned32 count) +rtems_bsdnet_write (rtems_libio_t *iop, const void *buffer, unsigned32 count) { - return send (fd, buffer, count, 0); + return send (iop->data0, buffer, count, 0); } static int @@ -659,13 +667,14 @@ so_ioctl (struct socket *so, unsigned32 command, void *buffer) } static int -rtems_bsdnet_ioctl (int fd, unsigned32 command, void *buffer) +rtems_bsdnet_ioctl (rtems_libio_t *iop, unsigned32 command, void *buffer) { struct socket *so; int error; rtems_bsdnet_semaphore_obtain (); - if ((so = rtems_bsdnet_fdToSocket (fd)) == NULL) { + if ((so = iop->data1) == NULL) { + errno = EBADF; rtems_bsdnet_semaphore_release (); return -1; } @@ -678,12 +687,24 @@ rtems_bsdnet_ioctl (int fd, unsigned32 command, void *buffer) return 0; } -rtems_libio_handler_t rtems_bsdnet_io_handler = { +static int +rtems_bsdnet_fstat (rtems_filesystem_location_info_t *loc, struct stat *sp) +{ + sp->st_mode = S_IFSOCK; + return 0; +} + +static const rtems_filesystem_file_handlers_r socket_handlers = { NULL, /* open */ rtems_bsdnet_close, /* close */ rtems_bsdnet_read, /* read */ rtems_bsdnet_write, /* write */ rtems_bsdnet_ioctl, /* ioctl */ NULL, /* lseek */ + rtems_bsdnet_fstat, /* fstat */ + NULL, /* fchmod */ + NULL, /* ftruncate */ + NULL, /* fpathconf */ + NULL, /* fsync */ + NULL, /* fdatasync */ }; - diff --git a/c/src/libnetworking/rtems/rtems_bsdnet_internal.h b/c/src/libnetworking/rtems/rtems_bsdnet_internal.h index 8cbba180d6..adaecbd5f9 100644 --- a/c/src/libnetworking/rtems/rtems_bsdnet_internal.h +++ b/c/src/libnetworking/rtems/rtems_bsdnet_internal.h @@ -174,8 +174,6 @@ void arpintr (void); void bootpc_init(void); int socket (int, int, int); int ioctl (int, unsigned long, ...); -struct socket *rtems_bsdnet_fdToSocket (int fd); -int rtems_bsdnet_makeFdForSocket (void *); /* * Events used by networking routines. diff --git a/c/src/libnetworking/rtems/rtems_glue.c b/c/src/libnetworking/rtems/rtems_glue.c index 5eb885e70e..0601e5659f 100644 --- a/c/src/libnetworking/rtems/rtems_glue.c +++ b/c/src/libnetworking/rtems/rtems_glue.c @@ -78,8 +78,6 @@ struct in_addr rtems_bsdnet_nameserver[sizeof rtems_bsdnet_config.name_server / sizeof rtems_bsdnet_config.name_server[0]]; int rtems_bsdnet_nameserver_count; -extern rtems_libio_handler_t rtems_bsdnet_io_handler; - /* * Perform FreeBSD memory allocation. * FIXME: This should be modified to keep memory allocation statistics. @@ -231,12 +229,6 @@ rtems_bsdnet_initialize (void) networkDaemonTid = rtems_bsdnet_newproc ("ntwk", 4096, networkDaemon, NULL); /* - * Register as an external I/O handler - */ - rtems_register_libio_handler (LIBIO_FLAGS_HANDLER_SOCK, - &rtems_bsdnet_io_handler); - - /* * Let other network tasks begin */ rtems_bsdnet_semaphore_release (); diff --git a/c/src/libnetworking/rtems/rtems_select.c b/c/src/libnetworking/rtems/rtems_select.c index 2487edf9fc..972bf2d650 100644 --- a/c/src/libnetworking/rtems/rtems_select.c +++ b/c/src/libnetworking/rtems/rtems_select.c @@ -46,6 +46,7 @@ */ static __inline int imin(int a, int b) { return (a < b ? a : b); } +struct socket *rtems_bsdnet_fdToSocket(int fd); static int socket_select (struct socket *so, int which, rtems_id tid) diff --git a/c/src/libnetworking/rtems/rtems_syscall.c b/c/src/libnetworking/rtems/rtems_syscall.c index 4a871f78fb..141b7ceeba 100644 --- a/c/src/libnetworking/rtems/rtems_syscall.c +++ b/c/src/libnetworking/rtems/rtems_syscall.c @@ -26,6 +26,13 @@ #include <net/route.h> /* + * Hooks to RTEMS I/O system + */ +static const rtems_filesystem_file_handlers_r socket_handlers; +int rtems_bsdnet_makeFdForSocket(void *so, const rtems_filesystem_file_handlers_r *h); +struct socket *rtems_bsdnet_fdToSocket(int fd); + +/* * Package system call argument into mbuf. */ static int @@ -64,7 +71,7 @@ socket (int domain, int type, int protocol) rtems_bsdnet_semaphore_obtain (); error = socreate(domain, &so, type, protocol, NULL); if (error == 0) { - fd = rtems_bsdnet_makeFdForSocket (so); + fd = rtems_bsdnet_makeFdForSocket (so, &socket_handlers); if (fd < 0) soclose (so); } @@ -213,7 +220,7 @@ accept (int s, struct sockaddr *name, int *namelen) TAILQ_REMOVE(&head->so_comp, so, so_list); head->so_qlen--; - fd = rtems_bsdnet_makeFdForSocket (so); + fd = rtems_bsdnet_makeFdForSocket (so, &socket_handlers); if (fd < 0) { TAILQ_INSERT_HEAD(&head->so_comp, so, so_list); head->so_qlen++; @@ -600,17 +607,18 @@ getsockname (int s, struct sockaddr *name, int *namelen) /* ************************************************************************ - * RTEMS EXTERNAL I/O HANDLER ROUTINES * + * RTEMS I/O HANDLER ROUTINES * ************************************************************************ */ static int -rtems_bsdnet_close (int fd) +rtems_bsdnet_close (rtems_libio_t *iop) { struct socket *so; int error; rtems_bsdnet_semaphore_obtain (); - if ((so = rtems_bsdnet_fdToSocket (fd)) == NULL) { + if ((so = iop->data1) == NULL) { + errno = EBADF; rtems_bsdnet_semaphore_release (); return -1; } @@ -624,15 +632,15 @@ rtems_bsdnet_close (int fd) } static int -rtems_bsdnet_read (int fd, void *buffer, unsigned32 count) +rtems_bsdnet_read (rtems_libio_t *iop, void *buffer, unsigned32 count) { - return recv (fd, buffer, count, 0); + return recv (iop->data0, buffer, count, 0); } static int -rtems_bsdnet_write (int fd, const void *buffer, unsigned32 count) +rtems_bsdnet_write (rtems_libio_t *iop, const void *buffer, unsigned32 count) { - return send (fd, buffer, count, 0); + return send (iop->data0, buffer, count, 0); } static int @@ -659,13 +667,14 @@ so_ioctl (struct socket *so, unsigned32 command, void *buffer) } static int -rtems_bsdnet_ioctl (int fd, unsigned32 command, void *buffer) +rtems_bsdnet_ioctl (rtems_libio_t *iop, unsigned32 command, void *buffer) { struct socket *so; int error; rtems_bsdnet_semaphore_obtain (); - if ((so = rtems_bsdnet_fdToSocket (fd)) == NULL) { + if ((so = iop->data1) == NULL) { + errno = EBADF; rtems_bsdnet_semaphore_release (); return -1; } @@ -678,12 +687,24 @@ rtems_bsdnet_ioctl (int fd, unsigned32 command, void *buffer) return 0; } -rtems_libio_handler_t rtems_bsdnet_io_handler = { +static int +rtems_bsdnet_fstat (rtems_filesystem_location_info_t *loc, struct stat *sp) +{ + sp->st_mode = S_IFSOCK; + return 0; +} + +static const rtems_filesystem_file_handlers_r socket_handlers = { NULL, /* open */ rtems_bsdnet_close, /* close */ rtems_bsdnet_read, /* read */ rtems_bsdnet_write, /* write */ rtems_bsdnet_ioctl, /* ioctl */ NULL, /* lseek */ + rtems_bsdnet_fstat, /* fstat */ + NULL, /* fchmod */ + NULL, /* ftruncate */ + NULL, /* fpathconf */ + NULL, /* fsync */ + NULL, /* fdatasync */ }; - |