summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libc
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>1999-03-01 22:40:08 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>1999-03-01 22:40:08 +0000
commit73f6236bc09b3cadf0aa030e16396154421f3e30 (patch)
tree30c344abe6e8091d860d583e0a1342af575ae791 /c/src/lib/libc
parentPart of the automake VI patch from Ralf Corsepius <corsepiu@faw.uni-ulm.de>: (diff)
downloadrtems-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/src/lib/libc')
-rw-r--r--c/src/lib/libc/close.c24
-rw-r--r--c/src/lib/libc/fchmod.c7
-rw-r--r--c/src/lib/libc/fcntl.c7
-rw-r--r--c/src/lib/libc/fdatasync.c8
-rw-r--r--c/src/lib/libc/fpathconf.c9
-rw-r--r--c/src/lib/libc/fstat.c37
-rw-r--r--c/src/lib/libc/fsync.c8
-rw-r--r--c/src/lib/libc/ftruncate.c7
-rw-r--r--c/src/lib/libc/ioctl.c16
-rw-r--r--c/src/lib/libc/libio.c32
-rw-r--r--c/src/lib/libc/libio.h36
-rw-r--r--c/src/lib/libc/libio_.h9
-rw-r--r--c/src/lib/libc/libio_sockets.c22
-rw-r--r--c/src/lib/libc/lseek.c16
-rw-r--r--c/src/lib/libc/read.c16
-rw-r--r--c/src/lib/libc/write.c16
16 files changed, 26 insertions, 244 deletions
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.
*/