summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libc
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>1997-04-09 14:05:50 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>1997-04-09 14:05:50 +0000
commite2d795597310f976af211f9bac2466dbf89b50c8 (patch)
tree7d3053fa42d08569c75a1add4c5715a5fc8ff4fa /c/src/lib/libc
parentadded cast to eliminate warning. (diff)
downloadrtems-e2d795597310f976af211f9bac2466dbf89b50c8.tar.bz2
Added ka9q tcpip stack and network driver for the gen68360. This effort
was done based on the 3.6.0 release and had to be autoconf'ed locally. It is turned on is the bsp enables it and it is not explicitly disabled via the configure option --disable-tcpip. As many warnings as possible were removed locally after the code was merged. Only the gen68360 and mvme136 bsps were compiled this way. The ka9q port and network driver were submitted by Eric Norum (eric@skatter.USask.Ca). The network demo programs are not included in the tree at this point.
Diffstat (limited to 'c/src/lib/libc')
-rw-r--r--c/src/lib/libc/libio.c106
-rw-r--r--c/src/lib/libc/libio.h22
2 files changed, 114 insertions, 14 deletions
diff --git a/c/src/lib/libc/libio.c b/c/src/lib/libc/libio.c
index 3a7325c422..ec10184a10 100644
--- a/c/src/lib/libc/libio.c
+++ b/c/src/lib/libc/libio.c
@@ -79,12 +79,34 @@ rtems_libio_t *rtems_libio_last_iop;
} \
} while (0)
+/*
+ * External I/O handlers
+ *
+ * Space for all possible handlers is preallocated
+ * to speed up dispatch to external handlers.
+ */
+
+static rtems_libio_handler_t handlers[15];
+
+void
+rtems_register_libio_handler(
+ int handler_flag,
+ const rtems_libio_handler_t *handler
+)
+{
+ int handler_index = rtems_file_descriptor_type_index(handler_flag);
+
+ if ((handler_index < 0) || (handler_index >= 15))
+ rtems_fatal_error_occurred( RTEMS_INVALID_NUMBER );
+ handlers[handler_index] = *handler;
+}
+
void
rtems_libio_config(
rtems_configuration_table *config,
unsigned32 max_fds
- )
+)
{
rtems_libio_number_iops = max_fds;
@@ -253,15 +275,16 @@ __rtems_open(
rtems_driver_name_t *np;
rtems_libio_open_close_args_t args;
- if ((rc = rtems_io_lookup_name(pathname, &np)) != RTEMS_SUCCESSFUL) {
-/*
- if ( rc == RTEMS_UNSATISFIED ) {
- puts( "open -- ENOSYS case" );
- assert( 0 );
- }
-*/
+ /*
+ * Additional external I/O handlers would be supported by
+ * adding code to pick apart the pathname appropriately.
+ * The networking code does not require changes here since
+ * network file descriptors are obtained using socket(), not
+ * open().
+ */
+
+ if ((rc = rtems_io_lookup_name(pathname, &np)) != RTEMS_SUCCESSFUL)
goto done;
- }
iop = rtems_libio_allocate();
if (iop == 0)
@@ -299,9 +322,20 @@ __rtems_close(
{
rtems_status_code rc;
rtems_driver_name_t *np;
- rtems_libio_t *iop = rtems_libio_iop(fd);
+ rtems_libio_t *iop;
rtems_libio_open_close_args_t args;
+ if (rtems_file_descriptor_type(fd)) {
+ int (*fp)(int fd);
+
+ fp = handlers[rtems_file_descriptor_type_index(fd)].close;
+ if (fp == NULL) {
+ errno = EBADF;
+ return -1;
+ }
+ return (*fp)(fd);
+ }
+ iop = rtems_libio_iop(fd);
rtems_libio_check_fd(fd);
np = iop->driver;
@@ -326,9 +360,20 @@ __rtems_read(
{
rtems_status_code rc;
rtems_driver_name_t *np;
- rtems_libio_t *iop = rtems_libio_iop(fd);
+ rtems_libio_t *iop;
rtems_libio_rw_args_t args;
+ if (rtems_file_descriptor_type(fd)) {
+ int (*fp)(int fd, void *buffer, unsigned32 count);
+
+ fp = handlers[rtems_file_descriptor_type_index(fd)].read;
+ if (fp == NULL) {
+ errno = EBADF;
+ return -1;
+ }
+ return (*fp)(fd, buffer, count);
+ }
+ iop = rtems_libio_iop(fd);
rtems_libio_check_fd(fd);
rtems_libio_check_buffer(buffer);
rtems_libio_check_count(count);
@@ -362,9 +407,20 @@ __rtems_write(
{
rtems_status_code rc;
rtems_driver_name_t *np;
- rtems_libio_t *iop = rtems_libio_iop(fd);
+ rtems_libio_t *iop;
rtems_libio_rw_args_t args;
+ if (rtems_file_descriptor_type(fd)) {
+ int (*fp)(int fd, const void *buffer, unsigned32 count);
+
+ fp = handlers[rtems_file_descriptor_type_index(fd)].write;
+ if (fp == NULL) {
+ errno = EBADF;
+ return -1;
+ }
+ return (*fp)(fd, buffer, count);
+ }
+ iop = rtems_libio_iop(fd);
rtems_libio_check_fd(fd);
rtems_libio_check_buffer(buffer);
rtems_libio_check_count(count);
@@ -397,9 +453,20 @@ __rtems_ioctl(
{
rtems_status_code rc;
rtems_driver_name_t *np;
- rtems_libio_t *iop = rtems_libio_iop(fd);
+ rtems_libio_t *iop;
rtems_libio_ioctl_args_t args;
+ if (rtems_file_descriptor_type(fd)) {
+ int (*fp)(int fd, unsigned32 command, void *buffer);
+
+ fp = handlers[rtems_file_descriptor_type_index(fd)].ioctl;
+ if (fp == NULL) {
+ errno = EBADF;
+ return -1;
+ }
+ return (*fp)(fd, command, buffer);
+ }
+ iop = rtems_libio_iop(fd);
rtems_libio_check_fd(fd);
np = iop->driver;
@@ -428,8 +495,19 @@ __rtems_lseek(
int whence
)
{
- rtems_libio_t *iop = rtems_libio_iop(fd);
+ rtems_libio_t *iop;
+
+ if (rtems_file_descriptor_type(fd)) {
+ int (*fp)(int fd, rtems_libio_offset_t offset, int whence);
+ fp = handlers[rtems_file_descriptor_type_index(fd)].lseek;
+ if (fp == NULL) {
+ errno = EBADF;
+ return -1;
+ }
+ return (*fp)(fd, offset, whence);
+ }
+ iop = rtems_libio_iop(fd);
rtems_libio_check_fd(fd);
switch (whence)
diff --git a/c/src/lib/libc/libio.h b/c/src/lib/libc/libio.h
index b518100484..c79dfc2e33 100644
--- a/c/src/lib/libc/libio.h
+++ b/c/src/lib/libc/libio.h
@@ -99,4 +99,26 @@ int __rtems_lseek(int fd, rtems_libio_offset_t offset, int whence);
int __rtems_fstat(int _fd, struct stat* _sbuf);
int __rtems_isatty(int _fd);
+/*
+ * External I/O handlers
+ */
+typedef struct {
+ int (*open)(const char *pathname, unsigned32 flag, unsigned32 mode);
+ int (*close)(int fd);
+ int (*read)(int fd, void *buffer, unsigned32 count);
+ int (*write)(int fd, const void *buffer, unsigned32 count);
+ int (*ioctl)(int fd, unsigned32 command, void *buffer);
+ int (*lseek)(int fd, rtems_libio_offset_t offset, int whence);
+} rtems_libio_handler_t;
+
+void rtems_register_libio_handler(int handler_flag,
+ const rtems_libio_handler_t *handler);
+
+#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)
+
#endif /* _RTEMS_LIBIO_H */