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 /cpukit/libcsupport/src | |
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 '')
-rw-r--r-- | cpukit/libcsupport/src/close.c | 24 | ||||
-rw-r--r-- | cpukit/libcsupport/src/fchmod.c | 7 | ||||
-rw-r--r-- | cpukit/libcsupport/src/fcntl.c | 7 | ||||
-rw-r--r-- | cpukit/libcsupport/src/fdatasync.c | 8 | ||||
-rw-r--r-- | cpukit/libcsupport/src/fpathconf.c | 9 | ||||
-rw-r--r-- | cpukit/libcsupport/src/fstat.c | 37 | ||||
-rw-r--r-- | cpukit/libcsupport/src/fsync.c | 8 | ||||
-rw-r--r-- | cpukit/libcsupport/src/ftruncate.c | 7 | ||||
-rw-r--r-- | cpukit/libcsupport/src/ioctl.c | 16 | ||||
-rw-r--r-- | cpukit/libcsupport/src/libio.c | 32 | ||||
-rw-r--r-- | cpukit/libcsupport/src/libio_sockets.c | 22 | ||||
-rw-r--r-- | cpukit/libcsupport/src/lseek.c | 16 | ||||
-rw-r--r-- | cpukit/libcsupport/src/read.c | 16 | ||||
-rw-r--r-- | cpukit/libcsupport/src/write.c | 16 |
14 files changed, 26 insertions, 199 deletions
diff --git a/cpukit/libcsupport/src/close.c b/cpukit/libcsupport/src/close.c index 04c269664b..ba69847533 100644 --- a/cpukit/libcsupport/src/close.c +++ b/cpukit/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/cpukit/libcsupport/src/fchmod.c b/cpukit/libcsupport/src/fchmod.c index 46c64cd6f7..a964c737ea 100644 --- a/cpukit/libcsupport/src/fchmod.c +++ b/cpukit/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/cpukit/libcsupport/src/fcntl.c b/cpukit/libcsupport/src/fcntl.c index a89306c9fc..7673049a58 100644 --- a/cpukit/libcsupport/src/fcntl.c +++ b/cpukit/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/cpukit/libcsupport/src/fdatasync.c b/cpukit/libcsupport/src/fdatasync.c index 7de28ce38a..e1f47848bf 100644 --- a/cpukit/libcsupport/src/fdatasync.c +++ b/cpukit/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/cpukit/libcsupport/src/fpathconf.c b/cpukit/libcsupport/src/fpathconf.c index 97c392b5af..b8cede80ff 100644 --- a/cpukit/libcsupport/src/fpathconf.c +++ b/cpukit/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/cpukit/libcsupport/src/fstat.c b/cpukit/libcsupport/src/fstat.c index 0399518532..7fdc2a4b8a 100644 --- a/cpukit/libcsupport/src/fstat.c +++ b/cpukit/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/cpukit/libcsupport/src/fsync.c b/cpukit/libcsupport/src/fsync.c index eef1f85171..e2bad3bb2e 100644 --- a/cpukit/libcsupport/src/fsync.c +++ b/cpukit/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/cpukit/libcsupport/src/ftruncate.c b/cpukit/libcsupport/src/ftruncate.c index 0e90db5c79..0112817981 100644 --- a/cpukit/libcsupport/src/ftruncate.c +++ b/cpukit/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/cpukit/libcsupport/src/ioctl.c b/cpukit/libcsupport/src/ioctl.c index 5ac530b6e0..0e8072588b 100644 --- a/cpukit/libcsupport/src/ioctl.c +++ b/cpukit/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/cpukit/libcsupport/src/libio.c b/cpukit/libcsupport/src/libio.c index 88aea9b62f..59b7086a03 100644 --- a/cpukit/libcsupport/src/libio.c +++ b/cpukit/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/cpukit/libcsupport/src/libio_sockets.c b/cpukit/libcsupport/src/libio_sockets.c index cb1d5a7bdd..8d21120f3d 100644 --- a/cpukit/libcsupport/src/libio_sockets.c +++ b/cpukit/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/cpukit/libcsupport/src/lseek.c b/cpukit/libcsupport/src/lseek.c index 3e586bbc31..6f37f3c294 100644 --- a/cpukit/libcsupport/src/lseek.c +++ b/cpukit/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/cpukit/libcsupport/src/read.c b/cpukit/libcsupport/src/read.c index e2866744a4..360fc75f66 100644 --- a/cpukit/libcsupport/src/read.c +++ b/cpukit/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/cpukit/libcsupport/src/write.c b/cpukit/libcsupport/src/write.c index 13dc90bb89..a3eca4eccd 100644 --- a/cpukit/libcsupport/src/write.c +++ b/cpukit/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. */ |