Merged Eric Norum's select patch that was based on 4.0 and resolved

all conflicts.
This commit is contained in:
Joel Sherrill
1998-12-10 23:31:54 +00:00
parent 6c98012877
commit cca44008d8
64 changed files with 589 additions and 845 deletions

View File

@@ -2,4 +2,4 @@
# $Id$ # $Id$
# #
RTEMS Version 19981203 RTEMS Version 4.0.0

View File

@@ -65,6 +65,7 @@ extern rtems_id rtems_libio_semaphore;
extern unsigned32 rtems_libio_number_iops; extern unsigned32 rtems_libio_number_iops;
extern rtems_libio_t *rtems_libio_iops; extern rtems_libio_t *rtems_libio_iops;
extern rtems_libio_t *rtems_libio_last_iop; extern rtems_libio_t *rtems_libio_last_iop;
extern rtems_libio_t *rtems_libio_iop_freelist;
/* /*
* External I/O Handlers Table * External I/O Handlers Table

View File

@@ -393,12 +393,16 @@ typedef struct {
#define LIBIO_FLAGS_NO_DELAY 0x0001 /* return immediately if no data */ #define LIBIO_FLAGS_NO_DELAY 0x0001 /* return immediately if no data */
#define LIBIO_FLAGS_READ 0x0002 /* reading */ #define LIBIO_FLAGS_READ 0x0002 /* reading */
#define LIBIO_FLAGS_WRITE 0x0004 /* writing */ #define LIBIO_FLAGS_WRITE 0x0004 /* writing */
#define LIBIO_FLAGS_LINE_BUFFERED 0x0008 /* line buffered io (^h, ^u, etc) */
#define LIBIO_FLAGS_OPEN 0x0100 /* device is open */ #define LIBIO_FLAGS_OPEN 0x0100 /* device is open */
#define LIBIO_FLAGS_APPEND 0x0200 /* all writes append */ #define LIBIO_FLAGS_APPEND 0x0200 /* all writes append */
#define LIBIO_FLAGS_CREATE 0x0400 /* create file */ #define LIBIO_FLAGS_CREATE 0x0400 /* create file */
#define LIBIO_FLAGS_CLOSE_ON_EXEC 0x0800 /* close on process exec() */ #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) #define LIBIO_FLAGS_READ_WRITE (LIBIO_FLAGS_READ | LIBIO_FLAGS_WRITE)

View File

@@ -65,6 +65,7 @@ extern rtems_id rtems_libio_semaphore;
extern unsigned32 rtems_libio_number_iops; extern unsigned32 rtems_libio_number_iops;
extern rtems_libio_t *rtems_libio_iops; extern rtems_libio_t *rtems_libio_iops;
extern rtems_libio_t *rtems_libio_last_iop; extern rtems_libio_t *rtems_libio_last_iop;
extern rtems_libio_t *rtems_libio_iop_freelist;
/* /*
* External I/O Handlers Table * External I/O Handlers Table

View File

@@ -83,11 +83,10 @@
#define SIOCSIFMEDIA _IOWR('i', 55, struct ifreq) /* set net media */ #define SIOCSIFMEDIA _IOWR('i', 55, struct ifreq) /* set net media */
#define SIOCGIFMEDIA _IOWR('i', 56, struct ifmediareq) /* get net media */ #define SIOCGIFMEDIA _IOWR('i', 56, struct ifmediareq) /* get net media */
/* /*
* RTEMS additions for setting/getting `tap' function on incoming packets. * RTEMS additions for setting/getting `tap' function on incoming packets.
*/ */
#define SIOCSIFTAP _IOW('i', 80, struct ifreq) /* set tap function */ #define SIOCSIFTAP _IOW('i', 80, struct ifreq) /* set tap function */
#define SIOCGIFTAP _IOWR('i', 81, struct ifreq) /* get tap function */ #define SIOCGIFTAP _IOW('i', 81, struct ifreq) /* get tap function */
#endif /* !_SYS_SOCKIO_H_ */ #endif /* !_SYS_SOCKIO_H_ */

View File

@@ -22,17 +22,18 @@ int close(
rtems_status_code rc; rtems_status_code rc;
int status; int status;
if ( rtems_file_descriptor_type( fd ) ) { rtems_libio_check_fd(fd);
iop = rtems_libio_iop(fd);
if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) {
int (*fp)(int fd); int (*fp)(int fd);
fp = rtems_libio_handlers[rtems_file_descriptor_type_index(fd)].close; fp = rtems_libio_handlers[
(iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].close;
if ( fp == NULL ) if ( fp == NULL )
set_errno_and_return_minus_one( EBADF ); set_errno_and_return_minus_one( EBADF );
status = (*fp)( fd ); status = (*fp)( fd );
return status; return status;
} }
iop = rtems_libio_iop(fd);
rtems_libio_check_fd(fd);
if ( !iop->handlers ) if ( !iop->handlers )
set_errno_and_return_minus_one( EBADF ); set_errno_and_return_minus_one( EBADF );

View File

@@ -27,19 +27,20 @@ int fchmod(
{ {
rtems_libio_t *iop; rtems_libio_t *iop;
rtems_libio_check_fd( fd );
iop = rtems_libio_iop( fd );
/* /*
* If this is not a file system based entity, it is an error. * If this is not a file system based entity, it is an error.
*/ */
if ( rtems_file_descriptor_type( fd ) ) if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK )
set_errno_and_return_minus_one( EBADF ); set_errno_and_return_minus_one( EBADF );
/* /*
* Now process the fchmod(). * Now process the fchmod().
*/ */
iop = rtems_libio_iop( fd );
rtems_libio_check_fd( fd );
rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE ); rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE );
if ( !iop->handlers->fchmod ) if ( !iop->handlers->fchmod )

View File

@@ -32,20 +32,20 @@ int fcntl(
va_start( ap, cmd ); va_start( ap, cmd );
rtems_libio_check_fd( fd );
iop = rtems_libio_iop( fd );
/* /*
* If this is not a file system based entity, it is an error. * If this is not a file system based entity, it is an error.
*/ */
if ( rtems_file_descriptor_type( fd ) ) if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK )
set_errno_and_return_minus_one( EBADF ); set_errno_and_return_minus_one( EBADF );
/* /*
* Now process the fcntl(). * Now process the fcntl().
*/ */
iop = rtems_libio_iop( fd );
rtems_libio_check_fd( fd );
/* /*
* This switch should contain all the cases from POSIX. * This switch should contain all the cases from POSIX.
*/ */

View File

@@ -22,22 +22,22 @@ int fdatasync(
{ {
rtems_libio_t *iop; rtems_libio_t *iop;
rtems_libio_check_fd( fd );
iop = rtems_libio_iop( fd );
rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE );
/* /*
* If this file descriptor is mapped to an external set of handlers, * If this file descriptor is mapped to an external set of handlers,
* then pass the request on to them. * then pass the request on to them.
*/ */
if ( rtems_file_descriptor_type( fd ) ) if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK )
set_errno_and_return_minus_one( EBADF ); set_errno_and_return_minus_one( EBADF );
/* /*
* Now process the fdatasync(). * Now process the fdatasync().
*/ */
iop = rtems_libio_iop( fd );
rtems_libio_check_fd( fd );
rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE );
if ( !iop->handlers->fdatasync ) if ( !iop->handlers->fdatasync )
set_errno_and_return_minus_one( ENOTSUP ); set_errno_and_return_minus_one( ENOTSUP );

View File

@@ -26,23 +26,23 @@ long fpathconf(
rtems_libio_t *iop; rtems_libio_t *iop;
rtems_filesystem_limits_and_options_t *the_limits; rtems_filesystem_limits_and_options_t *the_limits;
rtems_libio_check_fd(fd);
iop = rtems_libio_iop(fd);
rtems_libio_check_permissions(iop, LIBIO_FLAGS_READ);
/* /*
* If this file descriptor is mapped to an external set of handlers, * If this file descriptor is mapped to an external set of handlers,
* then it is an error since fpathconf() is not included in the * then it is an error since fpathconf() is not included in the
* set. * set.
*/ */
if ( rtems_file_descriptor_type( fd ) ) if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK )
set_errno_and_return_minus_one( EBADF ); set_errno_and_return_minus_one( EBADF );
/* /*
* Now process the information request. * Now process the information request.
*/ */
iop = rtems_libio_iop(fd);
rtems_libio_check_fd(fd);
rtems_libio_check_permissions(iop, LIBIO_FLAGS_READ);
the_limits = &iop->pathinfo.mt_entry->pathconf_limits_and_options; the_limits = &iop->pathinfo.mt_entry->pathconf_limits_and_options;
switch ( name ) { switch ( name ) {

View File

@@ -22,22 +22,22 @@ int fsync(
{ {
rtems_libio_t *iop; rtems_libio_t *iop;
rtems_libio_check_fd( fd );
iop = rtems_libio_iop( fd );
rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE );
/* /*
* If this file descriptor is mapped to an external set of handlers, * If this file descriptor is mapped to an external set of handlers,
* then pass the request on to them. * then pass the request on to them.
*/ */
if ( rtems_file_descriptor_type( fd ) ) if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK )
set_errno_and_return_minus_one( EBADF ); set_errno_and_return_minus_one( EBADF );
/* /*
* Now process the fsync(). * Now process the fsync().
*/ */
iop = rtems_libio_iop( fd );
rtems_libio_check_fd( fd );
rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE );
if ( !iop->handlers->fsync ) if ( !iop->handlers->fsync )
set_errno_and_return_minus_one( ENOTSUP ); set_errno_and_return_minus_one( ENOTSUP );

View File

@@ -25,19 +25,20 @@ int ftruncate(
rtems_libio_t *iop; rtems_libio_t *iop;
rtems_filesystem_location_info_t loc; rtems_filesystem_location_info_t loc;
rtems_libio_check_fd( fd );
iop = rtems_libio_iop( fd );
/* /*
* If this is not a file system based entity, it is an error. * If this is not a file system based entity, it is an error.
*/ */
if ( rtems_file_descriptor_type( fd ) ) if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK )
set_errno_and_return_minus_one( EBADF ); set_errno_and_return_minus_one( EBADF );
/* /*
* Now process the ftruncate() request. * Now process the ftruncate() request.
*/ */
iop = rtems_libio_iop( fd );
/* /*
* Make sure we are not working on a directory * Make sure we are not working on a directory
*/ */
@@ -49,7 +50,6 @@ int ftruncate(
if ( (*loc.ops->node_type)( &loc ) == RTEMS_FILESYSTEM_DIRECTORY ) if ( (*loc.ops->node_type)( &loc ) == RTEMS_FILESYSTEM_DIRECTORY )
set_errno_and_return_minus_one( EISDIR ); set_errno_and_return_minus_one( EISDIR );
rtems_libio_check_fd( fd );
rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE ); rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE );
if ( !iop->handlers->ftruncate ) if ( !iop->handlers->ftruncate )

View File

@@ -26,15 +26,19 @@ int ioctl(
rtems_status_code rc; rtems_status_code rc;
rtems_libio_t *iop; rtems_libio_t *iop;
rtems_libio_check_fd( fd );
iop = rtems_libio_iop( fd );
/* /*
* If this file descriptor is mapped to an external set of handlers, * If this file descriptor is mapped to an external set of handlers,
* then pass the request on to them. * then pass the request on to them.
*/ */
if ( rtems_file_descriptor_type( fd ) ) { if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) {
rtems_libio_ioctl_t fp; rtems_libio_ioctl_t fp;
fp = rtems_libio_handlers[rtems_file_descriptor_type_index(fd)].ioctl; fp = rtems_libio_handlers[
(iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].ioctl;
if ( fp == NULL ) if ( fp == NULL )
set_errno_and_return_minus_one( EBADF ); set_errno_and_return_minus_one( EBADF );
@@ -45,9 +49,6 @@ int ioctl(
* Now process the ioctl(). * Now process the ioctl().
*/ */
iop = rtems_libio_iop( fd );
rtems_libio_check_fd( fd );
if ( !iop->handlers->ioctl ) if ( !iop->handlers->ioctl )
set_errno_and_return_minus_one( ENOTSUP ); set_errno_and_return_minus_one( ENOTSUP );

View File

@@ -3,9 +3,6 @@
* table of integer style file descriptors used by the low level * table of integer style file descriptors used by the low level
* POSIX system calls like open(), read, fstat(), etc. * POSIX system calls like open(), read, fstat(), etc.
* *
* This provides the foundation for POSIX compliant IO system calls
* for RTEMS.
*
* COPYRIGHT (c) 1989-1998. * COPYRIGHT (c) 1989-1998.
* On-Line Applications Research Corporation (OAR). * On-Line Applications Research Corporation (OAR).
* Copyright assigned to U.S. Government, 1994. * Copyright assigned to U.S. Government, 1994.
@@ -18,17 +15,55 @@
*/ */
#include "libio_.h" /* libio_.h pulls in rtems */ #include "libio_.h" /* libio_.h pulls in rtems */
#include <rtems.h>
#include <rtems/assoc.h> /* assoc.h not included by rtems.h */
#include <stdio.h> /* O_RDONLY, et.al. */
#include <fcntl.h> /* O_RDONLY, et.al. */
#include <assert.h>
#include <errno.h>
#if ! defined(O_NDELAY)
# if defined(solaris2)
# define O_NDELAY O_NONBLOCK
# elif defined(RTEMS_NEWLIB)
# define O_NDELAY _FNBIO
# endif
#endif
#include <errno.h>
#include <string.h> /* strcmp */
#include <unistd.h>
#include <stdlib.h> /* calloc() */
#include "libio.h" /* libio.h not pulled in by rtems */
/* /*
* Global variables used to manage the File Descriptor Table. * File descriptor Table Information
* IOP = IO Pointer.
*/ */
extern unsigned32 rtems_libio_number_iops;
rtems_id rtems_libio_semaphore; rtems_id rtems_libio_semaphore;
rtems_libio_t *rtems_libio_iops; rtems_libio_t *rtems_libio_iops;
rtems_libio_t *rtems_libio_last_iop; 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]; rtems_libio_handler_t rtems_libio_handlers[15];
/*
* Default mode for all files.
*/
mode_t rtems_filesystem_umask;
/* /*
* rtems_register_libio_handler * rtems_register_libio_handler
* *
@@ -44,8 +79,7 @@ void rtems_register_libio_handler(
const rtems_libio_handler_t *handler const rtems_libio_handler_t *handler
) )
{ {
int handler_index = rtems_file_descriptor_type_index( handler_flag ); int handler_index = (handler_flag >> LIBIO_FLAGS_HANDLER_SHIFT) - 1;
if ((handler_index < 0) || (handler_index >= 15)) if ((handler_index < 0) || (handler_index >= 15))
rtems_fatal_error_occurred( RTEMS_INVALID_NUMBER ); rtems_fatal_error_occurred( RTEMS_INVALID_NUMBER );
@@ -62,19 +96,20 @@ void rtems_register_libio_handler(
void rtems_libio_init( void ) void rtems_libio_init( void )
{ {
rtems_status_code rc; rtems_status_code rc;
int i;
rtems_libio_t *iop;
/* if (rtems_libio_number_iops > 0)
* Allocate memory for the IOP Table {
*/ rtems_libio_iops = (rtems_libio_t *) calloc(rtems_libio_number_iops,
sizeof(rtems_libio_t));
if ( rtems_libio_number_iops > 0 ) {
rtems_libio_iops =
(rtems_libio_t *) calloc(rtems_libio_number_iops, sizeof(rtems_libio_t));
if (rtems_libio_iops == NULL) if (rtems_libio_iops == NULL)
rtems_fatal_error_occurred( RTEMS_NO_MEMORY ); rtems_fatal_error_occurred(RTEMS_NO_MEMORY);
rtems_libio_last_iop = rtems_libio_iops + (rtems_libio_number_iops - 1); iop = rtems_libio_iop_freelist = rtems_libio_iops;
for (i = 0 ; i < (rtems_libio_number_iops - 1) ; i++, iop++)
iop->data1 = iop + 1;
iop->data1 = NULL;
} }
/* /*
@@ -157,12 +192,8 @@ rtems_libio_t *rtems_libio_allocate( void )
rtems_semaphore_obtain( rtems_libio_semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT ); rtems_semaphore_obtain( rtems_libio_semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT );
for (iop = rtems_libio_iops; iop <= rtems_libio_last_iop; iop++) if (rtems_libio_iop_freelist) {
if ((iop->flags & LIBIO_FLAGS_OPEN) == 0) { iop = rtems_libio_iop_freelist;
/*
* Got an IOP -- create a semaphore for it.
*/
rc = rtems_semaphore_create( rc = rtems_semaphore_create(
RTEMS_LIBIO_IOP_SEM(iop - rtems_libio_iops), RTEMS_LIBIO_IOP_SEM(iop - rtems_libio_iops),
1, 1,
@@ -170,9 +201,10 @@ rtems_libio_t *rtems_libio_allocate( void )
RTEMS_NO_PRIORITY, RTEMS_NO_PRIORITY,
&iop->sem &iop->sem
); );
if ( rc != RTEMS_SUCCESSFUL ) if (rc != RTEMS_SUCCESSFUL)
goto failed; goto failed;
rtems_libio_iop_freelist = iop->data1;
iop->data1 = 0;
iop->flags = LIBIO_FLAGS_OPEN; iop->flags = LIBIO_FLAGS_OPEN;
goto done; goto done;
} }
@@ -201,16 +233,17 @@ void rtems_libio_free(
if (iop->sem) if (iop->sem)
rtems_semaphore_delete(iop->sem); rtems_semaphore_delete(iop->sem);
(void) memset(iop, 0, sizeof(*iop)); iop->data1 = rtems_libio_iop_freelist;
rtems_libio_iop_freelist = iop;
rtems_semaphore_release( rtems_libio_semaphore ); rtems_semaphore_release(rtems_libio_semaphore);
} }
/* /*
* rtems_libio_is_open_files_in_fs * rtems_libio_is_open_files_in_fs
* *
* This routine scans the entire file descriptor table to determine if the * This routine scans the entire file descriptor table to determine if the
* are any active file descriptors that refer to the atleast one node in the * are any active file descriptors that refer to the at least one node in the
* file system that we are trying to dismount. * file system that we are trying to dismount.
* *
* If there is at least one node in the file system referenced by the mount * If there is at least one node in the file system referenced by the mount
@@ -293,3 +326,5 @@ int rtems_libio_is_file_open(
return result; return result;
} }

View File

@@ -24,15 +24,19 @@ off_t lseek(
{ {
rtems_libio_t *iop; rtems_libio_t *iop;
rtems_libio_check_fd( fd );
iop = rtems_libio_iop( fd );
/* /*
* If this file descriptor is mapped to an external set of handlers, * If this file descriptor is mapped to an external set of handlers,
* then pass the request on to them. * then pass the request on to them.
*/ */
if ( rtems_file_descriptor_type( fd ) ) { if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) {
rtems_libio_lseek_t fp; rtems_libio_lseek_t fp;
fp = rtems_libio_handlers[rtems_file_descriptor_type_index(fd)].lseek; fp = rtems_libio_handlers[
(iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].lseek;
if ( fp == NULL ) if ( fp == NULL )
set_errno_and_return_minus_one( EBADF ); set_errno_and_return_minus_one( EBADF );
@@ -43,9 +47,6 @@ off_t lseek(
* Now process the lseek(). * Now process the lseek().
*/ */
iop = rtems_libio_iop( fd );
rtems_libio_check_fd( fd );
switch ( whence ) { switch ( whence ) {
case SEEK_SET: case SEEK_SET:
iop->offset = offset; iop->offset = offset;

View File

@@ -26,15 +26,22 @@ int read(
int rc; /* XXX change to a size_t when prototype is fixed */ int rc; /* XXX change to a size_t when prototype is fixed */
rtems_libio_t *iop; rtems_libio_t *iop;
rtems_libio_check_fd( fd );
iop = rtems_libio_iop( fd );
rtems_libio_check_buffer( buffer );
rtems_libio_check_count( count );
rtems_libio_check_permissions( iop, LIBIO_FLAGS_READ );
/* /*
* If this file descriptor is mapped to an external set of handlers, * If this file descriptor is mapped to an external set of handlers,
* then pass the request on to them. * then pass the request on to them.
*/ */
if ( rtems_file_descriptor_type( fd ) ) { if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) {
rtems_libio_read_t fp; rtems_libio_read_t fp;
fp = rtems_libio_handlers[rtems_file_descriptor_type_index(fd)].read; fp = rtems_libio_handlers[
(iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].read;
if ( fp == NULL ) if ( fp == NULL )
set_errno_and_return_minus_one( EBADF ); set_errno_and_return_minus_one( EBADF );
@@ -45,12 +52,6 @@ int read(
* Now process the read(). * Now process the read().
*/ */
iop = rtems_libio_iop( fd );
rtems_libio_check_fd( fd );
rtems_libio_check_buffer( buffer );
rtems_libio_check_count( count );
rtems_libio_check_permissions( iop, LIBIO_FLAGS_READ );
if ( !iop->handlers->read ) if ( !iop->handlers->read )
set_errno_and_return_minus_one( ENOTSUP ); set_errno_and_return_minus_one( ENOTSUP );

View File

@@ -34,15 +34,22 @@ int write( /* XXX this should return a ssize_t */
rtems_status_code rc; rtems_status_code rc;
rtems_libio_t *iop; rtems_libio_t *iop;
rtems_libio_check_fd( fd );
iop = rtems_libio_iop( fd );
rtems_libio_check_buffer( buffer );
rtems_libio_check_count( count );
rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE );
/* /*
* If this file descriptor is mapped to an external set of handlers, * If this file descriptor is mapped to an external set of handlers,
* then pass the request on to them. * then pass the request on to them.
*/ */
if ( rtems_file_descriptor_type( fd ) ) { if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) {
rtems_libio_write_t fp; rtems_libio_write_t fp;
fp = rtems_libio_handlers[rtems_file_descriptor_type_index(fd)].write; fp = rtems_libio_handlers[
(iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].write;
if ( fp == NULL ) if ( fp == NULL )
set_errno_and_return_minus_one( EBADF ); set_errno_and_return_minus_one( EBADF );
@@ -53,12 +60,6 @@ int write( /* XXX this should return a ssize_t */
* Now process the write() request. * Now process the write() request.
*/ */
iop = rtems_libio_iop( fd );
rtems_libio_check_fd( fd );
rtems_libio_check_buffer( buffer );
rtems_libio_check_count( count );
rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE );
if ( !iop->handlers->write ) if ( !iop->handlers->write )
set_errno_and_return_minus_one( ENOTSUP ); set_errno_and_return_minus_one( ENOTSUP );

View File

@@ -30,19 +30,6 @@
#include <net/netisr.h> #include <net/netisr.h>
#include <net/route.h> #include <net/route.h>
/*
* Events used by networking routines.
* Everything will break if the application
* tries to use these events or if the `sleep'
* events are equal to any of the NETISR * events.
*/
#define SBWAIT_EVENT RTEMS_EVENT_24
#define SOSLEEP_EVENT RTEMS_EVENT_25
#define NETISR_IP_EVENT (1 << NETISR_IP)
#define NETISR_ARP_EVENT (1 << NETISR_ARP)
#define NETISR_EVENTS (NETISR_IP_EVENT|NETISR_ARP_EVENT)
/* /*
* Memory allocation * Memory allocation
*/ */
@@ -246,7 +233,7 @@ rtems_bsdnet_initialize (void)
/* /*
* Register as an external I/O handler * Register as an external I/O handler
*/ */
rtems_register_libio_handler (RTEMS_FILE_DESCRIPTOR_TYPE_SOCKET, rtems_register_libio_handler (LIBIO_FLAGS_HANDLER_SOCK,
&rtems_bsdnet_io_handler); &rtems_bsdnet_io_handler);
/* /*
@@ -305,16 +292,9 @@ sbwait(sb)
/* /*
* Set this task as the target of the wakeup operation. * Set this task as the target of the wakeup operation.
*/ */
if (sb->sb_sel.si_pid)
rtems_panic ("Another task is already sleeping on that socket buffer");
rtems_task_ident (RTEMS_SELF, 0, &tid); rtems_task_ident (RTEMS_SELF, 0, &tid);
sb->sb_sel.si_pid = tid; sb->sb_sel.si_pid = tid;
/*
* Mark the socket buffer as waiting.
*/
sb->sb_flags |= SB_WAIT;
/* /*
* Release the network semaphore. * Release the network semaphore.
*/ */
@@ -330,12 +310,6 @@ sbwait(sb)
*/ */
rtems_bsdnet_semaphore_obtain (); rtems_bsdnet_semaphore_obtain ();
/*
* Relinquish ownership of the socket buffer
*/
sb->sb_flags &= ~SB_WAIT;
sb->sb_sel.si_pid = 0;
/* /*
* Return the status of the wait. * Return the status of the wait.
*/ */
@@ -355,9 +329,11 @@ sowakeup(so, sb)
register struct socket *so; register struct socket *so;
register struct sockbuf *sb; register struct sockbuf *sb;
{ {
if (sb->sb_flags & SB_WAIT) { rtems_id tid;
sb->sb_flags &= ~SB_WAIT;
rtems_event_send (sb->sb_sel.si_pid, SBWAIT_EVENT); if ((tid = sb->sb_sel.si_pid) != 0) {
sb->sb_sel.si_pid = 0;
rtems_event_send (tid, SBWAIT_EVENT);
} }
} }

View File

@@ -25,77 +25,6 @@
#include <net/if.h> #include <net/if.h>
#include <net/route.h> #include <net/route.h>
/*
*********************************************************************
* Map RTEMS file descriptor to BSD socket *
*********************************************************************
*/
struct fdsock {
int indexFreeNext;
struct socket *sock;
};
static struct fdsock *fdsock;
static int fdsockCount;
static int indexFreeHead = -1;
/*
* Convert an RTEMS file descriptor to a BSD socket pointer.
*/
static struct socket *
fdToSocket (int fd)
{
int i;
struct socket *s;
if ((fd < 0)
|| (rtems_file_descriptor_type(fd) != RTEMS_FILE_DESCRIPTOR_TYPE_SOCKET)
|| ((i = rtems_file_descriptor_base(fd)) >= fdsockCount)
|| ((s = fdsock[i].sock) == NULL)) {
errno = EBADF;
return NULL;
}
return s;
}
/*
* Enlarge the size of the file-descritor/socket pointer map.
*/
static int
enlargeFdMap (void)
{
struct fdsock *nfdsock;
int i;
nfdsock = realloc (fdsock, sizeof *fdsock * (fdsockCount + 20));
if (nfdsock == NULL) {
errno = ENFILE;
return 0;
}
fdsock = nfdsock;
for (i = fdsockCount, fdsockCount += 20 ; i < fdsockCount ; i++) {
fdsock[i].sock = NULL;
fdsock[i].indexFreeNext = indexFreeHead;
indexFreeHead = i;
}
return 1;
}
/*
* Create a file descriptor for a new socket
*/
static int
makeFd (struct socket *s)
{
int i;
if ((indexFreeHead < 0) && !enlargeFdMap ())
return -1;
i = indexFreeHead;
indexFreeHead = fdsock[i].indexFreeNext;
fdsock[i].sock = s;
return rtems_make_file_descriptor(i,RTEMS_FILE_DESCRIPTOR_TYPE_SOCKET);
}
/* /*
* Package system call argument into mbuf. * Package system call argument into mbuf.
*/ */
@@ -128,14 +57,14 @@ sockargstombuf (struct mbuf **mp, const void *buf, int buflen, int type)
int int
socket (int domain, int type, int protocol) socket (int domain, int type, int protocol)
{ {
int fd = -1; int fd;
int error; int error;
struct socket *so; struct socket *so;
rtems_bsdnet_semaphore_obtain (); rtems_bsdnet_semaphore_obtain ();
error = socreate(domain, &so, type, protocol, NULL); error = socreate(domain, &so, type, protocol, NULL);
if (error == 0) { if (error == 0) {
fd = makeFd (so); fd = rtems_bsdnet_makeFdForSocket (so);
if (fd < 0) if (fd < 0)
soclose (so); soclose (so);
} }
@@ -156,7 +85,7 @@ bind (int s, struct sockaddr *name, int namelen)
struct mbuf *nam; struct mbuf *nam;
rtems_bsdnet_semaphore_obtain (); rtems_bsdnet_semaphore_obtain ();
if ((so = fdToSocket (s)) != NULL) { if ((so = rtems_bsdnet_fdToSocket (s)) != NULL) {
error = sockargstombuf (&nam, name, namelen, MT_SONAME); error = sockargstombuf (&nam, name, namelen, MT_SONAME);
if (error == 0) { if (error == 0) {
error = sobind (so, nam); error = sobind (so, nam);
@@ -183,7 +112,7 @@ connect (int s, struct sockaddr *name, int namelen)
struct mbuf *nam; struct mbuf *nam;
rtems_bsdnet_semaphore_obtain (); rtems_bsdnet_semaphore_obtain ();
if ((so = fdToSocket (s)) == NULL) { if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) {
rtems_bsdnet_semaphore_release (); rtems_bsdnet_semaphore_release ();
return -1; return -1;
} }
@@ -233,7 +162,7 @@ listen (int s, int backlog)
struct socket *so; struct socket *so;
rtems_bsdnet_semaphore_obtain (); rtems_bsdnet_semaphore_obtain ();
if ((so = fdToSocket (s)) != NULL) { if ((so = rtems_bsdnet_fdToSocket (s)) != NULL) {
error = solisten (so, backlog); error = solisten (so, backlog);
if (error == 0) if (error == 0)
ret = 0; ret = 0;
@@ -252,7 +181,7 @@ accept (int s, struct sockaddr *name, int *namelen)
struct mbuf *nam; struct mbuf *nam;
rtems_bsdnet_semaphore_obtain (); rtems_bsdnet_semaphore_obtain ();
if ((head = fdToSocket (s)) == NULL) { if ((head = rtems_bsdnet_fdToSocket (s)) == NULL) {
rtems_bsdnet_semaphore_release (); rtems_bsdnet_semaphore_release ();
return -1; return -1;
} }
@@ -284,7 +213,7 @@ accept (int s, struct sockaddr *name, int *namelen)
TAILQ_REMOVE(&head->so_comp, so, so_list); TAILQ_REMOVE(&head->so_comp, so, so_list);
head->so_qlen--; head->so_qlen--;
fd = makeFd (so); fd = rtems_bsdnet_makeFdForSocket (so);
if (fd < 0) { if (fd < 0) {
TAILQ_INSERT_HEAD(&head->so_comp, so, so_list); TAILQ_INSERT_HEAD(&head->so_comp, so, so_list);
head->so_qlen++; head->so_qlen++;
@@ -325,7 +254,7 @@ sendmsg (int s, const struct msghdr *mp, int flags)
int len; int len;
rtems_bsdnet_semaphore_obtain (); rtems_bsdnet_semaphore_obtain ();
if ((so = fdToSocket (s)) == NULL) { if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) {
rtems_bsdnet_semaphore_release (); rtems_bsdnet_semaphore_release ();
return -1; return -1;
} }
@@ -428,7 +357,7 @@ recvmsg (int s, struct msghdr *mp, int flags)
int len; int len;
rtems_bsdnet_semaphore_obtain (); rtems_bsdnet_semaphore_obtain ();
if ((so = fdToSocket (s)) == NULL) { if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) {
rtems_bsdnet_semaphore_release (); rtems_bsdnet_semaphore_release ();
return -1; return -1;
} }
@@ -547,7 +476,7 @@ setsockopt (int s, int level, int name, const void *val, int len)
int error; int error;
rtems_bsdnet_semaphore_obtain (); rtems_bsdnet_semaphore_obtain ();
if ((so = fdToSocket (s)) == NULL) { if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) {
rtems_bsdnet_semaphore_release (); rtems_bsdnet_semaphore_release ();
return -1; return -1;
} }
@@ -584,7 +513,7 @@ getsockopt (int s, int level, int name, void *aval, int *avalsize)
int error; int error;
rtems_bsdnet_semaphore_obtain (); rtems_bsdnet_semaphore_obtain ();
if ((so = fdToSocket (s)) == NULL) { if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) {
rtems_bsdnet_semaphore_release (); rtems_bsdnet_semaphore_release ();
return -1; return -1;
} }
@@ -626,7 +555,7 @@ getpeersockname (int s, struct sockaddr *name, int *namelen, int pflag)
int error; int error;
rtems_bsdnet_semaphore_obtain (); rtems_bsdnet_semaphore_obtain ();
if ((so = fdToSocket (s)) == NULL) { if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) {
rtems_bsdnet_semaphore_release (); rtems_bsdnet_semaphore_release ();
return -1; return -1;
} }
@@ -676,16 +605,12 @@ rtems_bsdnet_close (int fd)
{ {
struct socket *so; struct socket *so;
int error; int error;
int i;
rtems_bsdnet_semaphore_obtain (); rtems_bsdnet_semaphore_obtain ();
if ((so = fdToSocket (fd)) == NULL) { if ((so = rtems_bsdnet_fdToSocket (fd)) == NULL) {
rtems_bsdnet_semaphore_release (); rtems_bsdnet_semaphore_release ();
return -1; return -1;
} }
i = rtems_file_descriptor_base(fd);
fdsock[i].indexFreeNext = indexFreeHead;;
indexFreeHead = i;
error = soclose (so); error = soclose (so);
rtems_bsdnet_semaphore_release (); rtems_bsdnet_semaphore_release ();
if (error) { if (error) {
@@ -737,7 +662,7 @@ rtems_bsdnet_ioctl (int fd, unsigned32 command, void *buffer)
int error; int error;
rtems_bsdnet_semaphore_obtain (); rtems_bsdnet_semaphore_obtain ();
if ((so = fdToSocket (fd)) == NULL) { if ((so = rtems_bsdnet_fdToSocket (fd)) == NULL) {
rtems_bsdnet_semaphore_release (); rtems_bsdnet_semaphore_release ();
return -1; return -1;
} }

View File

@@ -393,12 +393,16 @@ typedef struct {
#define LIBIO_FLAGS_NO_DELAY 0x0001 /* return immediately if no data */ #define LIBIO_FLAGS_NO_DELAY 0x0001 /* return immediately if no data */
#define LIBIO_FLAGS_READ 0x0002 /* reading */ #define LIBIO_FLAGS_READ 0x0002 /* reading */
#define LIBIO_FLAGS_WRITE 0x0004 /* writing */ #define LIBIO_FLAGS_WRITE 0x0004 /* writing */
#define LIBIO_FLAGS_LINE_BUFFERED 0x0008 /* line buffered io (^h, ^u, etc) */
#define LIBIO_FLAGS_OPEN 0x0100 /* device is open */ #define LIBIO_FLAGS_OPEN 0x0100 /* device is open */
#define LIBIO_FLAGS_APPEND 0x0200 /* all writes append */ #define LIBIO_FLAGS_APPEND 0x0200 /* all writes append */
#define LIBIO_FLAGS_CREATE 0x0400 /* create file */ #define LIBIO_FLAGS_CREATE 0x0400 /* create file */
#define LIBIO_FLAGS_CLOSE_ON_EXEC 0x0800 /* close on process exec() */ #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) #define LIBIO_FLAGS_READ_WRITE (LIBIO_FLAGS_READ | LIBIO_FLAGS_WRITE)

View File

@@ -65,6 +65,7 @@ extern rtems_id rtems_libio_semaphore;
extern unsigned32 rtems_libio_number_iops; extern unsigned32 rtems_libio_number_iops;
extern rtems_libio_t *rtems_libio_iops; extern rtems_libio_t *rtems_libio_iops;
extern rtems_libio_t *rtems_libio_last_iop; extern rtems_libio_t *rtems_libio_last_iop;
extern rtems_libio_t *rtems_libio_iop_freelist;
/* /*
* External I/O Handlers Table * External I/O Handlers Table

View File

@@ -83,11 +83,10 @@
#define SIOCSIFMEDIA _IOWR('i', 55, struct ifreq) /* set net media */ #define SIOCSIFMEDIA _IOWR('i', 55, struct ifreq) /* set net media */
#define SIOCGIFMEDIA _IOWR('i', 56, struct ifmediareq) /* get net media */ #define SIOCGIFMEDIA _IOWR('i', 56, struct ifmediareq) /* get net media */
/* /*
* RTEMS additions for setting/getting `tap' function on incoming packets. * RTEMS additions for setting/getting `tap' function on incoming packets.
*/ */
#define SIOCSIFTAP _IOW('i', 80, struct ifreq) /* set tap function */ #define SIOCSIFTAP _IOW('i', 80, struct ifreq) /* set tap function */
#define SIOCGIFTAP _IOWR('i', 81, struct ifreq) /* get tap function */ #define SIOCGIFTAP _IOW('i', 81, struct ifreq) /* get tap function */
#endif /* !_SYS_SOCKIO_H_ */ #endif /* !_SYS_SOCKIO_H_ */

View File

@@ -22,17 +22,18 @@ int close(
rtems_status_code rc; rtems_status_code rc;
int status; int status;
if ( rtems_file_descriptor_type( fd ) ) { rtems_libio_check_fd(fd);
iop = rtems_libio_iop(fd);
if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) {
int (*fp)(int fd); int (*fp)(int fd);
fp = rtems_libio_handlers[rtems_file_descriptor_type_index(fd)].close; fp = rtems_libio_handlers[
(iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].close;
if ( fp == NULL ) if ( fp == NULL )
set_errno_and_return_minus_one( EBADF ); set_errno_and_return_minus_one( EBADF );
status = (*fp)( fd ); status = (*fp)( fd );
return status; return status;
} }
iop = rtems_libio_iop(fd);
rtems_libio_check_fd(fd);
if ( !iop->handlers ) if ( !iop->handlers )
set_errno_and_return_minus_one( EBADF ); set_errno_and_return_minus_one( EBADF );

View File

@@ -27,19 +27,20 @@ int fchmod(
{ {
rtems_libio_t *iop; rtems_libio_t *iop;
rtems_libio_check_fd( fd );
iop = rtems_libio_iop( fd );
/* /*
* If this is not a file system based entity, it is an error. * If this is not a file system based entity, it is an error.
*/ */
if ( rtems_file_descriptor_type( fd ) ) if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK )
set_errno_and_return_minus_one( EBADF ); set_errno_and_return_minus_one( EBADF );
/* /*
* Now process the fchmod(). * Now process the fchmod().
*/ */
iop = rtems_libio_iop( fd );
rtems_libio_check_fd( fd );
rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE ); rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE );
if ( !iop->handlers->fchmod ) if ( !iop->handlers->fchmod )

View File

@@ -32,20 +32,20 @@ int fcntl(
va_start( ap, cmd ); va_start( ap, cmd );
rtems_libio_check_fd( fd );
iop = rtems_libio_iop( fd );
/* /*
* If this is not a file system based entity, it is an error. * If this is not a file system based entity, it is an error.
*/ */
if ( rtems_file_descriptor_type( fd ) ) if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK )
set_errno_and_return_minus_one( EBADF ); set_errno_and_return_minus_one( EBADF );
/* /*
* Now process the fcntl(). * Now process the fcntl().
*/ */
iop = rtems_libio_iop( fd );
rtems_libio_check_fd( fd );
/* /*
* This switch should contain all the cases from POSIX. * This switch should contain all the cases from POSIX.
*/ */

View File

@@ -22,22 +22,22 @@ int fdatasync(
{ {
rtems_libio_t *iop; rtems_libio_t *iop;
rtems_libio_check_fd( fd );
iop = rtems_libio_iop( fd );
rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE );
/* /*
* If this file descriptor is mapped to an external set of handlers, * If this file descriptor is mapped to an external set of handlers,
* then pass the request on to them. * then pass the request on to them.
*/ */
if ( rtems_file_descriptor_type( fd ) ) if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK )
set_errno_and_return_minus_one( EBADF ); set_errno_and_return_minus_one( EBADF );
/* /*
* Now process the fdatasync(). * Now process the fdatasync().
*/ */
iop = rtems_libio_iop( fd );
rtems_libio_check_fd( fd );
rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE );
if ( !iop->handlers->fdatasync ) if ( !iop->handlers->fdatasync )
set_errno_and_return_minus_one( ENOTSUP ); set_errno_and_return_minus_one( ENOTSUP );

View File

@@ -26,23 +26,23 @@ long fpathconf(
rtems_libio_t *iop; rtems_libio_t *iop;
rtems_filesystem_limits_and_options_t *the_limits; rtems_filesystem_limits_and_options_t *the_limits;
rtems_libio_check_fd(fd);
iop = rtems_libio_iop(fd);
rtems_libio_check_permissions(iop, LIBIO_FLAGS_READ);
/* /*
* If this file descriptor is mapped to an external set of handlers, * If this file descriptor is mapped to an external set of handlers,
* then it is an error since fpathconf() is not included in the * then it is an error since fpathconf() is not included in the
* set. * set.
*/ */
if ( rtems_file_descriptor_type( fd ) ) if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK )
set_errno_and_return_minus_one( EBADF ); set_errno_and_return_minus_one( EBADF );
/* /*
* Now process the information request. * Now process the information request.
*/ */
iop = rtems_libio_iop(fd);
rtems_libio_check_fd(fd);
rtems_libio_check_permissions(iop, LIBIO_FLAGS_READ);
the_limits = &iop->pathinfo.mt_entry->pathconf_limits_and_options; the_limits = &iop->pathinfo.mt_entry->pathconf_limits_and_options;
switch ( name ) { switch ( name ) {

View File

@@ -22,22 +22,22 @@ int fsync(
{ {
rtems_libio_t *iop; rtems_libio_t *iop;
rtems_libio_check_fd( fd );
iop = rtems_libio_iop( fd );
rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE );
/* /*
* If this file descriptor is mapped to an external set of handlers, * If this file descriptor is mapped to an external set of handlers,
* then pass the request on to them. * then pass the request on to them.
*/ */
if ( rtems_file_descriptor_type( fd ) ) if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK )
set_errno_and_return_minus_one( EBADF ); set_errno_and_return_minus_one( EBADF );
/* /*
* Now process the fsync(). * Now process the fsync().
*/ */
iop = rtems_libio_iop( fd );
rtems_libio_check_fd( fd );
rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE );
if ( !iop->handlers->fsync ) if ( !iop->handlers->fsync )
set_errno_and_return_minus_one( ENOTSUP ); set_errno_and_return_minus_one( ENOTSUP );

View File

@@ -25,19 +25,20 @@ int ftruncate(
rtems_libio_t *iop; rtems_libio_t *iop;
rtems_filesystem_location_info_t loc; rtems_filesystem_location_info_t loc;
rtems_libio_check_fd( fd );
iop = rtems_libio_iop( fd );
/* /*
* If this is not a file system based entity, it is an error. * If this is not a file system based entity, it is an error.
*/ */
if ( rtems_file_descriptor_type( fd ) ) if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK )
set_errno_and_return_minus_one( EBADF ); set_errno_and_return_minus_one( EBADF );
/* /*
* Now process the ftruncate() request. * Now process the ftruncate() request.
*/ */
iop = rtems_libio_iop( fd );
/* /*
* Make sure we are not working on a directory * Make sure we are not working on a directory
*/ */
@@ -49,7 +50,6 @@ int ftruncate(
if ( (*loc.ops->node_type)( &loc ) == RTEMS_FILESYSTEM_DIRECTORY ) if ( (*loc.ops->node_type)( &loc ) == RTEMS_FILESYSTEM_DIRECTORY )
set_errno_and_return_minus_one( EISDIR ); set_errno_and_return_minus_one( EISDIR );
rtems_libio_check_fd( fd );
rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE ); rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE );
if ( !iop->handlers->ftruncate ) if ( !iop->handlers->ftruncate )

View File

@@ -26,15 +26,19 @@ int ioctl(
rtems_status_code rc; rtems_status_code rc;
rtems_libio_t *iop; rtems_libio_t *iop;
rtems_libio_check_fd( fd );
iop = rtems_libio_iop( fd );
/* /*
* If this file descriptor is mapped to an external set of handlers, * If this file descriptor is mapped to an external set of handlers,
* then pass the request on to them. * then pass the request on to them.
*/ */
if ( rtems_file_descriptor_type( fd ) ) { if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) {
rtems_libio_ioctl_t fp; rtems_libio_ioctl_t fp;
fp = rtems_libio_handlers[rtems_file_descriptor_type_index(fd)].ioctl; fp = rtems_libio_handlers[
(iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].ioctl;
if ( fp == NULL ) if ( fp == NULL )
set_errno_and_return_minus_one( EBADF ); set_errno_and_return_minus_one( EBADF );
@@ -45,9 +49,6 @@ int ioctl(
* Now process the ioctl(). * Now process the ioctl().
*/ */
iop = rtems_libio_iop( fd );
rtems_libio_check_fd( fd );
if ( !iop->handlers->ioctl ) if ( !iop->handlers->ioctl )
set_errno_and_return_minus_one( ENOTSUP ); set_errno_and_return_minus_one( ENOTSUP );

View File

@@ -3,9 +3,6 @@
* table of integer style file descriptors used by the low level * table of integer style file descriptors used by the low level
* POSIX system calls like open(), read, fstat(), etc. * POSIX system calls like open(), read, fstat(), etc.
* *
* This provides the foundation for POSIX compliant IO system calls
* for RTEMS.
*
* COPYRIGHT (c) 1989-1998. * COPYRIGHT (c) 1989-1998.
* On-Line Applications Research Corporation (OAR). * On-Line Applications Research Corporation (OAR).
* Copyright assigned to U.S. Government, 1994. * Copyright assigned to U.S. Government, 1994.
@@ -18,17 +15,55 @@
*/ */
#include "libio_.h" /* libio_.h pulls in rtems */ #include "libio_.h" /* libio_.h pulls in rtems */
#include <rtems.h>
#include <rtems/assoc.h> /* assoc.h not included by rtems.h */
#include <stdio.h> /* O_RDONLY, et.al. */
#include <fcntl.h> /* O_RDONLY, et.al. */
#include <assert.h>
#include <errno.h>
#if ! defined(O_NDELAY)
# if defined(solaris2)
# define O_NDELAY O_NONBLOCK
# elif defined(RTEMS_NEWLIB)
# define O_NDELAY _FNBIO
# endif
#endif
#include <errno.h>
#include <string.h> /* strcmp */
#include <unistd.h>
#include <stdlib.h> /* calloc() */
#include "libio.h" /* libio.h not pulled in by rtems */
/* /*
* Global variables used to manage the File Descriptor Table. * File descriptor Table Information
* IOP = IO Pointer.
*/ */
extern unsigned32 rtems_libio_number_iops;
rtems_id rtems_libio_semaphore; rtems_id rtems_libio_semaphore;
rtems_libio_t *rtems_libio_iops; rtems_libio_t *rtems_libio_iops;
rtems_libio_t *rtems_libio_last_iop; 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]; rtems_libio_handler_t rtems_libio_handlers[15];
/*
* Default mode for all files.
*/
mode_t rtems_filesystem_umask;
/* /*
* rtems_register_libio_handler * rtems_register_libio_handler
* *
@@ -44,8 +79,7 @@ void rtems_register_libio_handler(
const rtems_libio_handler_t *handler const rtems_libio_handler_t *handler
) )
{ {
int handler_index = rtems_file_descriptor_type_index( handler_flag ); int handler_index = (handler_flag >> LIBIO_FLAGS_HANDLER_SHIFT) - 1;
if ((handler_index < 0) || (handler_index >= 15)) if ((handler_index < 0) || (handler_index >= 15))
rtems_fatal_error_occurred( RTEMS_INVALID_NUMBER ); rtems_fatal_error_occurred( RTEMS_INVALID_NUMBER );
@@ -62,19 +96,20 @@ void rtems_register_libio_handler(
void rtems_libio_init( void ) void rtems_libio_init( void )
{ {
rtems_status_code rc; rtems_status_code rc;
int i;
rtems_libio_t *iop;
/* if (rtems_libio_number_iops > 0)
* Allocate memory for the IOP Table {
*/ rtems_libio_iops = (rtems_libio_t *) calloc(rtems_libio_number_iops,
sizeof(rtems_libio_t));
if ( rtems_libio_number_iops > 0 ) {
rtems_libio_iops =
(rtems_libio_t *) calloc(rtems_libio_number_iops, sizeof(rtems_libio_t));
if (rtems_libio_iops == NULL) if (rtems_libio_iops == NULL)
rtems_fatal_error_occurred( RTEMS_NO_MEMORY ); rtems_fatal_error_occurred(RTEMS_NO_MEMORY);
rtems_libio_last_iop = rtems_libio_iops + (rtems_libio_number_iops - 1); iop = rtems_libio_iop_freelist = rtems_libio_iops;
for (i = 0 ; i < (rtems_libio_number_iops - 1) ; i++, iop++)
iop->data1 = iop + 1;
iop->data1 = NULL;
} }
/* /*
@@ -157,12 +192,8 @@ rtems_libio_t *rtems_libio_allocate( void )
rtems_semaphore_obtain( rtems_libio_semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT ); rtems_semaphore_obtain( rtems_libio_semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT );
for (iop = rtems_libio_iops; iop <= rtems_libio_last_iop; iop++) if (rtems_libio_iop_freelist) {
if ((iop->flags & LIBIO_FLAGS_OPEN) == 0) { iop = rtems_libio_iop_freelist;
/*
* Got an IOP -- create a semaphore for it.
*/
rc = rtems_semaphore_create( rc = rtems_semaphore_create(
RTEMS_LIBIO_IOP_SEM(iop - rtems_libio_iops), RTEMS_LIBIO_IOP_SEM(iop - rtems_libio_iops),
1, 1,
@@ -170,9 +201,10 @@ rtems_libio_t *rtems_libio_allocate( void )
RTEMS_NO_PRIORITY, RTEMS_NO_PRIORITY,
&iop->sem &iop->sem
); );
if ( rc != RTEMS_SUCCESSFUL ) if (rc != RTEMS_SUCCESSFUL)
goto failed; goto failed;
rtems_libio_iop_freelist = iop->data1;
iop->data1 = 0;
iop->flags = LIBIO_FLAGS_OPEN; iop->flags = LIBIO_FLAGS_OPEN;
goto done; goto done;
} }
@@ -201,16 +233,17 @@ void rtems_libio_free(
if (iop->sem) if (iop->sem)
rtems_semaphore_delete(iop->sem); rtems_semaphore_delete(iop->sem);
(void) memset(iop, 0, sizeof(*iop)); iop->data1 = rtems_libio_iop_freelist;
rtems_libio_iop_freelist = iop;
rtems_semaphore_release( rtems_libio_semaphore ); rtems_semaphore_release(rtems_libio_semaphore);
} }
/* /*
* rtems_libio_is_open_files_in_fs * rtems_libio_is_open_files_in_fs
* *
* This routine scans the entire file descriptor table to determine if the * This routine scans the entire file descriptor table to determine if the
* are any active file descriptors that refer to the atleast one node in the * are any active file descriptors that refer to the at least one node in the
* file system that we are trying to dismount. * file system that we are trying to dismount.
* *
* If there is at least one node in the file system referenced by the mount * If there is at least one node in the file system referenced by the mount
@@ -293,3 +326,5 @@ int rtems_libio_is_file_open(
return result; return result;
} }

View File

@@ -393,12 +393,16 @@ typedef struct {
#define LIBIO_FLAGS_NO_DELAY 0x0001 /* return immediately if no data */ #define LIBIO_FLAGS_NO_DELAY 0x0001 /* return immediately if no data */
#define LIBIO_FLAGS_READ 0x0002 /* reading */ #define LIBIO_FLAGS_READ 0x0002 /* reading */
#define LIBIO_FLAGS_WRITE 0x0004 /* writing */ #define LIBIO_FLAGS_WRITE 0x0004 /* writing */
#define LIBIO_FLAGS_LINE_BUFFERED 0x0008 /* line buffered io (^h, ^u, etc) */
#define LIBIO_FLAGS_OPEN 0x0100 /* device is open */ #define LIBIO_FLAGS_OPEN 0x0100 /* device is open */
#define LIBIO_FLAGS_APPEND 0x0200 /* all writes append */ #define LIBIO_FLAGS_APPEND 0x0200 /* all writes append */
#define LIBIO_FLAGS_CREATE 0x0400 /* create file */ #define LIBIO_FLAGS_CREATE 0x0400 /* create file */
#define LIBIO_FLAGS_CLOSE_ON_EXEC 0x0800 /* close on process exec() */ #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) #define LIBIO_FLAGS_READ_WRITE (LIBIO_FLAGS_READ | LIBIO_FLAGS_WRITE)

View File

@@ -65,6 +65,7 @@ extern rtems_id rtems_libio_semaphore;
extern unsigned32 rtems_libio_number_iops; extern unsigned32 rtems_libio_number_iops;
extern rtems_libio_t *rtems_libio_iops; extern rtems_libio_t *rtems_libio_iops;
extern rtems_libio_t *rtems_libio_last_iop; extern rtems_libio_t *rtems_libio_last_iop;
extern rtems_libio_t *rtems_libio_iop_freelist;
/* /*
* External I/O Handlers Table * External I/O Handlers Table

View File

@@ -24,15 +24,19 @@ off_t lseek(
{ {
rtems_libio_t *iop; rtems_libio_t *iop;
rtems_libio_check_fd( fd );
iop = rtems_libio_iop( fd );
/* /*
* If this file descriptor is mapped to an external set of handlers, * If this file descriptor is mapped to an external set of handlers,
* then pass the request on to them. * then pass the request on to them.
*/ */
if ( rtems_file_descriptor_type( fd ) ) { if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) {
rtems_libio_lseek_t fp; rtems_libio_lseek_t fp;
fp = rtems_libio_handlers[rtems_file_descriptor_type_index(fd)].lseek; fp = rtems_libio_handlers[
(iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].lseek;
if ( fp == NULL ) if ( fp == NULL )
set_errno_and_return_minus_one( EBADF ); set_errno_and_return_minus_one( EBADF );
@@ -43,9 +47,6 @@ off_t lseek(
* Now process the lseek(). * Now process the lseek().
*/ */
iop = rtems_libio_iop( fd );
rtems_libio_check_fd( fd );
switch ( whence ) { switch ( whence ) {
case SEEK_SET: case SEEK_SET:
iop->offset = offset; iop->offset = offset;

View File

@@ -26,15 +26,22 @@ int read(
int rc; /* XXX change to a size_t when prototype is fixed */ int rc; /* XXX change to a size_t when prototype is fixed */
rtems_libio_t *iop; rtems_libio_t *iop;
rtems_libio_check_fd( fd );
iop = rtems_libio_iop( fd );
rtems_libio_check_buffer( buffer );
rtems_libio_check_count( count );
rtems_libio_check_permissions( iop, LIBIO_FLAGS_READ );
/* /*
* If this file descriptor is mapped to an external set of handlers, * If this file descriptor is mapped to an external set of handlers,
* then pass the request on to them. * then pass the request on to them.
*/ */
if ( rtems_file_descriptor_type( fd ) ) { if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) {
rtems_libio_read_t fp; rtems_libio_read_t fp;
fp = rtems_libio_handlers[rtems_file_descriptor_type_index(fd)].read; fp = rtems_libio_handlers[
(iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].read;
if ( fp == NULL ) if ( fp == NULL )
set_errno_and_return_minus_one( EBADF ); set_errno_and_return_minus_one( EBADF );
@@ -45,12 +52,6 @@ int read(
* Now process the read(). * Now process the read().
*/ */
iop = rtems_libio_iop( fd );
rtems_libio_check_fd( fd );
rtems_libio_check_buffer( buffer );
rtems_libio_check_count( count );
rtems_libio_check_permissions( iop, LIBIO_FLAGS_READ );
if ( !iop->handlers->read ) if ( !iop->handlers->read )
set_errno_and_return_minus_one( ENOTSUP ); set_errno_and_return_minus_one( ENOTSUP );

View File

@@ -34,15 +34,22 @@ int write( /* XXX this should return a ssize_t */
rtems_status_code rc; rtems_status_code rc;
rtems_libio_t *iop; rtems_libio_t *iop;
rtems_libio_check_fd( fd );
iop = rtems_libio_iop( fd );
rtems_libio_check_buffer( buffer );
rtems_libio_check_count( count );
rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE );
/* /*
* If this file descriptor is mapped to an external set of handlers, * If this file descriptor is mapped to an external set of handlers,
* then pass the request on to them. * then pass the request on to them.
*/ */
if ( rtems_file_descriptor_type( fd ) ) { if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) {
rtems_libio_write_t fp; rtems_libio_write_t fp;
fp = rtems_libio_handlers[rtems_file_descriptor_type_index(fd)].write; fp = rtems_libio_handlers[
(iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].write;
if ( fp == NULL ) if ( fp == NULL )
set_errno_and_return_minus_one( EBADF ); set_errno_and_return_minus_one( EBADF );
@@ -53,12 +60,6 @@ int write( /* XXX this should return a ssize_t */
* Now process the write() request. * Now process the write() request.
*/ */
iop = rtems_libio_iop( fd );
rtems_libio_check_fd( fd );
rtems_libio_check_buffer( buffer );
rtems_libio_check_count( count );
rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE );
if ( !iop->handlers->write ) if ( !iop->handlers->write )
set_errno_and_return_minus_one( ENOTSUP ); set_errno_and_return_minus_one( ENOTSUP );

View File

@@ -16,7 +16,7 @@ C_PIECES=sghostname issetugid \
rtems_glue rtems_syscall rtems_bootp \ rtems_glue rtems_syscall rtems_bootp \
rtems_showmbuf rtems_showroute \ rtems_showmbuf rtems_showroute \
rtems_showifstat rtems_showipstat rtems_showicmpstat \ rtems_showifstat rtems_showipstat rtems_showicmpstat \
rtems_showtcpstat rtems_showudpstat rtems_showtcpstat rtems_showudpstat rtems_select
C_FILES=$(C_PIECES:%=%.c) C_FILES=$(C_PIECES:%=%.c)
C_O_FILES=$(C_PIECES:%=${ARCH}/%.o) C_O_FILES=$(C_PIECES:%=${ARCH}/%.o)

View File

@@ -30,19 +30,6 @@
#include <net/netisr.h> #include <net/netisr.h>
#include <net/route.h> #include <net/route.h>
/*
* Events used by networking routines.
* Everything will break if the application
* tries to use these events or if the `sleep'
* events are equal to any of the NETISR * events.
*/
#define SBWAIT_EVENT RTEMS_EVENT_24
#define SOSLEEP_EVENT RTEMS_EVENT_25
#define NETISR_IP_EVENT (1 << NETISR_IP)
#define NETISR_ARP_EVENT (1 << NETISR_ARP)
#define NETISR_EVENTS (NETISR_IP_EVENT|NETISR_ARP_EVENT)
/* /*
* Memory allocation * Memory allocation
*/ */
@@ -246,7 +233,7 @@ rtems_bsdnet_initialize (void)
/* /*
* Register as an external I/O handler * Register as an external I/O handler
*/ */
rtems_register_libio_handler (RTEMS_FILE_DESCRIPTOR_TYPE_SOCKET, rtems_register_libio_handler (LIBIO_FLAGS_HANDLER_SOCK,
&rtems_bsdnet_io_handler); &rtems_bsdnet_io_handler);
/* /*
@@ -305,16 +292,9 @@ sbwait(sb)
/* /*
* Set this task as the target of the wakeup operation. * Set this task as the target of the wakeup operation.
*/ */
if (sb->sb_sel.si_pid)
rtems_panic ("Another task is already sleeping on that socket buffer");
rtems_task_ident (RTEMS_SELF, 0, &tid); rtems_task_ident (RTEMS_SELF, 0, &tid);
sb->sb_sel.si_pid = tid; sb->sb_sel.si_pid = tid;
/*
* Mark the socket buffer as waiting.
*/
sb->sb_flags |= SB_WAIT;
/* /*
* Release the network semaphore. * Release the network semaphore.
*/ */
@@ -330,12 +310,6 @@ sbwait(sb)
*/ */
rtems_bsdnet_semaphore_obtain (); rtems_bsdnet_semaphore_obtain ();
/*
* Relinquish ownership of the socket buffer
*/
sb->sb_flags &= ~SB_WAIT;
sb->sb_sel.si_pid = 0;
/* /*
* Return the status of the wait. * Return the status of the wait.
*/ */
@@ -355,9 +329,11 @@ sowakeup(so, sb)
register struct socket *so; register struct socket *so;
register struct sockbuf *sb; register struct sockbuf *sb;
{ {
if (sb->sb_flags & SB_WAIT) { rtems_id tid;
sb->sb_flags &= ~SB_WAIT;
rtems_event_send (sb->sb_sel.si_pid, SBWAIT_EVENT); if ((tid = sb->sb_sel.si_pid) != 0) {
sb->sb_sel.si_pid = 0;
rtems_event_send (tid, SBWAIT_EVENT);
} }
} }

View File

@@ -25,77 +25,6 @@
#include <net/if.h> #include <net/if.h>
#include <net/route.h> #include <net/route.h>
/*
*********************************************************************
* Map RTEMS file descriptor to BSD socket *
*********************************************************************
*/
struct fdsock {
int indexFreeNext;
struct socket *sock;
};
static struct fdsock *fdsock;
static int fdsockCount;
static int indexFreeHead = -1;
/*
* Convert an RTEMS file descriptor to a BSD socket pointer.
*/
static struct socket *
fdToSocket (int fd)
{
int i;
struct socket *s;
if ((fd < 0)
|| (rtems_file_descriptor_type(fd) != RTEMS_FILE_DESCRIPTOR_TYPE_SOCKET)
|| ((i = rtems_file_descriptor_base(fd)) >= fdsockCount)
|| ((s = fdsock[i].sock) == NULL)) {
errno = EBADF;
return NULL;
}
return s;
}
/*
* Enlarge the size of the file-descritor/socket pointer map.
*/
static int
enlargeFdMap (void)
{
struct fdsock *nfdsock;
int i;
nfdsock = realloc (fdsock, sizeof *fdsock * (fdsockCount + 20));
if (nfdsock == NULL) {
errno = ENFILE;
return 0;
}
fdsock = nfdsock;
for (i = fdsockCount, fdsockCount += 20 ; i < fdsockCount ; i++) {
fdsock[i].sock = NULL;
fdsock[i].indexFreeNext = indexFreeHead;
indexFreeHead = i;
}
return 1;
}
/*
* Create a file descriptor for a new socket
*/
static int
makeFd (struct socket *s)
{
int i;
if ((indexFreeHead < 0) && !enlargeFdMap ())
return -1;
i = indexFreeHead;
indexFreeHead = fdsock[i].indexFreeNext;
fdsock[i].sock = s;
return rtems_make_file_descriptor(i,RTEMS_FILE_DESCRIPTOR_TYPE_SOCKET);
}
/* /*
* Package system call argument into mbuf. * Package system call argument into mbuf.
*/ */
@@ -128,14 +57,14 @@ sockargstombuf (struct mbuf **mp, const void *buf, int buflen, int type)
int int
socket (int domain, int type, int protocol) socket (int domain, int type, int protocol)
{ {
int fd = -1; int fd;
int error; int error;
struct socket *so; struct socket *so;
rtems_bsdnet_semaphore_obtain (); rtems_bsdnet_semaphore_obtain ();
error = socreate(domain, &so, type, protocol, NULL); error = socreate(domain, &so, type, protocol, NULL);
if (error == 0) { if (error == 0) {
fd = makeFd (so); fd = rtems_bsdnet_makeFdForSocket (so);
if (fd < 0) if (fd < 0)
soclose (so); soclose (so);
} }
@@ -156,7 +85,7 @@ bind (int s, struct sockaddr *name, int namelen)
struct mbuf *nam; struct mbuf *nam;
rtems_bsdnet_semaphore_obtain (); rtems_bsdnet_semaphore_obtain ();
if ((so = fdToSocket (s)) != NULL) { if ((so = rtems_bsdnet_fdToSocket (s)) != NULL) {
error = sockargstombuf (&nam, name, namelen, MT_SONAME); error = sockargstombuf (&nam, name, namelen, MT_SONAME);
if (error == 0) { if (error == 0) {
error = sobind (so, nam); error = sobind (so, nam);
@@ -183,7 +112,7 @@ connect (int s, struct sockaddr *name, int namelen)
struct mbuf *nam; struct mbuf *nam;
rtems_bsdnet_semaphore_obtain (); rtems_bsdnet_semaphore_obtain ();
if ((so = fdToSocket (s)) == NULL) { if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) {
rtems_bsdnet_semaphore_release (); rtems_bsdnet_semaphore_release ();
return -1; return -1;
} }
@@ -233,7 +162,7 @@ listen (int s, int backlog)
struct socket *so; struct socket *so;
rtems_bsdnet_semaphore_obtain (); rtems_bsdnet_semaphore_obtain ();
if ((so = fdToSocket (s)) != NULL) { if ((so = rtems_bsdnet_fdToSocket (s)) != NULL) {
error = solisten (so, backlog); error = solisten (so, backlog);
if (error == 0) if (error == 0)
ret = 0; ret = 0;
@@ -252,7 +181,7 @@ accept (int s, struct sockaddr *name, int *namelen)
struct mbuf *nam; struct mbuf *nam;
rtems_bsdnet_semaphore_obtain (); rtems_bsdnet_semaphore_obtain ();
if ((head = fdToSocket (s)) == NULL) { if ((head = rtems_bsdnet_fdToSocket (s)) == NULL) {
rtems_bsdnet_semaphore_release (); rtems_bsdnet_semaphore_release ();
return -1; return -1;
} }
@@ -284,7 +213,7 @@ accept (int s, struct sockaddr *name, int *namelen)
TAILQ_REMOVE(&head->so_comp, so, so_list); TAILQ_REMOVE(&head->so_comp, so, so_list);
head->so_qlen--; head->so_qlen--;
fd = makeFd (so); fd = rtems_bsdnet_makeFdForSocket (so);
if (fd < 0) { if (fd < 0) {
TAILQ_INSERT_HEAD(&head->so_comp, so, so_list); TAILQ_INSERT_HEAD(&head->so_comp, so, so_list);
head->so_qlen++; head->so_qlen++;
@@ -325,7 +254,7 @@ sendmsg (int s, const struct msghdr *mp, int flags)
int len; int len;
rtems_bsdnet_semaphore_obtain (); rtems_bsdnet_semaphore_obtain ();
if ((so = fdToSocket (s)) == NULL) { if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) {
rtems_bsdnet_semaphore_release (); rtems_bsdnet_semaphore_release ();
return -1; return -1;
} }
@@ -428,7 +357,7 @@ recvmsg (int s, struct msghdr *mp, int flags)
int len; int len;
rtems_bsdnet_semaphore_obtain (); rtems_bsdnet_semaphore_obtain ();
if ((so = fdToSocket (s)) == NULL) { if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) {
rtems_bsdnet_semaphore_release (); rtems_bsdnet_semaphore_release ();
return -1; return -1;
} }
@@ -547,7 +476,7 @@ setsockopt (int s, int level, int name, const void *val, int len)
int error; int error;
rtems_bsdnet_semaphore_obtain (); rtems_bsdnet_semaphore_obtain ();
if ((so = fdToSocket (s)) == NULL) { if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) {
rtems_bsdnet_semaphore_release (); rtems_bsdnet_semaphore_release ();
return -1; return -1;
} }
@@ -584,7 +513,7 @@ getsockopt (int s, int level, int name, void *aval, int *avalsize)
int error; int error;
rtems_bsdnet_semaphore_obtain (); rtems_bsdnet_semaphore_obtain ();
if ((so = fdToSocket (s)) == NULL) { if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) {
rtems_bsdnet_semaphore_release (); rtems_bsdnet_semaphore_release ();
return -1; return -1;
} }
@@ -626,7 +555,7 @@ getpeersockname (int s, struct sockaddr *name, int *namelen, int pflag)
int error; int error;
rtems_bsdnet_semaphore_obtain (); rtems_bsdnet_semaphore_obtain ();
if ((so = fdToSocket (s)) == NULL) { if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) {
rtems_bsdnet_semaphore_release (); rtems_bsdnet_semaphore_release ();
return -1; return -1;
} }
@@ -676,16 +605,12 @@ rtems_bsdnet_close (int fd)
{ {
struct socket *so; struct socket *so;
int error; int error;
int i;
rtems_bsdnet_semaphore_obtain (); rtems_bsdnet_semaphore_obtain ();
if ((so = fdToSocket (fd)) == NULL) { if ((so = rtems_bsdnet_fdToSocket (fd)) == NULL) {
rtems_bsdnet_semaphore_release (); rtems_bsdnet_semaphore_release ();
return -1; return -1;
} }
i = rtems_file_descriptor_base(fd);
fdsock[i].indexFreeNext = indexFreeHead;;
indexFreeHead = i;
error = soclose (so); error = soclose (so);
rtems_bsdnet_semaphore_release (); rtems_bsdnet_semaphore_release ();
if (error) { if (error) {
@@ -737,7 +662,7 @@ rtems_bsdnet_ioctl (int fd, unsigned32 command, void *buffer)
int error; int error;
rtems_bsdnet_semaphore_obtain (); rtems_bsdnet_semaphore_obtain ();
if ((so = fdToSocket (fd)) == NULL) { if ((so = rtems_bsdnet_fdToSocket (fd)) == NULL) {
rtems_bsdnet_semaphore_release (); rtems_bsdnet_semaphore_release ();
return -1; return -1;
} }

View File

@@ -83,11 +83,10 @@
#define SIOCSIFMEDIA _IOWR('i', 55, struct ifreq) /* set net media */ #define SIOCSIFMEDIA _IOWR('i', 55, struct ifreq) /* set net media */
#define SIOCGIFMEDIA _IOWR('i', 56, struct ifmediareq) /* get net media */ #define SIOCGIFMEDIA _IOWR('i', 56, struct ifmediareq) /* get net media */
/* /*
* RTEMS additions for setting/getting `tap' function on incoming packets. * RTEMS additions for setting/getting `tap' function on incoming packets.
*/ */
#define SIOCSIFTAP _IOW('i', 80, struct ifreq) /* set tap function */ #define SIOCSIFTAP _IOW('i', 80, struct ifreq) /* set tap function */
#define SIOCGIFTAP _IOWR('i', 81, struct ifreq) /* get tap function */ #define SIOCGIFTAP _IOW('i', 81, struct ifreq) /* get tap function */
#endif /* !_SYS_SOCKIO_H_ */ #endif /* !_SYS_SOCKIO_H_ */

View File

@@ -16,7 +16,7 @@ C_PIECES=sghostname issetugid \
rtems_glue rtems_syscall rtems_bootp \ rtems_glue rtems_syscall rtems_bootp \
rtems_showmbuf rtems_showroute \ rtems_showmbuf rtems_showroute \
rtems_showifstat rtems_showipstat rtems_showicmpstat \ rtems_showifstat rtems_showipstat rtems_showicmpstat \
rtems_showtcpstat rtems_showudpstat rtems_showtcpstat rtems_showudpstat rtems_select
C_FILES=$(C_PIECES:%=%.c) C_FILES=$(C_PIECES:%=%.c)
C_O_FILES=$(C_PIECES:%=${ARCH}/%.o) C_O_FILES=$(C_PIECES:%=${ARCH}/%.o)

View File

@@ -30,19 +30,6 @@
#include <net/netisr.h> #include <net/netisr.h>
#include <net/route.h> #include <net/route.h>
/*
* Events used by networking routines.
* Everything will break if the application
* tries to use these events or if the `sleep'
* events are equal to any of the NETISR * events.
*/
#define SBWAIT_EVENT RTEMS_EVENT_24
#define SOSLEEP_EVENT RTEMS_EVENT_25
#define NETISR_IP_EVENT (1 << NETISR_IP)
#define NETISR_ARP_EVENT (1 << NETISR_ARP)
#define NETISR_EVENTS (NETISR_IP_EVENT|NETISR_ARP_EVENT)
/* /*
* Memory allocation * Memory allocation
*/ */
@@ -246,7 +233,7 @@ rtems_bsdnet_initialize (void)
/* /*
* Register as an external I/O handler * Register as an external I/O handler
*/ */
rtems_register_libio_handler (RTEMS_FILE_DESCRIPTOR_TYPE_SOCKET, rtems_register_libio_handler (LIBIO_FLAGS_HANDLER_SOCK,
&rtems_bsdnet_io_handler); &rtems_bsdnet_io_handler);
/* /*
@@ -305,16 +292,9 @@ sbwait(sb)
/* /*
* Set this task as the target of the wakeup operation. * Set this task as the target of the wakeup operation.
*/ */
if (sb->sb_sel.si_pid)
rtems_panic ("Another task is already sleeping on that socket buffer");
rtems_task_ident (RTEMS_SELF, 0, &tid); rtems_task_ident (RTEMS_SELF, 0, &tid);
sb->sb_sel.si_pid = tid; sb->sb_sel.si_pid = tid;
/*
* Mark the socket buffer as waiting.
*/
sb->sb_flags |= SB_WAIT;
/* /*
* Release the network semaphore. * Release the network semaphore.
*/ */
@@ -330,12 +310,6 @@ sbwait(sb)
*/ */
rtems_bsdnet_semaphore_obtain (); rtems_bsdnet_semaphore_obtain ();
/*
* Relinquish ownership of the socket buffer
*/
sb->sb_flags &= ~SB_WAIT;
sb->sb_sel.si_pid = 0;
/* /*
* Return the status of the wait. * Return the status of the wait.
*/ */
@@ -355,9 +329,11 @@ sowakeup(so, sb)
register struct socket *so; register struct socket *so;
register struct sockbuf *sb; register struct sockbuf *sb;
{ {
if (sb->sb_flags & SB_WAIT) { rtems_id tid;
sb->sb_flags &= ~SB_WAIT;
rtems_event_send (sb->sb_sel.si_pid, SBWAIT_EVENT); if ((tid = sb->sb_sel.si_pid) != 0) {
sb->sb_sel.si_pid = 0;
rtems_event_send (tid, SBWAIT_EVENT);
} }
} }

View File

@@ -25,77 +25,6 @@
#include <net/if.h> #include <net/if.h>
#include <net/route.h> #include <net/route.h>
/*
*********************************************************************
* Map RTEMS file descriptor to BSD socket *
*********************************************************************
*/
struct fdsock {
int indexFreeNext;
struct socket *sock;
};
static struct fdsock *fdsock;
static int fdsockCount;
static int indexFreeHead = -1;
/*
* Convert an RTEMS file descriptor to a BSD socket pointer.
*/
static struct socket *
fdToSocket (int fd)
{
int i;
struct socket *s;
if ((fd < 0)
|| (rtems_file_descriptor_type(fd) != RTEMS_FILE_DESCRIPTOR_TYPE_SOCKET)
|| ((i = rtems_file_descriptor_base(fd)) >= fdsockCount)
|| ((s = fdsock[i].sock) == NULL)) {
errno = EBADF;
return NULL;
}
return s;
}
/*
* Enlarge the size of the file-descritor/socket pointer map.
*/
static int
enlargeFdMap (void)
{
struct fdsock *nfdsock;
int i;
nfdsock = realloc (fdsock, sizeof *fdsock * (fdsockCount + 20));
if (nfdsock == NULL) {
errno = ENFILE;
return 0;
}
fdsock = nfdsock;
for (i = fdsockCount, fdsockCount += 20 ; i < fdsockCount ; i++) {
fdsock[i].sock = NULL;
fdsock[i].indexFreeNext = indexFreeHead;
indexFreeHead = i;
}
return 1;
}
/*
* Create a file descriptor for a new socket
*/
static int
makeFd (struct socket *s)
{
int i;
if ((indexFreeHead < 0) && !enlargeFdMap ())
return -1;
i = indexFreeHead;
indexFreeHead = fdsock[i].indexFreeNext;
fdsock[i].sock = s;
return rtems_make_file_descriptor(i,RTEMS_FILE_DESCRIPTOR_TYPE_SOCKET);
}
/* /*
* Package system call argument into mbuf. * Package system call argument into mbuf.
*/ */
@@ -128,14 +57,14 @@ sockargstombuf (struct mbuf **mp, const void *buf, int buflen, int type)
int int
socket (int domain, int type, int protocol) socket (int domain, int type, int protocol)
{ {
int fd = -1; int fd;
int error; int error;
struct socket *so; struct socket *so;
rtems_bsdnet_semaphore_obtain (); rtems_bsdnet_semaphore_obtain ();
error = socreate(domain, &so, type, protocol, NULL); error = socreate(domain, &so, type, protocol, NULL);
if (error == 0) { if (error == 0) {
fd = makeFd (so); fd = rtems_bsdnet_makeFdForSocket (so);
if (fd < 0) if (fd < 0)
soclose (so); soclose (so);
} }
@@ -156,7 +85,7 @@ bind (int s, struct sockaddr *name, int namelen)
struct mbuf *nam; struct mbuf *nam;
rtems_bsdnet_semaphore_obtain (); rtems_bsdnet_semaphore_obtain ();
if ((so = fdToSocket (s)) != NULL) { if ((so = rtems_bsdnet_fdToSocket (s)) != NULL) {
error = sockargstombuf (&nam, name, namelen, MT_SONAME); error = sockargstombuf (&nam, name, namelen, MT_SONAME);
if (error == 0) { if (error == 0) {
error = sobind (so, nam); error = sobind (so, nam);
@@ -183,7 +112,7 @@ connect (int s, struct sockaddr *name, int namelen)
struct mbuf *nam; struct mbuf *nam;
rtems_bsdnet_semaphore_obtain (); rtems_bsdnet_semaphore_obtain ();
if ((so = fdToSocket (s)) == NULL) { if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) {
rtems_bsdnet_semaphore_release (); rtems_bsdnet_semaphore_release ();
return -1; return -1;
} }
@@ -233,7 +162,7 @@ listen (int s, int backlog)
struct socket *so; struct socket *so;
rtems_bsdnet_semaphore_obtain (); rtems_bsdnet_semaphore_obtain ();
if ((so = fdToSocket (s)) != NULL) { if ((so = rtems_bsdnet_fdToSocket (s)) != NULL) {
error = solisten (so, backlog); error = solisten (so, backlog);
if (error == 0) if (error == 0)
ret = 0; ret = 0;
@@ -252,7 +181,7 @@ accept (int s, struct sockaddr *name, int *namelen)
struct mbuf *nam; struct mbuf *nam;
rtems_bsdnet_semaphore_obtain (); rtems_bsdnet_semaphore_obtain ();
if ((head = fdToSocket (s)) == NULL) { if ((head = rtems_bsdnet_fdToSocket (s)) == NULL) {
rtems_bsdnet_semaphore_release (); rtems_bsdnet_semaphore_release ();
return -1; return -1;
} }
@@ -284,7 +213,7 @@ accept (int s, struct sockaddr *name, int *namelen)
TAILQ_REMOVE(&head->so_comp, so, so_list); TAILQ_REMOVE(&head->so_comp, so, so_list);
head->so_qlen--; head->so_qlen--;
fd = makeFd (so); fd = rtems_bsdnet_makeFdForSocket (so);
if (fd < 0) { if (fd < 0) {
TAILQ_INSERT_HEAD(&head->so_comp, so, so_list); TAILQ_INSERT_HEAD(&head->so_comp, so, so_list);
head->so_qlen++; head->so_qlen++;
@@ -325,7 +254,7 @@ sendmsg (int s, const struct msghdr *mp, int flags)
int len; int len;
rtems_bsdnet_semaphore_obtain (); rtems_bsdnet_semaphore_obtain ();
if ((so = fdToSocket (s)) == NULL) { if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) {
rtems_bsdnet_semaphore_release (); rtems_bsdnet_semaphore_release ();
return -1; return -1;
} }
@@ -428,7 +357,7 @@ recvmsg (int s, struct msghdr *mp, int flags)
int len; int len;
rtems_bsdnet_semaphore_obtain (); rtems_bsdnet_semaphore_obtain ();
if ((so = fdToSocket (s)) == NULL) { if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) {
rtems_bsdnet_semaphore_release (); rtems_bsdnet_semaphore_release ();
return -1; return -1;
} }
@@ -547,7 +476,7 @@ setsockopt (int s, int level, int name, const void *val, int len)
int error; int error;
rtems_bsdnet_semaphore_obtain (); rtems_bsdnet_semaphore_obtain ();
if ((so = fdToSocket (s)) == NULL) { if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) {
rtems_bsdnet_semaphore_release (); rtems_bsdnet_semaphore_release ();
return -1; return -1;
} }
@@ -584,7 +513,7 @@ getsockopt (int s, int level, int name, void *aval, int *avalsize)
int error; int error;
rtems_bsdnet_semaphore_obtain (); rtems_bsdnet_semaphore_obtain ();
if ((so = fdToSocket (s)) == NULL) { if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) {
rtems_bsdnet_semaphore_release (); rtems_bsdnet_semaphore_release ();
return -1; return -1;
} }
@@ -626,7 +555,7 @@ getpeersockname (int s, struct sockaddr *name, int *namelen, int pflag)
int error; int error;
rtems_bsdnet_semaphore_obtain (); rtems_bsdnet_semaphore_obtain ();
if ((so = fdToSocket (s)) == NULL) { if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) {
rtems_bsdnet_semaphore_release (); rtems_bsdnet_semaphore_release ();
return -1; return -1;
} }
@@ -676,16 +605,12 @@ rtems_bsdnet_close (int fd)
{ {
struct socket *so; struct socket *so;
int error; int error;
int i;
rtems_bsdnet_semaphore_obtain (); rtems_bsdnet_semaphore_obtain ();
if ((so = fdToSocket (fd)) == NULL) { if ((so = rtems_bsdnet_fdToSocket (fd)) == NULL) {
rtems_bsdnet_semaphore_release (); rtems_bsdnet_semaphore_release ();
return -1; return -1;
} }
i = rtems_file_descriptor_base(fd);
fdsock[i].indexFreeNext = indexFreeHead;;
indexFreeHead = i;
error = soclose (so); error = soclose (so);
rtems_bsdnet_semaphore_release (); rtems_bsdnet_semaphore_release ();
if (error) { if (error) {
@@ -737,7 +662,7 @@ rtems_bsdnet_ioctl (int fd, unsigned32 command, void *buffer)
int error; int error;
rtems_bsdnet_semaphore_obtain (); rtems_bsdnet_semaphore_obtain ();
if ((so = fdToSocket (fd)) == NULL) { if ((so = rtems_bsdnet_fdToSocket (fd)) == NULL) {
rtems_bsdnet_semaphore_release (); rtems_bsdnet_semaphore_release ();
return -1; return -1;
} }

View File

@@ -83,11 +83,10 @@
#define SIOCSIFMEDIA _IOWR('i', 55, struct ifreq) /* set net media */ #define SIOCSIFMEDIA _IOWR('i', 55, struct ifreq) /* set net media */
#define SIOCGIFMEDIA _IOWR('i', 56, struct ifmediareq) /* get net media */ #define SIOCGIFMEDIA _IOWR('i', 56, struct ifmediareq) /* get net media */
/* /*
* RTEMS additions for setting/getting `tap' function on incoming packets. * RTEMS additions for setting/getting `tap' function on incoming packets.
*/ */
#define SIOCSIFTAP _IOW('i', 80, struct ifreq) /* set tap function */ #define SIOCSIFTAP _IOW('i', 80, struct ifreq) /* set tap function */
#define SIOCGIFTAP _IOWR('i', 81, struct ifreq) /* get tap function */ #define SIOCGIFTAP _IOW('i', 81, struct ifreq) /* get tap function */
#endif /* !_SYS_SOCKIO_H_ */ #endif /* !_SYS_SOCKIO_H_ */

2
configure vendored
View File

@@ -806,7 +806,7 @@ case "${enableval}" in
*) { echo "configure: error: bad value ${enableval} for enable-rdbg option" 1>&2; exit 1; } ;; *) { echo "configure: error: bad value ${enableval} for enable-rdbg option" 1>&2; exit 1; } ;;
esac esac
else else
RTEMS_HAS_RDBG=yes RTEMS_HAS_RDBG=no
fi fi

View File

@@ -49,7 +49,7 @@ AC_ARG_ENABLE(rdbg, \
yes) RTEMS_HAS_RDBG=yes ;; yes) RTEMS_HAS_RDBG=yes ;;
no) RTEMS_HAS_RDBG=no ;; no) RTEMS_HAS_RDBG=no ;;
*) AC_MSG_ERROR(bad value ${enableval} for enable-rdbg option) ;; *) AC_MSG_ERROR(bad value ${enableval} for enable-rdbg option) ;;
esac],[RTEMS_HAS_RDBG=yes]) esac],[RTEMS_HAS_RDBG=no])
AC_ARG_ENABLE(rtems-inlines, \ AC_ARG_ENABLE(rtems-inlines, \
[ --enable-rtems-inlines enable RTEMS inline functions (use macros)], \ [ --enable-rtems-inlines enable RTEMS inline functions (use macros)], \

View File

@@ -65,6 +65,7 @@ extern rtems_id rtems_libio_semaphore;
extern unsigned32 rtems_libio_number_iops; extern unsigned32 rtems_libio_number_iops;
extern rtems_libio_t *rtems_libio_iops; extern rtems_libio_t *rtems_libio_iops;
extern rtems_libio_t *rtems_libio_last_iop; extern rtems_libio_t *rtems_libio_last_iop;
extern rtems_libio_t *rtems_libio_iop_freelist;
/* /*
* External I/O Handlers Table * External I/O Handlers Table

View File

@@ -393,12 +393,16 @@ typedef struct {
#define LIBIO_FLAGS_NO_DELAY 0x0001 /* return immediately if no data */ #define LIBIO_FLAGS_NO_DELAY 0x0001 /* return immediately if no data */
#define LIBIO_FLAGS_READ 0x0002 /* reading */ #define LIBIO_FLAGS_READ 0x0002 /* reading */
#define LIBIO_FLAGS_WRITE 0x0004 /* writing */ #define LIBIO_FLAGS_WRITE 0x0004 /* writing */
#define LIBIO_FLAGS_LINE_BUFFERED 0x0008 /* line buffered io (^h, ^u, etc) */
#define LIBIO_FLAGS_OPEN 0x0100 /* device is open */ #define LIBIO_FLAGS_OPEN 0x0100 /* device is open */
#define LIBIO_FLAGS_APPEND 0x0200 /* all writes append */ #define LIBIO_FLAGS_APPEND 0x0200 /* all writes append */
#define LIBIO_FLAGS_CREATE 0x0400 /* create file */ #define LIBIO_FLAGS_CREATE 0x0400 /* create file */
#define LIBIO_FLAGS_CLOSE_ON_EXEC 0x0800 /* close on process exec() */ #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) #define LIBIO_FLAGS_READ_WRITE (LIBIO_FLAGS_READ | LIBIO_FLAGS_WRITE)

View File

@@ -65,6 +65,7 @@ extern rtems_id rtems_libio_semaphore;
extern unsigned32 rtems_libio_number_iops; extern unsigned32 rtems_libio_number_iops;
extern rtems_libio_t *rtems_libio_iops; extern rtems_libio_t *rtems_libio_iops;
extern rtems_libio_t *rtems_libio_last_iop; extern rtems_libio_t *rtems_libio_last_iop;
extern rtems_libio_t *rtems_libio_iop_freelist;
/* /*
* External I/O Handlers Table * External I/O Handlers Table

View File

@@ -83,11 +83,10 @@
#define SIOCSIFMEDIA _IOWR('i', 55, struct ifreq) /* set net media */ #define SIOCSIFMEDIA _IOWR('i', 55, struct ifreq) /* set net media */
#define SIOCGIFMEDIA _IOWR('i', 56, struct ifmediareq) /* get net media */ #define SIOCGIFMEDIA _IOWR('i', 56, struct ifmediareq) /* get net media */
/* /*
* RTEMS additions for setting/getting `tap' function on incoming packets. * RTEMS additions for setting/getting `tap' function on incoming packets.
*/ */
#define SIOCSIFTAP _IOW('i', 80, struct ifreq) /* set tap function */ #define SIOCSIFTAP _IOW('i', 80, struct ifreq) /* set tap function */
#define SIOCGIFTAP _IOWR('i', 81, struct ifreq) /* get tap function */ #define SIOCGIFTAP _IOW('i', 81, struct ifreq) /* get tap function */
#endif /* !_SYS_SOCKIO_H_ */ #endif /* !_SYS_SOCKIO_H_ */

View File

@@ -22,17 +22,18 @@ int close(
rtems_status_code rc; rtems_status_code rc;
int status; int status;
if ( rtems_file_descriptor_type( fd ) ) { rtems_libio_check_fd(fd);
iop = rtems_libio_iop(fd);
if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) {
int (*fp)(int fd); int (*fp)(int fd);
fp = rtems_libio_handlers[rtems_file_descriptor_type_index(fd)].close; fp = rtems_libio_handlers[
(iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].close;
if ( fp == NULL ) if ( fp == NULL )
set_errno_and_return_minus_one( EBADF ); set_errno_and_return_minus_one( EBADF );
status = (*fp)( fd ); status = (*fp)( fd );
return status; return status;
} }
iop = rtems_libio_iop(fd);
rtems_libio_check_fd(fd);
if ( !iop->handlers ) if ( !iop->handlers )
set_errno_and_return_minus_one( EBADF ); set_errno_and_return_minus_one( EBADF );

View File

@@ -27,19 +27,20 @@ int fchmod(
{ {
rtems_libio_t *iop; rtems_libio_t *iop;
rtems_libio_check_fd( fd );
iop = rtems_libio_iop( fd );
/* /*
* If this is not a file system based entity, it is an error. * If this is not a file system based entity, it is an error.
*/ */
if ( rtems_file_descriptor_type( fd ) ) if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK )
set_errno_and_return_minus_one( EBADF ); set_errno_and_return_minus_one( EBADF );
/* /*
* Now process the fchmod(). * Now process the fchmod().
*/ */
iop = rtems_libio_iop( fd );
rtems_libio_check_fd( fd );
rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE ); rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE );
if ( !iop->handlers->fchmod ) if ( !iop->handlers->fchmod )

View File

@@ -32,20 +32,20 @@ int fcntl(
va_start( ap, cmd ); va_start( ap, cmd );
rtems_libio_check_fd( fd );
iop = rtems_libio_iop( fd );
/* /*
* If this is not a file system based entity, it is an error. * If this is not a file system based entity, it is an error.
*/ */
if ( rtems_file_descriptor_type( fd ) ) if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK )
set_errno_and_return_minus_one( EBADF ); set_errno_and_return_minus_one( EBADF );
/* /*
* Now process the fcntl(). * Now process the fcntl().
*/ */
iop = rtems_libio_iop( fd );
rtems_libio_check_fd( fd );
/* /*
* This switch should contain all the cases from POSIX. * This switch should contain all the cases from POSIX.
*/ */

View File

@@ -22,22 +22,22 @@ int fdatasync(
{ {
rtems_libio_t *iop; rtems_libio_t *iop;
rtems_libio_check_fd( fd );
iop = rtems_libio_iop( fd );
rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE );
/* /*
* If this file descriptor is mapped to an external set of handlers, * If this file descriptor is mapped to an external set of handlers,
* then pass the request on to them. * then pass the request on to them.
*/ */
if ( rtems_file_descriptor_type( fd ) ) if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK )
set_errno_and_return_minus_one( EBADF ); set_errno_and_return_minus_one( EBADF );
/* /*
* Now process the fdatasync(). * Now process the fdatasync().
*/ */
iop = rtems_libio_iop( fd );
rtems_libio_check_fd( fd );
rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE );
if ( !iop->handlers->fdatasync ) if ( !iop->handlers->fdatasync )
set_errno_and_return_minus_one( ENOTSUP ); set_errno_and_return_minus_one( ENOTSUP );

View File

@@ -26,23 +26,23 @@ long fpathconf(
rtems_libio_t *iop; rtems_libio_t *iop;
rtems_filesystem_limits_and_options_t *the_limits; rtems_filesystem_limits_and_options_t *the_limits;
rtems_libio_check_fd(fd);
iop = rtems_libio_iop(fd);
rtems_libio_check_permissions(iop, LIBIO_FLAGS_READ);
/* /*
* If this file descriptor is mapped to an external set of handlers, * If this file descriptor is mapped to an external set of handlers,
* then it is an error since fpathconf() is not included in the * then it is an error since fpathconf() is not included in the
* set. * set.
*/ */
if ( rtems_file_descriptor_type( fd ) ) if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK )
set_errno_and_return_minus_one( EBADF ); set_errno_and_return_minus_one( EBADF );
/* /*
* Now process the information request. * Now process the information request.
*/ */
iop = rtems_libio_iop(fd);
rtems_libio_check_fd(fd);
rtems_libio_check_permissions(iop, LIBIO_FLAGS_READ);
the_limits = &iop->pathinfo.mt_entry->pathconf_limits_and_options; the_limits = &iop->pathinfo.mt_entry->pathconf_limits_and_options;
switch ( name ) { switch ( name ) {

View File

@@ -22,22 +22,22 @@ int fsync(
{ {
rtems_libio_t *iop; rtems_libio_t *iop;
rtems_libio_check_fd( fd );
iop = rtems_libio_iop( fd );
rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE );
/* /*
* If this file descriptor is mapped to an external set of handlers, * If this file descriptor is mapped to an external set of handlers,
* then pass the request on to them. * then pass the request on to them.
*/ */
if ( rtems_file_descriptor_type( fd ) ) if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK )
set_errno_and_return_minus_one( EBADF ); set_errno_and_return_minus_one( EBADF );
/* /*
* Now process the fsync(). * Now process the fsync().
*/ */
iop = rtems_libio_iop( fd );
rtems_libio_check_fd( fd );
rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE );
if ( !iop->handlers->fsync ) if ( !iop->handlers->fsync )
set_errno_and_return_minus_one( ENOTSUP ); set_errno_and_return_minus_one( ENOTSUP );

View File

@@ -25,19 +25,20 @@ int ftruncate(
rtems_libio_t *iop; rtems_libio_t *iop;
rtems_filesystem_location_info_t loc; rtems_filesystem_location_info_t loc;
rtems_libio_check_fd( fd );
iop = rtems_libio_iop( fd );
/* /*
* If this is not a file system based entity, it is an error. * If this is not a file system based entity, it is an error.
*/ */
if ( rtems_file_descriptor_type( fd ) ) if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK )
set_errno_and_return_minus_one( EBADF ); set_errno_and_return_minus_one( EBADF );
/* /*
* Now process the ftruncate() request. * Now process the ftruncate() request.
*/ */
iop = rtems_libio_iop( fd );
/* /*
* Make sure we are not working on a directory * Make sure we are not working on a directory
*/ */
@@ -49,7 +50,6 @@ int ftruncate(
if ( (*loc.ops->node_type)( &loc ) == RTEMS_FILESYSTEM_DIRECTORY ) if ( (*loc.ops->node_type)( &loc ) == RTEMS_FILESYSTEM_DIRECTORY )
set_errno_and_return_minus_one( EISDIR ); set_errno_and_return_minus_one( EISDIR );
rtems_libio_check_fd( fd );
rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE ); rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE );
if ( !iop->handlers->ftruncate ) if ( !iop->handlers->ftruncate )

View File

@@ -26,15 +26,19 @@ int ioctl(
rtems_status_code rc; rtems_status_code rc;
rtems_libio_t *iop; rtems_libio_t *iop;
rtems_libio_check_fd( fd );
iop = rtems_libio_iop( fd );
/* /*
* If this file descriptor is mapped to an external set of handlers, * If this file descriptor is mapped to an external set of handlers,
* then pass the request on to them. * then pass the request on to them.
*/ */
if ( rtems_file_descriptor_type( fd ) ) { if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) {
rtems_libio_ioctl_t fp; rtems_libio_ioctl_t fp;
fp = rtems_libio_handlers[rtems_file_descriptor_type_index(fd)].ioctl; fp = rtems_libio_handlers[
(iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].ioctl;
if ( fp == NULL ) if ( fp == NULL )
set_errno_and_return_minus_one( EBADF ); set_errno_and_return_minus_one( EBADF );
@@ -45,9 +49,6 @@ int ioctl(
* Now process the ioctl(). * Now process the ioctl().
*/ */
iop = rtems_libio_iop( fd );
rtems_libio_check_fd( fd );
if ( !iop->handlers->ioctl ) if ( !iop->handlers->ioctl )
set_errno_and_return_minus_one( ENOTSUP ); set_errno_and_return_minus_one( ENOTSUP );

View File

@@ -3,9 +3,6 @@
* table of integer style file descriptors used by the low level * table of integer style file descriptors used by the low level
* POSIX system calls like open(), read, fstat(), etc. * POSIX system calls like open(), read, fstat(), etc.
* *
* This provides the foundation for POSIX compliant IO system calls
* for RTEMS.
*
* COPYRIGHT (c) 1989-1998. * COPYRIGHT (c) 1989-1998.
* On-Line Applications Research Corporation (OAR). * On-Line Applications Research Corporation (OAR).
* Copyright assigned to U.S. Government, 1994. * Copyright assigned to U.S. Government, 1994.
@@ -18,17 +15,55 @@
*/ */
#include "libio_.h" /* libio_.h pulls in rtems */ #include "libio_.h" /* libio_.h pulls in rtems */
#include <rtems.h>
#include <rtems/assoc.h> /* assoc.h not included by rtems.h */
#include <stdio.h> /* O_RDONLY, et.al. */
#include <fcntl.h> /* O_RDONLY, et.al. */
#include <assert.h>
#include <errno.h>
#if ! defined(O_NDELAY)
# if defined(solaris2)
# define O_NDELAY O_NONBLOCK
# elif defined(RTEMS_NEWLIB)
# define O_NDELAY _FNBIO
# endif
#endif
#include <errno.h>
#include <string.h> /* strcmp */
#include <unistd.h>
#include <stdlib.h> /* calloc() */
#include "libio.h" /* libio.h not pulled in by rtems */
/* /*
* Global variables used to manage the File Descriptor Table. * File descriptor Table Information
* IOP = IO Pointer.
*/ */
extern unsigned32 rtems_libio_number_iops;
rtems_id rtems_libio_semaphore; rtems_id rtems_libio_semaphore;
rtems_libio_t *rtems_libio_iops; rtems_libio_t *rtems_libio_iops;
rtems_libio_t *rtems_libio_last_iop; 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]; rtems_libio_handler_t rtems_libio_handlers[15];
/*
* Default mode for all files.
*/
mode_t rtems_filesystem_umask;
/* /*
* rtems_register_libio_handler * rtems_register_libio_handler
* *
@@ -44,8 +79,7 @@ void rtems_register_libio_handler(
const rtems_libio_handler_t *handler const rtems_libio_handler_t *handler
) )
{ {
int handler_index = rtems_file_descriptor_type_index( handler_flag ); int handler_index = (handler_flag >> LIBIO_FLAGS_HANDLER_SHIFT) - 1;
if ((handler_index < 0) || (handler_index >= 15)) if ((handler_index < 0) || (handler_index >= 15))
rtems_fatal_error_occurred( RTEMS_INVALID_NUMBER ); rtems_fatal_error_occurred( RTEMS_INVALID_NUMBER );
@@ -62,19 +96,20 @@ void rtems_register_libio_handler(
void rtems_libio_init( void ) void rtems_libio_init( void )
{ {
rtems_status_code rc; rtems_status_code rc;
int i;
rtems_libio_t *iop;
/* if (rtems_libio_number_iops > 0)
* Allocate memory for the IOP Table {
*/ rtems_libio_iops = (rtems_libio_t *) calloc(rtems_libio_number_iops,
sizeof(rtems_libio_t));
if ( rtems_libio_number_iops > 0 ) {
rtems_libio_iops =
(rtems_libio_t *) calloc(rtems_libio_number_iops, sizeof(rtems_libio_t));
if (rtems_libio_iops == NULL) if (rtems_libio_iops == NULL)
rtems_fatal_error_occurred( RTEMS_NO_MEMORY ); rtems_fatal_error_occurred(RTEMS_NO_MEMORY);
rtems_libio_last_iop = rtems_libio_iops + (rtems_libio_number_iops - 1); iop = rtems_libio_iop_freelist = rtems_libio_iops;
for (i = 0 ; i < (rtems_libio_number_iops - 1) ; i++, iop++)
iop->data1 = iop + 1;
iop->data1 = NULL;
} }
/* /*
@@ -157,12 +192,8 @@ rtems_libio_t *rtems_libio_allocate( void )
rtems_semaphore_obtain( rtems_libio_semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT ); rtems_semaphore_obtain( rtems_libio_semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT );
for (iop = rtems_libio_iops; iop <= rtems_libio_last_iop; iop++) if (rtems_libio_iop_freelist) {
if ((iop->flags & LIBIO_FLAGS_OPEN) == 0) { iop = rtems_libio_iop_freelist;
/*
* Got an IOP -- create a semaphore for it.
*/
rc = rtems_semaphore_create( rc = rtems_semaphore_create(
RTEMS_LIBIO_IOP_SEM(iop - rtems_libio_iops), RTEMS_LIBIO_IOP_SEM(iop - rtems_libio_iops),
1, 1,
@@ -170,9 +201,10 @@ rtems_libio_t *rtems_libio_allocate( void )
RTEMS_NO_PRIORITY, RTEMS_NO_PRIORITY,
&iop->sem &iop->sem
); );
if ( rc != RTEMS_SUCCESSFUL ) if (rc != RTEMS_SUCCESSFUL)
goto failed; goto failed;
rtems_libio_iop_freelist = iop->data1;
iop->data1 = 0;
iop->flags = LIBIO_FLAGS_OPEN; iop->flags = LIBIO_FLAGS_OPEN;
goto done; goto done;
} }
@@ -201,16 +233,17 @@ void rtems_libio_free(
if (iop->sem) if (iop->sem)
rtems_semaphore_delete(iop->sem); rtems_semaphore_delete(iop->sem);
(void) memset(iop, 0, sizeof(*iop)); iop->data1 = rtems_libio_iop_freelist;
rtems_libio_iop_freelist = iop;
rtems_semaphore_release( rtems_libio_semaphore ); rtems_semaphore_release(rtems_libio_semaphore);
} }
/* /*
* rtems_libio_is_open_files_in_fs * rtems_libio_is_open_files_in_fs
* *
* This routine scans the entire file descriptor table to determine if the * This routine scans the entire file descriptor table to determine if the
* are any active file descriptors that refer to the atleast one node in the * are any active file descriptors that refer to the at least one node in the
* file system that we are trying to dismount. * file system that we are trying to dismount.
* *
* If there is at least one node in the file system referenced by the mount * If there is at least one node in the file system referenced by the mount
@@ -293,3 +326,5 @@ int rtems_libio_is_file_open(
return result; return result;
} }

View File

@@ -24,15 +24,19 @@ off_t lseek(
{ {
rtems_libio_t *iop; rtems_libio_t *iop;
rtems_libio_check_fd( fd );
iop = rtems_libio_iop( fd );
/* /*
* If this file descriptor is mapped to an external set of handlers, * If this file descriptor is mapped to an external set of handlers,
* then pass the request on to them. * then pass the request on to them.
*/ */
if ( rtems_file_descriptor_type( fd ) ) { if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) {
rtems_libio_lseek_t fp; rtems_libio_lseek_t fp;
fp = rtems_libio_handlers[rtems_file_descriptor_type_index(fd)].lseek; fp = rtems_libio_handlers[
(iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].lseek;
if ( fp == NULL ) if ( fp == NULL )
set_errno_and_return_minus_one( EBADF ); set_errno_and_return_minus_one( EBADF );
@@ -43,9 +47,6 @@ off_t lseek(
* Now process the lseek(). * Now process the lseek().
*/ */
iop = rtems_libio_iop( fd );
rtems_libio_check_fd( fd );
switch ( whence ) { switch ( whence ) {
case SEEK_SET: case SEEK_SET:
iop->offset = offset; iop->offset = offset;

View File

@@ -26,15 +26,22 @@ int read(
int rc; /* XXX change to a size_t when prototype is fixed */ int rc; /* XXX change to a size_t when prototype is fixed */
rtems_libio_t *iop; rtems_libio_t *iop;
rtems_libio_check_fd( fd );
iop = rtems_libio_iop( fd );
rtems_libio_check_buffer( buffer );
rtems_libio_check_count( count );
rtems_libio_check_permissions( iop, LIBIO_FLAGS_READ );
/* /*
* If this file descriptor is mapped to an external set of handlers, * If this file descriptor is mapped to an external set of handlers,
* then pass the request on to them. * then pass the request on to them.
*/ */
if ( rtems_file_descriptor_type( fd ) ) { if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) {
rtems_libio_read_t fp; rtems_libio_read_t fp;
fp = rtems_libio_handlers[rtems_file_descriptor_type_index(fd)].read; fp = rtems_libio_handlers[
(iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].read;
if ( fp == NULL ) if ( fp == NULL )
set_errno_and_return_minus_one( EBADF ); set_errno_and_return_minus_one( EBADF );
@@ -45,12 +52,6 @@ int read(
* Now process the read(). * Now process the read().
*/ */
iop = rtems_libio_iop( fd );
rtems_libio_check_fd( fd );
rtems_libio_check_buffer( buffer );
rtems_libio_check_count( count );
rtems_libio_check_permissions( iop, LIBIO_FLAGS_READ );
if ( !iop->handlers->read ) if ( !iop->handlers->read )
set_errno_and_return_minus_one( ENOTSUP ); set_errno_and_return_minus_one( ENOTSUP );

View File

@@ -34,15 +34,22 @@ int write( /* XXX this should return a ssize_t */
rtems_status_code rc; rtems_status_code rc;
rtems_libio_t *iop; rtems_libio_t *iop;
rtems_libio_check_fd( fd );
iop = rtems_libio_iop( fd );
rtems_libio_check_buffer( buffer );
rtems_libio_check_count( count );
rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE );
/* /*
* If this file descriptor is mapped to an external set of handlers, * If this file descriptor is mapped to an external set of handlers,
* then pass the request on to them. * then pass the request on to them.
*/ */
if ( rtems_file_descriptor_type( fd ) ) { if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) {
rtems_libio_write_t fp; rtems_libio_write_t fp;
fp = rtems_libio_handlers[rtems_file_descriptor_type_index(fd)].write; fp = rtems_libio_handlers[
(iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].write;
if ( fp == NULL ) if ( fp == NULL )
set_errno_and_return_minus_one( EBADF ); set_errno_and_return_minus_one( EBADF );
@@ -53,12 +60,6 @@ int write( /* XXX this should return a ssize_t */
* Now process the write() request. * Now process the write() request.
*/ */
iop = rtems_libio_iop( fd );
rtems_libio_check_fd( fd );
rtems_libio_check_buffer( buffer );
rtems_libio_check_count( count );
rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE );
if ( !iop->handlers->write ) if ( !iop->handlers->write )
set_errno_and_return_minus_one( ENOTSUP ); set_errno_and_return_minus_one( ENOTSUP );

View File

@@ -30,19 +30,6 @@
#include <net/netisr.h> #include <net/netisr.h>
#include <net/route.h> #include <net/route.h>
/*
* Events used by networking routines.
* Everything will break if the application
* tries to use these events or if the `sleep'
* events are equal to any of the NETISR * events.
*/
#define SBWAIT_EVENT RTEMS_EVENT_24
#define SOSLEEP_EVENT RTEMS_EVENT_25
#define NETISR_IP_EVENT (1 << NETISR_IP)
#define NETISR_ARP_EVENT (1 << NETISR_ARP)
#define NETISR_EVENTS (NETISR_IP_EVENT|NETISR_ARP_EVENT)
/* /*
* Memory allocation * Memory allocation
*/ */
@@ -246,7 +233,7 @@ rtems_bsdnet_initialize (void)
/* /*
* Register as an external I/O handler * Register as an external I/O handler
*/ */
rtems_register_libio_handler (RTEMS_FILE_DESCRIPTOR_TYPE_SOCKET, rtems_register_libio_handler (LIBIO_FLAGS_HANDLER_SOCK,
&rtems_bsdnet_io_handler); &rtems_bsdnet_io_handler);
/* /*
@@ -305,16 +292,9 @@ sbwait(sb)
/* /*
* Set this task as the target of the wakeup operation. * Set this task as the target of the wakeup operation.
*/ */
if (sb->sb_sel.si_pid)
rtems_panic ("Another task is already sleeping on that socket buffer");
rtems_task_ident (RTEMS_SELF, 0, &tid); rtems_task_ident (RTEMS_SELF, 0, &tid);
sb->sb_sel.si_pid = tid; sb->sb_sel.si_pid = tid;
/*
* Mark the socket buffer as waiting.
*/
sb->sb_flags |= SB_WAIT;
/* /*
* Release the network semaphore. * Release the network semaphore.
*/ */
@@ -330,12 +310,6 @@ sbwait(sb)
*/ */
rtems_bsdnet_semaphore_obtain (); rtems_bsdnet_semaphore_obtain ();
/*
* Relinquish ownership of the socket buffer
*/
sb->sb_flags &= ~SB_WAIT;
sb->sb_sel.si_pid = 0;
/* /*
* Return the status of the wait. * Return the status of the wait.
*/ */
@@ -355,9 +329,11 @@ sowakeup(so, sb)
register struct socket *so; register struct socket *so;
register struct sockbuf *sb; register struct sockbuf *sb;
{ {
if (sb->sb_flags & SB_WAIT) { rtems_id tid;
sb->sb_flags &= ~SB_WAIT;
rtems_event_send (sb->sb_sel.si_pid, SBWAIT_EVENT); if ((tid = sb->sb_sel.si_pid) != 0) {
sb->sb_sel.si_pid = 0;
rtems_event_send (tid, SBWAIT_EVENT);
} }
} }

View File

@@ -25,77 +25,6 @@
#include <net/if.h> #include <net/if.h>
#include <net/route.h> #include <net/route.h>
/*
*********************************************************************
* Map RTEMS file descriptor to BSD socket *
*********************************************************************
*/
struct fdsock {
int indexFreeNext;
struct socket *sock;
};
static struct fdsock *fdsock;
static int fdsockCount;
static int indexFreeHead = -1;
/*
* Convert an RTEMS file descriptor to a BSD socket pointer.
*/
static struct socket *
fdToSocket (int fd)
{
int i;
struct socket *s;
if ((fd < 0)
|| (rtems_file_descriptor_type(fd) != RTEMS_FILE_DESCRIPTOR_TYPE_SOCKET)
|| ((i = rtems_file_descriptor_base(fd)) >= fdsockCount)
|| ((s = fdsock[i].sock) == NULL)) {
errno = EBADF;
return NULL;
}
return s;
}
/*
* Enlarge the size of the file-descritor/socket pointer map.
*/
static int
enlargeFdMap (void)
{
struct fdsock *nfdsock;
int i;
nfdsock = realloc (fdsock, sizeof *fdsock * (fdsockCount + 20));
if (nfdsock == NULL) {
errno = ENFILE;
return 0;
}
fdsock = nfdsock;
for (i = fdsockCount, fdsockCount += 20 ; i < fdsockCount ; i++) {
fdsock[i].sock = NULL;
fdsock[i].indexFreeNext = indexFreeHead;
indexFreeHead = i;
}
return 1;
}
/*
* Create a file descriptor for a new socket
*/
static int
makeFd (struct socket *s)
{
int i;
if ((indexFreeHead < 0) && !enlargeFdMap ())
return -1;
i = indexFreeHead;
indexFreeHead = fdsock[i].indexFreeNext;
fdsock[i].sock = s;
return rtems_make_file_descriptor(i,RTEMS_FILE_DESCRIPTOR_TYPE_SOCKET);
}
/* /*
* Package system call argument into mbuf. * Package system call argument into mbuf.
*/ */
@@ -128,14 +57,14 @@ sockargstombuf (struct mbuf **mp, const void *buf, int buflen, int type)
int int
socket (int domain, int type, int protocol) socket (int domain, int type, int protocol)
{ {
int fd = -1; int fd;
int error; int error;
struct socket *so; struct socket *so;
rtems_bsdnet_semaphore_obtain (); rtems_bsdnet_semaphore_obtain ();
error = socreate(domain, &so, type, protocol, NULL); error = socreate(domain, &so, type, protocol, NULL);
if (error == 0) { if (error == 0) {
fd = makeFd (so); fd = rtems_bsdnet_makeFdForSocket (so);
if (fd < 0) if (fd < 0)
soclose (so); soclose (so);
} }
@@ -156,7 +85,7 @@ bind (int s, struct sockaddr *name, int namelen)
struct mbuf *nam; struct mbuf *nam;
rtems_bsdnet_semaphore_obtain (); rtems_bsdnet_semaphore_obtain ();
if ((so = fdToSocket (s)) != NULL) { if ((so = rtems_bsdnet_fdToSocket (s)) != NULL) {
error = sockargstombuf (&nam, name, namelen, MT_SONAME); error = sockargstombuf (&nam, name, namelen, MT_SONAME);
if (error == 0) { if (error == 0) {
error = sobind (so, nam); error = sobind (so, nam);
@@ -183,7 +112,7 @@ connect (int s, struct sockaddr *name, int namelen)
struct mbuf *nam; struct mbuf *nam;
rtems_bsdnet_semaphore_obtain (); rtems_bsdnet_semaphore_obtain ();
if ((so = fdToSocket (s)) == NULL) { if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) {
rtems_bsdnet_semaphore_release (); rtems_bsdnet_semaphore_release ();
return -1; return -1;
} }
@@ -233,7 +162,7 @@ listen (int s, int backlog)
struct socket *so; struct socket *so;
rtems_bsdnet_semaphore_obtain (); rtems_bsdnet_semaphore_obtain ();
if ((so = fdToSocket (s)) != NULL) { if ((so = rtems_bsdnet_fdToSocket (s)) != NULL) {
error = solisten (so, backlog); error = solisten (so, backlog);
if (error == 0) if (error == 0)
ret = 0; ret = 0;
@@ -252,7 +181,7 @@ accept (int s, struct sockaddr *name, int *namelen)
struct mbuf *nam; struct mbuf *nam;
rtems_bsdnet_semaphore_obtain (); rtems_bsdnet_semaphore_obtain ();
if ((head = fdToSocket (s)) == NULL) { if ((head = rtems_bsdnet_fdToSocket (s)) == NULL) {
rtems_bsdnet_semaphore_release (); rtems_bsdnet_semaphore_release ();
return -1; return -1;
} }
@@ -284,7 +213,7 @@ accept (int s, struct sockaddr *name, int *namelen)
TAILQ_REMOVE(&head->so_comp, so, so_list); TAILQ_REMOVE(&head->so_comp, so, so_list);
head->so_qlen--; head->so_qlen--;
fd = makeFd (so); fd = rtems_bsdnet_makeFdForSocket (so);
if (fd < 0) { if (fd < 0) {
TAILQ_INSERT_HEAD(&head->so_comp, so, so_list); TAILQ_INSERT_HEAD(&head->so_comp, so, so_list);
head->so_qlen++; head->so_qlen++;
@@ -325,7 +254,7 @@ sendmsg (int s, const struct msghdr *mp, int flags)
int len; int len;
rtems_bsdnet_semaphore_obtain (); rtems_bsdnet_semaphore_obtain ();
if ((so = fdToSocket (s)) == NULL) { if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) {
rtems_bsdnet_semaphore_release (); rtems_bsdnet_semaphore_release ();
return -1; return -1;
} }
@@ -428,7 +357,7 @@ recvmsg (int s, struct msghdr *mp, int flags)
int len; int len;
rtems_bsdnet_semaphore_obtain (); rtems_bsdnet_semaphore_obtain ();
if ((so = fdToSocket (s)) == NULL) { if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) {
rtems_bsdnet_semaphore_release (); rtems_bsdnet_semaphore_release ();
return -1; return -1;
} }
@@ -547,7 +476,7 @@ setsockopt (int s, int level, int name, const void *val, int len)
int error; int error;
rtems_bsdnet_semaphore_obtain (); rtems_bsdnet_semaphore_obtain ();
if ((so = fdToSocket (s)) == NULL) { if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) {
rtems_bsdnet_semaphore_release (); rtems_bsdnet_semaphore_release ();
return -1; return -1;
} }
@@ -584,7 +513,7 @@ getsockopt (int s, int level, int name, void *aval, int *avalsize)
int error; int error;
rtems_bsdnet_semaphore_obtain (); rtems_bsdnet_semaphore_obtain ();
if ((so = fdToSocket (s)) == NULL) { if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) {
rtems_bsdnet_semaphore_release (); rtems_bsdnet_semaphore_release ();
return -1; return -1;
} }
@@ -626,7 +555,7 @@ getpeersockname (int s, struct sockaddr *name, int *namelen, int pflag)
int error; int error;
rtems_bsdnet_semaphore_obtain (); rtems_bsdnet_semaphore_obtain ();
if ((so = fdToSocket (s)) == NULL) { if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) {
rtems_bsdnet_semaphore_release (); rtems_bsdnet_semaphore_release ();
return -1; return -1;
} }
@@ -676,16 +605,12 @@ rtems_bsdnet_close (int fd)
{ {
struct socket *so; struct socket *so;
int error; int error;
int i;
rtems_bsdnet_semaphore_obtain (); rtems_bsdnet_semaphore_obtain ();
if ((so = fdToSocket (fd)) == NULL) { if ((so = rtems_bsdnet_fdToSocket (fd)) == NULL) {
rtems_bsdnet_semaphore_release (); rtems_bsdnet_semaphore_release ();
return -1; return -1;
} }
i = rtems_file_descriptor_base(fd);
fdsock[i].indexFreeNext = indexFreeHead;;
indexFreeHead = i;
error = soclose (so); error = soclose (so);
rtems_bsdnet_semaphore_release (); rtems_bsdnet_semaphore_release ();
if (error) { if (error) {
@@ -737,7 +662,7 @@ rtems_bsdnet_ioctl (int fd, unsigned32 command, void *buffer)
int error; int error;
rtems_bsdnet_semaphore_obtain (); rtems_bsdnet_semaphore_obtain ();
if ((so = fdToSocket (fd)) == NULL) { if ((so = rtems_bsdnet_fdToSocket (fd)) == NULL) {
rtems_bsdnet_semaphore_release (); rtems_bsdnet_semaphore_release ();
return -1; return -1;
} }