Changeset 73f6236 in rtems


Ignore:
Timestamp:
Mar 1, 1999, 10:40:08 PM (23 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, 4.8, 4.9, 5, master
Children:
9d81380
Parents:
e069cdc3
Message:

Patch from Eric Norum <eric@…> to eliminate external
IO handlers scheme that was implemented originally just to support
sockets. The file system IO switch is more general and works fine.

Files:
68 edited

Legend:

Unmodified
Added
Removed
  • c/src/exec/include/rtems/libio_.h

    re069cdc3 r73f6236  
    6767extern rtems_libio_t  *rtems_libio_last_iop;
    6868extern rtems_libio_t *rtems_libio_iop_freelist;
    69 
    70 /*
    71  *  External I/O Handlers Table
    72  *
    73  *  Space for all possible handlers is preallocated
    74  *  to speed up dispatch to external handlers.
    75  */
    76 
    77 extern rtems_libio_handler_t   rtems_libio_handlers[15];
    7869
    7970/*
  • c/src/exec/libcsupport/include/rtems/libio.h

    re069cdc3 r73f6236  
    398398#define LIBIO_FLAGS_CREATE        0x0400  /* create file */
    399399#define LIBIO_FLAGS_CLOSE_ON_EXEC 0x0800  /* close on process exec() */
    400 
    401 #define LIBIO_FLAGS_HANDLER_SHIFT 12
    402 #define LIBIO_FLAGS_HANDLER_MASK  0xF000  /* mask for external handler type */
    403 #define LIBIO_FLAGS_HANDLER_RTEMS 0x0000  /* `traditional' RTEMS I/O */
    404 #define LIBIO_FLAGS_HANDLER_SOCK  0x1000  /* BSD socket */
    405 
    406400#define LIBIO_FLAGS_READ_WRITE    (LIBIO_FLAGS_READ | LIBIO_FLAGS_WRITE)
    407 
    408401
    409402void rtems_libio_init(void);
     
    446439  int    whence
    447440);
    448 
    449 typedef struct {
    450     rtems_libio_open_t   open;
    451     rtems_libio_close_t  close;
    452     rtems_libio_read_t   read;
    453     rtems_libio_write_t  write;
    454     rtems_libio_ioctl_t  ioctl;
    455     rtems_libio_lseek_t  lseek;
    456 } rtems_libio_handler_t;
    457 
    458 /*
    459  *  Register a set of external handlers
    460  */
    461 
    462 void rtems_register_libio_handler(
    463   int                          handler_flag,
    464   const rtems_libio_handler_t *handler
    465 );
    466 
    467 /*
    468  *  Macros to assist in management of external IO handlers.
    469  */
    470 
    471 #define RTEMS_FILE_DESCRIPTOR_TYPE_FILE         0x0000
    472 #define RTEMS_FILE_DESCRIPTOR_TYPE_SOCKET       0x1000
    473 #define rtems_make_file_descriptor(fd,flags)    ((fd)|(flags))
    474 #define rtems_file_descriptor_base(fd)          ((fd) & 0x0FFF)
    475 #define rtems_file_descriptor_type(fd)          ((fd) & 0xF000)
    476 #define rtems_file_descriptor_type_index(fd)    ((((fd) & 0xF000) >> 12) - 1)
    477441
    478442/*
  • c/src/exec/libcsupport/include/rtems/libio_.h

    re069cdc3 r73f6236  
    6767extern rtems_libio_t  *rtems_libio_last_iop;
    6868extern rtems_libio_t *rtems_libio_iop_freelist;
    69 
    70 /*
    71  *  External I/O Handlers Table
    72  *
    73  *  Space for all possible handlers is preallocated
    74  *  to speed up dispatch to external handlers.
    75  */
    76 
    77 extern rtems_libio_handler_t   rtems_libio_handlers[15];
    7869
    7970/*
  • c/src/exec/libcsupport/src/close.c

    re069cdc3 r73f6236  
    2121  rtems_libio_t      *iop;
    2222  rtems_status_code   rc;
    23   int                 status;
    2423
    2524  rtems_libio_check_fd(fd);
    2625  iop = rtems_libio_iop(fd);
    2726  rtems_libio_check_is_open(iop);
    28   if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) {
    29     int (*fp)(int  fd);
    3027
    31     fp = rtems_libio_handlers[
    32             (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].close;
    33     if ( fp == NULL )
    34       set_errno_and_return_minus_one( EBADF );
    35     status = (*fp)( fd );
    36     return status;
    37   }
    38 
    39   if ( !iop->handlers )
    40     set_errno_and_return_minus_one( EBADF );
    41 
    42   if ( !iop->handlers->close )
    43     set_errno_and_return_minus_one( ENOTSUP );
    44 
    45   rc = (*iop->handlers->close)( iop );
     28  rc = RTEMS_SUCCESSFUL;
     29  if ( iop->handlers->close )
     30    rc = (*iop->handlers->close)( iop );
    4631
    4732  rtems_libio_free( iop );
    48 
    49   if (rc != RTEMS_SUCCESSFUL)
    50     set_errno_and_return_minus_one( rc );
    5133
    5234  return rc;
  • c/src/exec/libcsupport/src/fchmod.c

    re069cdc3 r73f6236  
    3333
    3434  /*
    35    *  If this is not a file system based entity, it is an error.
    36    */
    37 
    38   if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK )
    39     set_errno_and_return_minus_one( EBADF );
    40 
    41   /*
    4235   *  Now process the fchmod().
    4336   */
  • c/src/exec/libcsupport/src/fcntl.c

    re069cdc3 r73f6236  
    3636  iop = rtems_libio_iop( fd );
    3737  rtems_libio_check_is_open(iop);
    38 
    39   /*
    40    *  If this is not a file system based entity, it is an error.
    41    */
    42 
    43   if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK )
    44     set_errno_and_return_minus_one( EBADF );
    4538
    4639  /*
  • c/src/exec/libcsupport/src/fdatasync.c

    re069cdc3 r73f6236  
    2929
    3030  /*
    31    *  If this file descriptor is mapped to an external set of handlers,
    32    *  then pass the request on to them.
    33    */
    34 
    35   if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK )
    36     set_errno_and_return_minus_one( EBADF );
    37 
    38   /*
    3931   *  Now process the fdatasync().
    4032   */
  • c/src/exec/libcsupport/src/fpathconf.c

    re069cdc3 r73f6236  
    3131  rtems_libio_check_is_open(iop);
    3232  rtems_libio_check_permissions(iop, LIBIO_FLAGS_READ);
    33 
    34   /*
    35    *  If this file descriptor is mapped to an external set of handlers,
    36    *  then it is an error since fpathconf() is not included in the
    37    *  set.
    38    */
    39 
    40   if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK )
    41     set_errno_and_return_minus_one( EBADF );
    4233
    4334  /*
  • c/src/exec/libcsupport/src/fstat.c

    re069cdc3 r73f6236  
    3434
    3535  /*
    36    *  Zero out the stat structure so the various support
    37    *  versions of stat don't have to.
    38    */
    39 
    40   memset( sbuf, 0, sizeof(struct stat) );
    41 
    42   /*
    43    *  If this file descriptor is mapped to an external set of handlers,
    44    *  then pass the request on to them.
    45    */
    46 
    47   if (rtems_file_descriptor_type(fd)) {
    48     switch (rtems_file_descriptor_type (fd)) {
    49       case RTEMS_FILE_DESCRIPTOR_TYPE_FILE:
    50         break;
    51 
    52       case RTEMS_FILE_DESCRIPTOR_TYPE_SOCKET:
    53 #if !defined(__GO32__)
    54         sbuf->st_mode = S_IFSOCK;
    55         break;
    56 #endif
    57 
    58       default:
    59         set_errno_and_return_minus_one( EBADF );
    60     }
    61   }
    62 
    63   /*
    6436   *  Now process the stat() request.
    6537   */
     
    6941  rtems_libio_check_is_open(iop);
    7042
     43  if ( !iop->handlers )
     44    set_errno_and_return_minus_one( EBADF );
     45
    7146  if ( !iop->handlers->fstat )
    7247    set_errno_and_return_minus_one( ENOTSUP );
     48
     49  /*
     50   *  Zero out the stat structure so the various support
     51   *  versions of stat don't have to.
     52   */
     53  memset( sbuf, 0, sizeof(struct stat) );
    7354
    7455  return (*iop->handlers->fstat)( &iop->pathinfo, sbuf );
  • c/src/exec/libcsupport/src/fsync.c

    re069cdc3 r73f6236  
    2929
    3030  /*
    31    *  If this file descriptor is mapped to an external set of handlers,
    32    *  then pass the request on to them.
    33    */
    34 
    35   if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK )
    36     set_errno_and_return_minus_one( EBADF );
    37 
    38   /*
    3931   *  Now process the fsync().
    4032   */
  • c/src/exec/libcsupport/src/ftruncate.c

    re069cdc3 r73f6236  
    3131
    3232  /*
    33    *  If this is not a file system based entity, it is an error.
    34    */
    35 
    36   if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK )
    37     set_errno_and_return_minus_one( EBADF );
    38 
    39   /*
    4033   *  Now process the ftruncate() request.
    4134   */
  • c/src/exec/libcsupport/src/ioctl.c

    re069cdc3 r73f6236  
    3232
    3333  /*
    34    *  If this file descriptor is mapped to an external set of handlers,
    35    *  then pass the request on to them.
    36    */
    37 
    38   if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) {
    39     rtems_libio_ioctl_t fp;
    40 
    41     fp = rtems_libio_handlers[
    42            (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].ioctl;
    43     if ( fp == NULL )
    44       set_errno_and_return_minus_one( EBADF );
    45 
    46     return (*fp)( fd, command, buffer );
    47   }
    48 
    49   /*
    5034   *  Now process the ioctl().
    5135   */
  • c/src/exec/libcsupport/src/libio.c

    re069cdc3 r73f6236  
    5151
    5252/*
    53  *  External I/O Handlers Table
    54  *
    55  *  Space for all possible handlers is preallocated
    56  *  to speed up dispatch to external handlers.
    57  */
    58 
    59 rtems_libio_handler_t   rtems_libio_handlers[15];
    60 
    61 /*
    6253 *  Default mode for all files.
    6354 */
    6455
    6556mode_t    rtems_filesystem_umask;
    66 
    67 /*
    68  *  rtems_register_libio_handler
    69  *
    70  *  This function registers an external IO handler set.  This lets
    71  *  other subsystems have their own versions of many of the system
    72  *  calls.  For example, the networking code registers handlers which
    73  *  map the system calls for read() and write() to socket calls.
    74  *
    75  */
    76 
    77 void rtems_register_libio_handler(
    78   int                          handler_flag,
    79   const rtems_libio_handler_t *handler
    80 )
    81 {
    82   int handler_index = (handler_flag >> LIBIO_FLAGS_HANDLER_SHIFT) - 1;
    83 
    84   if ((handler_index < 0) || (handler_index >= 15))
    85     rtems_fatal_error_occurred( RTEMS_INVALID_NUMBER );
    86 
    87   rtems_libio_handlers[handler_index] = *handler;
    88 }
    8957
    9058/*
  • c/src/exec/libcsupport/src/libio_sockets.c

    re069cdc3 r73f6236  
    1919#include <errno.h>
    2020
    21 
    2221/*
    2322 * Convert an RTEMS file descriptor to a BSD socket pointer.
     
    3029  rtems_libio_t *iop;
    3130
    32   if ((unsigned32)fd >= rtems_libio_number_iops)
    33       return NULL;
     31  if ((unsigned32)fd >= rtems_libio_number_iops) {
     32    errno = EBADF;
     33    return NULL;
     34  }
    3435  iop = &rtems_libio_iops[fd];
    35   if ((iop->flags & LIBIO_FLAGS_HANDLER_MASK) != LIBIO_FLAGS_HANDLER_SOCK)
    36       return NULL;
     36  if (iop->data1 == NULL)
     37    errno = EBADF;
    3738  return iop->data1;
    3839}
     
    4344
    4445int rtems_bsdnet_makeFdForSocket(
    45   void *so
     46  void *so,
     47  const rtems_filesystem_file_handlers_r *h
    4648)
    4749{
    4850  rtems_libio_t *iop;
     51  int fd;
    4952
    5053  iop = rtems_libio_allocate();
     
    5356      return -1;
    5457  }
    55   iop->flags |= LIBIO_FLAGS_HANDLER_SOCK | LIBIO_FLAGS_WRITE | LIBIO_FLAGS_READ;
     58  fd = iop - rtems_libio_iops;
     59  iop->flags |= LIBIO_FLAGS_WRITE | LIBIO_FLAGS_READ;
     60  iop->data0 = fd;
    5661  iop->data1 = so;
    57   return iop - rtems_libio_iops;
     62  iop->handlers = h;
     63  return fd;
    5864}
  • c/src/exec/libcsupport/src/lseek.c

    re069cdc3 r73f6236  
    2828  iop = rtems_libio_iop( fd );
    2929  rtems_libio_check_is_open(iop);
    30 
    31   /*
    32    *  If this file descriptor is mapped to an external set of handlers,
    33    *  then pass the request on to them.
    34    */
    35 
    36   if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) {
    37     rtems_libio_lseek_t fp;
    38 
    39     fp = rtems_libio_handlers[
    40            (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].lseek;
    41     if ( fp == NULL )
    42       set_errno_and_return_minus_one( EBADF );
    43 
    44     return (*fp)( fd, offset, whence );
    45   }
    4630
    4731  /*
  • c/src/exec/libcsupport/src/read.c

    re069cdc3 r73f6236  
    3030  rtems_libio_check_count( count );
    3131  rtems_libio_check_permissions( iop, LIBIO_FLAGS_READ );
    32 
    33   /*
    34    *  If this file descriptor is mapped to an external set of handlers,
    35    *  then pass the request on to them.
    36    */
    37 
    38   if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) {
    39     rtems_libio_read_t fp;
    40 
    41     fp = rtems_libio_handlers[
    42            (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].read;
    43     if ( fp == NULL )
    44       set_errno_and_return_minus_one( EBADF );
    45 
    46     return (*fp)( fd, buffer, count );
    47   }
    4832
    4933  /*
  • c/src/exec/libcsupport/src/write.c

    re069cdc3 r73f6236  
    4040
    4141  /*
    42    *  If this file descriptor is mapped to an external set of handlers,
    43    *  then pass the request on to them.
    44    */
    45 
    46   if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) {
    47     rtems_libio_write_t fp;
    48 
    49     fp = rtems_libio_handlers[
    50            (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].write;
    51     if ( fp == NULL )
    52       set_errno_and_return_minus_one( EBADF );
    53 
    54     return (*fp)( fd, buffer, count );
    55   }
    56 
    57   /*
    5842   *  Now process the write() request.
    5943   */
  • c/src/exec/libnetworking/rtems/rtems_bsdnet_internal.h

    re069cdc3 r73f6236  
    175175int socket (int, int, int);
    176176int ioctl (int, unsigned long, ...);
    177 struct socket *rtems_bsdnet_fdToSocket (int fd);
    178 int rtems_bsdnet_makeFdForSocket (void *);
    179177
    180178/*
  • c/src/exec/libnetworking/rtems/rtems_glue.c

    re069cdc3 r73f6236  
    7878                        sizeof rtems_bsdnet_config.name_server[0]];
    7979int rtems_bsdnet_nameserver_count;
    80 
    81 extern rtems_libio_handler_t rtems_bsdnet_io_handler;
    8280
    8381/*
     
    230228         */
    231229        networkDaemonTid = rtems_bsdnet_newproc ("ntwk", 4096, networkDaemon, NULL);
    232 
    233         /*
    234          * Register as an external I/O handler
    235          */
    236         rtems_register_libio_handler (LIBIO_FLAGS_HANDLER_SOCK,
    237                                                 &rtems_bsdnet_io_handler);
    238230
    239231        /*
  • c/src/exec/libnetworking/rtems/rtems_select.c

    re069cdc3 r73f6236  
    4747
    4848static __inline int imin(int a, int b) { return (a < b ? a : b); }
     49struct socket *rtems_bsdnet_fdToSocket(int fd);
    4950
    5051static int
  • c/src/exec/libnetworking/rtems/rtems_syscall.c

    re069cdc3 r73f6236  
    2525#include <net/if.h>
    2626#include <net/route.h>
     27
     28/*
     29 * Hooks to RTEMS I/O system
     30 */
     31static const rtems_filesystem_file_handlers_r socket_handlers;
     32int rtems_bsdnet_makeFdForSocket(void *so, const rtems_filesystem_file_handlers_r *h);
     33struct socket *rtems_bsdnet_fdToSocket(int fd);
    2734
    2835/*
     
    6572        error = socreate(domain, &so, type, protocol, NULL);
    6673        if (error == 0) {
    67                 fd = rtems_bsdnet_makeFdForSocket (so);
     74                fd = rtems_bsdnet_makeFdForSocket (so, &socket_handlers);
    6875                if (fd < 0)
    6976                        soclose (so);
     
    214221        head->so_qlen--;
    215222
    216         fd = rtems_bsdnet_makeFdForSocket (so);
     223        fd = rtems_bsdnet_makeFdForSocket (so, &socket_handlers);
    217224        if (fd < 0) {
    218225                TAILQ_INSERT_HEAD(&head->so_comp, so, so_list);
     
    601608/*
    602609 ************************************************************************
    603  *                 RTEMS EXTERNAL I/O HANDLER ROUTINES                  *
     610 *                      RTEMS I/O HANDLER ROUTINES                      *
    604611 ************************************************************************
    605612 */
    606613static int
    607 rtems_bsdnet_close (int fd)
    608 {
    609         struct socket *so;
    610         int error;
    611 
    612         rtems_bsdnet_semaphore_obtain ();
    613         if ((so = rtems_bsdnet_fdToSocket (fd)) == NULL) {
     614rtems_bsdnet_close (rtems_libio_t *iop)
     615{
     616        struct socket *so;
     617        int error;
     618
     619        rtems_bsdnet_semaphore_obtain ();
     620        if ((so = iop->data1) == NULL) {
     621                errno = EBADF;
    614622                rtems_bsdnet_semaphore_release ();
    615623                return -1;
     
    625633
    626634static int
    627 rtems_bsdnet_read (int fd, void *buffer, unsigned32 count)
    628 {
    629         return recv (fd, buffer, count, 0);
     635rtems_bsdnet_read (rtems_libio_t *iop, void *buffer, unsigned32 count)
     636{
     637        return recv (iop->data0, buffer, count, 0);
    630638}
    631639
    632640static int
    633 rtems_bsdnet_write (int fd, const void *buffer, unsigned32 count)
    634 {
    635         return send (fd, buffer, count, 0);
     641rtems_bsdnet_write (rtems_libio_t *iop, const void *buffer, unsigned32 count)
     642{
     643        return send (iop->data0, buffer, count, 0);
    636644}
    637645
     
    660668
    661669static int
    662 rtems_bsdnet_ioctl (int fd, unsigned32 command, void *buffer)
    663 {
    664         struct socket *so;
    665         int error;
    666 
    667         rtems_bsdnet_semaphore_obtain ();
    668         if ((so = rtems_bsdnet_fdToSocket (fd)) == NULL) {
     670rtems_bsdnet_ioctl (rtems_libio_t *iop, unsigned32 command, void *buffer)
     671{
     672        struct socket *so;
     673        int error;
     674
     675        rtems_bsdnet_semaphore_obtain ();
     676        if ((so = iop->data1) == NULL) {
     677                errno = EBADF;
    669678                rtems_bsdnet_semaphore_release ();
    670679                return -1;
     
    679688}
    680689
    681 rtems_libio_handler_t rtems_bsdnet_io_handler = {
     690static int
     691rtems_bsdnet_fstat (rtems_filesystem_location_info_t *loc, struct stat *sp)
     692{
     693        sp->st_mode = S_IFSOCK;
     694        return 0;
     695}
     696
     697static const rtems_filesystem_file_handlers_r socket_handlers = {
    682698        NULL,                   /* open */
    683699        rtems_bsdnet_close,     /* close */
     
    686702        rtems_bsdnet_ioctl,     /* ioctl */
    687703        NULL,                   /* lseek */
     704        rtems_bsdnet_fstat,     /* fstat */
     705        NULL,                   /* fchmod */
     706        NULL,                   /* ftruncate */
     707        NULL,                   /* fpathconf */
     708        NULL,                   /* fsync */
     709        NULL,                   /* fdatasync */
    688710};
    689 
  • c/src/lib/include/rtems/libio.h

    re069cdc3 r73f6236  
    398398#define LIBIO_FLAGS_CREATE        0x0400  /* create file */
    399399#define LIBIO_FLAGS_CLOSE_ON_EXEC 0x0800  /* close on process exec() */
    400 
    401 #define LIBIO_FLAGS_HANDLER_SHIFT 12
    402 #define LIBIO_FLAGS_HANDLER_MASK  0xF000  /* mask for external handler type */
    403 #define LIBIO_FLAGS_HANDLER_RTEMS 0x0000  /* `traditional' RTEMS I/O */
    404 #define LIBIO_FLAGS_HANDLER_SOCK  0x1000  /* BSD socket */
    405 
    406400#define LIBIO_FLAGS_READ_WRITE    (LIBIO_FLAGS_READ | LIBIO_FLAGS_WRITE)
    407 
    408401
    409402void rtems_libio_init(void);
     
    446439  int    whence
    447440);
    448 
    449 typedef struct {
    450     rtems_libio_open_t   open;
    451     rtems_libio_close_t  close;
    452     rtems_libio_read_t   read;
    453     rtems_libio_write_t  write;
    454     rtems_libio_ioctl_t  ioctl;
    455     rtems_libio_lseek_t  lseek;
    456 } rtems_libio_handler_t;
    457 
    458 /*
    459  *  Register a set of external handlers
    460  */
    461 
    462 void rtems_register_libio_handler(
    463   int                          handler_flag,
    464   const rtems_libio_handler_t *handler
    465 );
    466 
    467 /*
    468  *  Macros to assist in management of external IO handlers.
    469  */
    470 
    471 #define RTEMS_FILE_DESCRIPTOR_TYPE_FILE         0x0000
    472 #define RTEMS_FILE_DESCRIPTOR_TYPE_SOCKET       0x1000
    473 #define rtems_make_file_descriptor(fd,flags)    ((fd)|(flags))
    474 #define rtems_file_descriptor_base(fd)          ((fd) & 0x0FFF)
    475 #define rtems_file_descriptor_type(fd)          ((fd) & 0xF000)
    476 #define rtems_file_descriptor_type_index(fd)    ((((fd) & 0xF000) >> 12) - 1)
    477441
    478442/*
  • c/src/lib/include/rtems/libio_.h

    re069cdc3 r73f6236  
    6767extern rtems_libio_t  *rtems_libio_last_iop;
    6868extern rtems_libio_t *rtems_libio_iop_freelist;
    69 
    70 /*
    71  *  External I/O Handlers Table
    72  *
    73  *  Space for all possible handlers is preallocated
    74  *  to speed up dispatch to external handlers.
    75  */
    76 
    77 extern rtems_libio_handler_t   rtems_libio_handlers[15];
    7869
    7970/*
  • c/src/lib/libc/close.c

    re069cdc3 r73f6236  
    2121  rtems_libio_t      *iop;
    2222  rtems_status_code   rc;
    23   int                 status;
    2423
    2524  rtems_libio_check_fd(fd);
    2625  iop = rtems_libio_iop(fd);
    2726  rtems_libio_check_is_open(iop);
    28   if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) {
    29     int (*fp)(int  fd);
    3027
    31     fp = rtems_libio_handlers[
    32             (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].close;
    33     if ( fp == NULL )
    34       set_errno_and_return_minus_one( EBADF );
    35     status = (*fp)( fd );
    36     return status;
    37   }
    38 
    39   if ( !iop->handlers )
    40     set_errno_and_return_minus_one( EBADF );
    41 
    42   if ( !iop->handlers->close )
    43     set_errno_and_return_minus_one( ENOTSUP );
    44 
    45   rc = (*iop->handlers->close)( iop );
     28  rc = RTEMS_SUCCESSFUL;
     29  if ( iop->handlers->close )
     30    rc = (*iop->handlers->close)( iop );
    4631
    4732  rtems_libio_free( iop );
    48 
    49   if (rc != RTEMS_SUCCESSFUL)
    50     set_errno_and_return_minus_one( rc );
    5133
    5234  return rc;
  • c/src/lib/libc/fchmod.c

    re069cdc3 r73f6236  
    3333
    3434  /*
    35    *  If this is not a file system based entity, it is an error.
    36    */
    37 
    38   if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK )
    39     set_errno_and_return_minus_one( EBADF );
    40 
    41   /*
    4235   *  Now process the fchmod().
    4336   */
  • c/src/lib/libc/fcntl.c

    re069cdc3 r73f6236  
    3636  iop = rtems_libio_iop( fd );
    3737  rtems_libio_check_is_open(iop);
    38 
    39   /*
    40    *  If this is not a file system based entity, it is an error.
    41    */
    42 
    43   if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK )
    44     set_errno_and_return_minus_one( EBADF );
    4538
    4639  /*
  • c/src/lib/libc/fdatasync.c

    re069cdc3 r73f6236  
    2929
    3030  /*
    31    *  If this file descriptor is mapped to an external set of handlers,
    32    *  then pass the request on to them.
    33    */
    34 
    35   if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK )
    36     set_errno_and_return_minus_one( EBADF );
    37 
    38   /*
    3931   *  Now process the fdatasync().
    4032   */
  • c/src/lib/libc/fpathconf.c

    re069cdc3 r73f6236  
    3131  rtems_libio_check_is_open(iop);
    3232  rtems_libio_check_permissions(iop, LIBIO_FLAGS_READ);
    33 
    34   /*
    35    *  If this file descriptor is mapped to an external set of handlers,
    36    *  then it is an error since fpathconf() is not included in the
    37    *  set.
    38    */
    39 
    40   if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK )
    41     set_errno_and_return_minus_one( EBADF );
    4233
    4334  /*
  • c/src/lib/libc/fstat.c

    re069cdc3 r73f6236  
    3434
    3535  /*
    36    *  Zero out the stat structure so the various support
    37    *  versions of stat don't have to.
    38    */
    39 
    40   memset( sbuf, 0, sizeof(struct stat) );
    41 
    42   /*
    43    *  If this file descriptor is mapped to an external set of handlers,
    44    *  then pass the request on to them.
    45    */
    46 
    47   if (rtems_file_descriptor_type(fd)) {
    48     switch (rtems_file_descriptor_type (fd)) {
    49       case RTEMS_FILE_DESCRIPTOR_TYPE_FILE:
    50         break;
    51 
    52       case RTEMS_FILE_DESCRIPTOR_TYPE_SOCKET:
    53 #if !defined(__GO32__)
    54         sbuf->st_mode = S_IFSOCK;
    55         break;
    56 #endif
    57 
    58       default:
    59         set_errno_and_return_minus_one( EBADF );
    60     }
    61   }
    62 
    63   /*
    6436   *  Now process the stat() request.
    6537   */
     
    6941  rtems_libio_check_is_open(iop);
    7042
     43  if ( !iop->handlers )
     44    set_errno_and_return_minus_one( EBADF );
     45
    7146  if ( !iop->handlers->fstat )
    7247    set_errno_and_return_minus_one( ENOTSUP );
     48
     49  /*
     50   *  Zero out the stat structure so the various support
     51   *  versions of stat don't have to.
     52   */
     53  memset( sbuf, 0, sizeof(struct stat) );
    7354
    7455  return (*iop->handlers->fstat)( &iop->pathinfo, sbuf );
  • c/src/lib/libc/fsync.c

    re069cdc3 r73f6236  
    2929
    3030  /*
    31    *  If this file descriptor is mapped to an external set of handlers,
    32    *  then pass the request on to them.
    33    */
    34 
    35   if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK )
    36     set_errno_and_return_minus_one( EBADF );
    37 
    38   /*
    3931   *  Now process the fsync().
    4032   */
  • c/src/lib/libc/ftruncate.c

    re069cdc3 r73f6236  
    3131
    3232  /*
    33    *  If this is not a file system based entity, it is an error.
    34    */
    35 
    36   if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK )
    37     set_errno_and_return_minus_one( EBADF );
    38 
    39   /*
    4033   *  Now process the ftruncate() request.
    4134   */
  • c/src/lib/libc/ioctl.c

    re069cdc3 r73f6236  
    3232
    3333  /*
    34    *  If this file descriptor is mapped to an external set of handlers,
    35    *  then pass the request on to them.
    36    */
    37 
    38   if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) {
    39     rtems_libio_ioctl_t fp;
    40 
    41     fp = rtems_libio_handlers[
    42            (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].ioctl;
    43     if ( fp == NULL )
    44       set_errno_and_return_minus_one( EBADF );
    45 
    46     return (*fp)( fd, command, buffer );
    47   }
    48 
    49   /*
    5034   *  Now process the ioctl().
    5135   */
  • c/src/lib/libc/libio.c

    re069cdc3 r73f6236  
    5151
    5252/*
    53  *  External I/O Handlers Table
    54  *
    55  *  Space for all possible handlers is preallocated
    56  *  to speed up dispatch to external handlers.
    57  */
    58 
    59 rtems_libio_handler_t   rtems_libio_handlers[15];
    60 
    61 /*
    6253 *  Default mode for all files.
    6354 */
    6455
    6556mode_t    rtems_filesystem_umask;
    66 
    67 /*
    68  *  rtems_register_libio_handler
    69  *
    70  *  This function registers an external IO handler set.  This lets
    71  *  other subsystems have their own versions of many of the system
    72  *  calls.  For example, the networking code registers handlers which
    73  *  map the system calls for read() and write() to socket calls.
    74  *
    75  */
    76 
    77 void rtems_register_libio_handler(
    78   int                          handler_flag,
    79   const rtems_libio_handler_t *handler
    80 )
    81 {
    82   int handler_index = (handler_flag >> LIBIO_FLAGS_HANDLER_SHIFT) - 1;
    83 
    84   if ((handler_index < 0) || (handler_index >= 15))
    85     rtems_fatal_error_occurred( RTEMS_INVALID_NUMBER );
    86 
    87   rtems_libio_handlers[handler_index] = *handler;
    88 }
    8957
    9058/*
  • c/src/lib/libc/libio.h

    re069cdc3 r73f6236  
    398398#define LIBIO_FLAGS_CREATE        0x0400  /* create file */
    399399#define LIBIO_FLAGS_CLOSE_ON_EXEC 0x0800  /* close on process exec() */
    400 
    401 #define LIBIO_FLAGS_HANDLER_SHIFT 12
    402 #define LIBIO_FLAGS_HANDLER_MASK  0xF000  /* mask for external handler type */
    403 #define LIBIO_FLAGS_HANDLER_RTEMS 0x0000  /* `traditional' RTEMS I/O */
    404 #define LIBIO_FLAGS_HANDLER_SOCK  0x1000  /* BSD socket */
    405 
    406400#define LIBIO_FLAGS_READ_WRITE    (LIBIO_FLAGS_READ | LIBIO_FLAGS_WRITE)
    407 
    408401
    409402void rtems_libio_init(void);
     
    446439  int    whence
    447440);
    448 
    449 typedef struct {
    450     rtems_libio_open_t   open;
    451     rtems_libio_close_t  close;
    452     rtems_libio_read_t   read;
    453     rtems_libio_write_t  write;
    454     rtems_libio_ioctl_t  ioctl;
    455     rtems_libio_lseek_t  lseek;
    456 } rtems_libio_handler_t;
    457 
    458 /*
    459  *  Register a set of external handlers
    460  */
    461 
    462 void rtems_register_libio_handler(
    463   int                          handler_flag,
    464   const rtems_libio_handler_t *handler
    465 );
    466 
    467 /*
    468  *  Macros to assist in management of external IO handlers.
    469  */
    470 
    471 #define RTEMS_FILE_DESCRIPTOR_TYPE_FILE         0x0000
    472 #define RTEMS_FILE_DESCRIPTOR_TYPE_SOCKET       0x1000
    473 #define rtems_make_file_descriptor(fd,flags)    ((fd)|(flags))
    474 #define rtems_file_descriptor_base(fd)          ((fd) & 0x0FFF)
    475 #define rtems_file_descriptor_type(fd)          ((fd) & 0xF000)
    476 #define rtems_file_descriptor_type_index(fd)    ((((fd) & 0xF000) >> 12) - 1)
    477441
    478442/*
  • c/src/lib/libc/libio_.h

    re069cdc3 r73f6236  
    6767extern rtems_libio_t  *rtems_libio_last_iop;
    6868extern rtems_libio_t *rtems_libio_iop_freelist;
    69 
    70 /*
    71  *  External I/O Handlers Table
    72  *
    73  *  Space for all possible handlers is preallocated
    74  *  to speed up dispatch to external handlers.
    75  */
    76 
    77 extern rtems_libio_handler_t   rtems_libio_handlers[15];
    7869
    7970/*
  • c/src/lib/libc/libio_sockets.c

    re069cdc3 r73f6236  
    1919#include <errno.h>
    2020
    21 
    2221/*
    2322 * Convert an RTEMS file descriptor to a BSD socket pointer.
     
    3029  rtems_libio_t *iop;
    3130
    32   if ((unsigned32)fd >= rtems_libio_number_iops)
    33       return NULL;
     31  if ((unsigned32)fd >= rtems_libio_number_iops) {
     32    errno = EBADF;
     33    return NULL;
     34  }
    3435  iop = &rtems_libio_iops[fd];
    35   if ((iop->flags & LIBIO_FLAGS_HANDLER_MASK) != LIBIO_FLAGS_HANDLER_SOCK)
    36       return NULL;
     36  if (iop->data1 == NULL)
     37    errno = EBADF;
    3738  return iop->data1;
    3839}
     
    4344
    4445int rtems_bsdnet_makeFdForSocket(
    45   void *so
     46  void *so,
     47  const rtems_filesystem_file_handlers_r *h
    4648)
    4749{
    4850  rtems_libio_t *iop;
     51  int fd;
    4952
    5053  iop = rtems_libio_allocate();
     
    5356      return -1;
    5457  }
    55   iop->flags |= LIBIO_FLAGS_HANDLER_SOCK | LIBIO_FLAGS_WRITE | LIBIO_FLAGS_READ;
     58  fd = iop - rtems_libio_iops;
     59  iop->flags |= LIBIO_FLAGS_WRITE | LIBIO_FLAGS_READ;
     60  iop->data0 = fd;
    5661  iop->data1 = so;
    57   return iop - rtems_libio_iops;
     62  iop->handlers = h;
     63  return fd;
    5864}
  • c/src/lib/libc/lseek.c

    re069cdc3 r73f6236  
    2828  iop = rtems_libio_iop( fd );
    2929  rtems_libio_check_is_open(iop);
    30 
    31   /*
    32    *  If this file descriptor is mapped to an external set of handlers,
    33    *  then pass the request on to them.
    34    */
    35 
    36   if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) {
    37     rtems_libio_lseek_t fp;
    38 
    39     fp = rtems_libio_handlers[
    40            (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].lseek;
    41     if ( fp == NULL )
    42       set_errno_and_return_minus_one( EBADF );
    43 
    44     return (*fp)( fd, offset, whence );
    45   }
    4630
    4731  /*
  • c/src/lib/libc/read.c

    re069cdc3 r73f6236  
    3030  rtems_libio_check_count( count );
    3131  rtems_libio_check_permissions( iop, LIBIO_FLAGS_READ );
    32 
    33   /*
    34    *  If this file descriptor is mapped to an external set of handlers,
    35    *  then pass the request on to them.
    36    */
    37 
    38   if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) {
    39     rtems_libio_read_t fp;
    40 
    41     fp = rtems_libio_handlers[
    42            (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].read;
    43     if ( fp == NULL )
    44       set_errno_and_return_minus_one( EBADF );
    45 
    46     return (*fp)( fd, buffer, count );
    47   }
    4832
    4933  /*
  • c/src/lib/libc/write.c

    re069cdc3 r73f6236  
    4040
    4141  /*
    42    *  If this file descriptor is mapped to an external set of handlers,
    43    *  then pass the request on to them.
    44    */
    45 
    46   if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) {
    47     rtems_libio_write_t fp;
    48 
    49     fp = rtems_libio_handlers[
    50            (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].write;
    51     if ( fp == NULL )
    52       set_errno_and_return_minus_one( EBADF );
    53 
    54     return (*fp)( fd, buffer, count );
    55   }
    56 
    57   /*
    5842   *  Now process the write() request.
    5943   */
  • c/src/lib/libnetworking/rtems/rtems_bsdnet_internal.h

    re069cdc3 r73f6236  
    175175int socket (int, int, int);
    176176int ioctl (int, unsigned long, ...);
    177 struct socket *rtems_bsdnet_fdToSocket (int fd);
    178 int rtems_bsdnet_makeFdForSocket (void *);
    179177
    180178/*
  • c/src/lib/libnetworking/rtems/rtems_glue.c

    re069cdc3 r73f6236  
    7878                        sizeof rtems_bsdnet_config.name_server[0]];
    7979int rtems_bsdnet_nameserver_count;
    80 
    81 extern rtems_libio_handler_t rtems_bsdnet_io_handler;
    8280
    8381/*
     
    230228         */
    231229        networkDaemonTid = rtems_bsdnet_newproc ("ntwk", 4096, networkDaemon, NULL);
    232 
    233         /*
    234          * Register as an external I/O handler
    235          */
    236         rtems_register_libio_handler (LIBIO_FLAGS_HANDLER_SOCK,
    237                                                 &rtems_bsdnet_io_handler);
    238230
    239231        /*
  • c/src/lib/libnetworking/rtems/rtems_select.c

    re069cdc3 r73f6236  
    4747
    4848static __inline int imin(int a, int b) { return (a < b ? a : b); }
     49struct socket *rtems_bsdnet_fdToSocket(int fd);
    4950
    5051static int
  • c/src/lib/libnetworking/rtems/rtems_syscall.c

    re069cdc3 r73f6236  
    2525#include <net/if.h>
    2626#include <net/route.h>
     27
     28/*
     29 * Hooks to RTEMS I/O system
     30 */
     31static const rtems_filesystem_file_handlers_r socket_handlers;
     32int rtems_bsdnet_makeFdForSocket(void *so, const rtems_filesystem_file_handlers_r *h);
     33struct socket *rtems_bsdnet_fdToSocket(int fd);
    2734
    2835/*
     
    6572        error = socreate(domain, &so, type, protocol, NULL);
    6673        if (error == 0) {
    67                 fd = rtems_bsdnet_makeFdForSocket (so);
     74                fd = rtems_bsdnet_makeFdForSocket (so, &socket_handlers);
    6875                if (fd < 0)
    6976                        soclose (so);
     
    214221        head->so_qlen--;
    215222
    216         fd = rtems_bsdnet_makeFdForSocket (so);
     223        fd = rtems_bsdnet_makeFdForSocket (so, &socket_handlers);
    217224        if (fd < 0) {
    218225                TAILQ_INSERT_HEAD(&head->so_comp, so, so_list);
     
    601608/*
    602609 ************************************************************************
    603  *                 RTEMS EXTERNAL I/O HANDLER ROUTINES                  *
     610 *                      RTEMS I/O HANDLER ROUTINES                      *
    604611 ************************************************************************
    605612 */
    606613static int
    607 rtems_bsdnet_close (int fd)
    608 {
    609         struct socket *so;
    610         int error;
    611 
    612         rtems_bsdnet_semaphore_obtain ();
    613         if ((so = rtems_bsdnet_fdToSocket (fd)) == NULL) {
     614rtems_bsdnet_close (rtems_libio_t *iop)
     615{
     616        struct socket *so;
     617        int error;
     618
     619        rtems_bsdnet_semaphore_obtain ();
     620        if ((so = iop->data1) == NULL) {
     621                errno = EBADF;
    614622                rtems_bsdnet_semaphore_release ();
    615623                return -1;
     
    625633
    626634static int
    627 rtems_bsdnet_read (int fd, void *buffer, unsigned32 count)
    628 {
    629         return recv (fd, buffer, count, 0);
     635rtems_bsdnet_read (rtems_libio_t *iop, void *buffer, unsigned32 count)
     636{
     637        return recv (iop->data0, buffer, count, 0);
    630638}
    631639
    632640static int
    633 rtems_bsdnet_write (int fd, const void *buffer, unsigned32 count)
    634 {
    635         return send (fd, buffer, count, 0);
     641rtems_bsdnet_write (rtems_libio_t *iop, const void *buffer, unsigned32 count)
     642{
     643        return send (iop->data0, buffer, count, 0);
    636644}
    637645
     
    660668
    661669static int
    662 rtems_bsdnet_ioctl (int fd, unsigned32 command, void *buffer)
    663 {
    664         struct socket *so;
    665         int error;
    666 
    667         rtems_bsdnet_semaphore_obtain ();
    668         if ((so = rtems_bsdnet_fdToSocket (fd)) == NULL) {
     670rtems_bsdnet_ioctl (rtems_libio_t *iop, unsigned32 command, void *buffer)
     671{
     672        struct socket *so;
     673        int error;
     674
     675        rtems_bsdnet_semaphore_obtain ();
     676        if ((so = iop->data1) == NULL) {
     677                errno = EBADF;
    669678                rtems_bsdnet_semaphore_release ();
    670679                return -1;
     
    679688}
    680689
    681 rtems_libio_handler_t rtems_bsdnet_io_handler = {
     690static int
     691rtems_bsdnet_fstat (rtems_filesystem_location_info_t *loc, struct stat *sp)
     692{
     693        sp->st_mode = S_IFSOCK;
     694        return 0;
     695}
     696
     697static const rtems_filesystem_file_handlers_r socket_handlers = {
    682698        NULL,                   /* open */
    683699        rtems_bsdnet_close,     /* close */
     
    686702        rtems_bsdnet_ioctl,     /* ioctl */
    687703        NULL,                   /* lseek */
     704        rtems_bsdnet_fstat,     /* fstat */
     705        NULL,                   /* fchmod */
     706        NULL,                   /* ftruncate */
     707        NULL,                   /* fpathconf */
     708        NULL,                   /* fsync */
     709        NULL,                   /* fdatasync */
    688710};
    689 
  • c/src/libnetworking/rtems/rtems_bsdnet_internal.h

    re069cdc3 r73f6236  
    175175int socket (int, int, int);
    176176int ioctl (int, unsigned long, ...);
    177 struct socket *rtems_bsdnet_fdToSocket (int fd);
    178 int rtems_bsdnet_makeFdForSocket (void *);
    179177
    180178/*
  • c/src/libnetworking/rtems/rtems_glue.c

    re069cdc3 r73f6236  
    7878                        sizeof rtems_bsdnet_config.name_server[0]];
    7979int rtems_bsdnet_nameserver_count;
    80 
    81 extern rtems_libio_handler_t rtems_bsdnet_io_handler;
    8280
    8381/*
     
    230228         */
    231229        networkDaemonTid = rtems_bsdnet_newproc ("ntwk", 4096, networkDaemon, NULL);
    232 
    233         /*
    234          * Register as an external I/O handler
    235          */
    236         rtems_register_libio_handler (LIBIO_FLAGS_HANDLER_SOCK,
    237                                                 &rtems_bsdnet_io_handler);
    238230
    239231        /*
  • c/src/libnetworking/rtems/rtems_select.c

    re069cdc3 r73f6236  
    4747
    4848static __inline int imin(int a, int b) { return (a < b ? a : b); }
     49struct socket *rtems_bsdnet_fdToSocket(int fd);
    4950
    5051static int
  • c/src/libnetworking/rtems/rtems_syscall.c

    re069cdc3 r73f6236  
    2525#include <net/if.h>
    2626#include <net/route.h>
     27
     28/*
     29 * Hooks to RTEMS I/O system
     30 */
     31static const rtems_filesystem_file_handlers_r socket_handlers;
     32int rtems_bsdnet_makeFdForSocket(void *so, const rtems_filesystem_file_handlers_r *h);
     33struct socket *rtems_bsdnet_fdToSocket(int fd);
    2734
    2835/*
     
    6572        error = socreate(domain, &so, type, protocol, NULL);
    6673        if (error == 0) {
    67                 fd = rtems_bsdnet_makeFdForSocket (so);
     74                fd = rtems_bsdnet_makeFdForSocket (so, &socket_handlers);
    6875                if (fd < 0)
    6976                        soclose (so);
     
    214221        head->so_qlen--;
    215222
    216         fd = rtems_bsdnet_makeFdForSocket (so);
     223        fd = rtems_bsdnet_makeFdForSocket (so, &socket_handlers);
    217224        if (fd < 0) {
    218225                TAILQ_INSERT_HEAD(&head->so_comp, so, so_list);
     
    601608/*
    602609 ************************************************************************
    603  *                 RTEMS EXTERNAL I/O HANDLER ROUTINES                  *
     610 *                      RTEMS I/O HANDLER ROUTINES                      *
    604611 ************************************************************************
    605612 */
    606613static int
    607 rtems_bsdnet_close (int fd)
    608 {
    609         struct socket *so;
    610         int error;
    611 
    612         rtems_bsdnet_semaphore_obtain ();
    613         if ((so = rtems_bsdnet_fdToSocket (fd)) == NULL) {
     614rtems_bsdnet_close (rtems_libio_t *iop)
     615{
     616        struct socket *so;
     617        int error;
     618
     619        rtems_bsdnet_semaphore_obtain ();
     620        if ((so = iop->data1) == NULL) {
     621                errno = EBADF;
    614622                rtems_bsdnet_semaphore_release ();
    615623                return -1;
     
    625633
    626634static int
    627 rtems_bsdnet_read (int fd, void *buffer, unsigned32 count)
    628 {
    629         return recv (fd, buffer, count, 0);
     635rtems_bsdnet_read (rtems_libio_t *iop, void *buffer, unsigned32 count)
     636{
     637        return recv (iop->data0, buffer, count, 0);
    630638}
    631639
    632640static int
    633 rtems_bsdnet_write (int fd, const void *buffer, unsigned32 count)
    634 {
    635         return send (fd, buffer, count, 0);
     641rtems_bsdnet_write (rtems_libio_t *iop, const void *buffer, unsigned32 count)
     642{
     643        return send (iop->data0, buffer, count, 0);
    636644}
    637645
     
    660668
    661669static int
    662 rtems_bsdnet_ioctl (int fd, unsigned32 command, void *buffer)
    663 {
    664         struct socket *so;
    665         int error;
    666 
    667         rtems_bsdnet_semaphore_obtain ();
    668         if ((so = rtems_bsdnet_fdToSocket (fd)) == NULL) {
     670rtems_bsdnet_ioctl (rtems_libio_t *iop, unsigned32 command, void *buffer)
     671{
     672        struct socket *so;
     673        int error;
     674
     675        rtems_bsdnet_semaphore_obtain ();
     676        if ((so = iop->data1) == NULL) {
     677                errno = EBADF;
    669678                rtems_bsdnet_semaphore_release ();
    670679                return -1;
     
    679688}
    680689
    681 rtems_libio_handler_t rtems_bsdnet_io_handler = {
     690static int
     691rtems_bsdnet_fstat (rtems_filesystem_location_info_t *loc, struct stat *sp)
     692{
     693        sp->st_mode = S_IFSOCK;
     694        return 0;
     695}
     696
     697static const rtems_filesystem_file_handlers_r socket_handlers = {
    682698        NULL,                   /* open */
    683699        rtems_bsdnet_close,     /* close */
     
    686702        rtems_bsdnet_ioctl,     /* ioctl */
    687703        NULL,                   /* lseek */
     704        rtems_bsdnet_fstat,     /* fstat */
     705        NULL,                   /* fchmod */
     706        NULL,                   /* ftruncate */
     707        NULL,                   /* fpathconf */
     708        NULL,                   /* fsync */
     709        NULL,                   /* fdatasync */
    688710};
    689 
  • cpukit/include/rtems/libio_.h

    re069cdc3 r73f6236  
    6767extern rtems_libio_t  *rtems_libio_last_iop;
    6868extern rtems_libio_t *rtems_libio_iop_freelist;
    69 
    70 /*
    71  *  External I/O Handlers Table
    72  *
    73  *  Space for all possible handlers is preallocated
    74  *  to speed up dispatch to external handlers.
    75  */
    76 
    77 extern rtems_libio_handler_t   rtems_libio_handlers[15];
    7869
    7970/*
  • cpukit/libcsupport/include/rtems/libio.h

    re069cdc3 r73f6236  
    398398#define LIBIO_FLAGS_CREATE        0x0400  /* create file */
    399399#define LIBIO_FLAGS_CLOSE_ON_EXEC 0x0800  /* close on process exec() */
    400 
    401 #define LIBIO_FLAGS_HANDLER_SHIFT 12
    402 #define LIBIO_FLAGS_HANDLER_MASK  0xF000  /* mask for external handler type */
    403 #define LIBIO_FLAGS_HANDLER_RTEMS 0x0000  /* `traditional' RTEMS I/O */
    404 #define LIBIO_FLAGS_HANDLER_SOCK  0x1000  /* BSD socket */
    405 
    406400#define LIBIO_FLAGS_READ_WRITE    (LIBIO_FLAGS_READ | LIBIO_FLAGS_WRITE)
    407 
    408401
    409402void rtems_libio_init(void);
     
    446439  int    whence
    447440);
    448 
    449 typedef struct {
    450     rtems_libio_open_t   open;
    451     rtems_libio_close_t  close;
    452     rtems_libio_read_t   read;
    453     rtems_libio_write_t  write;
    454     rtems_libio_ioctl_t  ioctl;
    455     rtems_libio_lseek_t  lseek;
    456 } rtems_libio_handler_t;
    457 
    458 /*
    459  *  Register a set of external handlers
    460  */
    461 
    462 void rtems_register_libio_handler(
    463   int                          handler_flag,
    464   const rtems_libio_handler_t *handler
    465 );
    466 
    467 /*
    468  *  Macros to assist in management of external IO handlers.
    469  */
    470 
    471 #define RTEMS_FILE_DESCRIPTOR_TYPE_FILE         0x0000
    472 #define RTEMS_FILE_DESCRIPTOR_TYPE_SOCKET       0x1000
    473 #define rtems_make_file_descriptor(fd,flags)    ((fd)|(flags))
    474 #define rtems_file_descriptor_base(fd)          ((fd) & 0x0FFF)
    475 #define rtems_file_descriptor_type(fd)          ((fd) & 0xF000)
    476 #define rtems_file_descriptor_type_index(fd)    ((((fd) & 0xF000) >> 12) - 1)
    477441
    478442/*
  • cpukit/libcsupport/include/rtems/libio_.h

    re069cdc3 r73f6236  
    6767extern rtems_libio_t  *rtems_libio_last_iop;
    6868extern rtems_libio_t *rtems_libio_iop_freelist;
    69 
    70 /*
    71  *  External I/O Handlers Table
    72  *
    73  *  Space for all possible handlers is preallocated
    74  *  to speed up dispatch to external handlers.
    75  */
    76 
    77 extern rtems_libio_handler_t   rtems_libio_handlers[15];
    7869
    7970/*
  • cpukit/libcsupport/src/close.c

    re069cdc3 r73f6236  
    2121  rtems_libio_t      *iop;
    2222  rtems_status_code   rc;
    23   int                 status;
    2423
    2524  rtems_libio_check_fd(fd);
    2625  iop = rtems_libio_iop(fd);
    2726  rtems_libio_check_is_open(iop);
    28   if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) {
    29     int (*fp)(int  fd);
    3027
    31     fp = rtems_libio_handlers[
    32             (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].close;
    33     if ( fp == NULL )
    34       set_errno_and_return_minus_one( EBADF );
    35     status = (*fp)( fd );
    36     return status;
    37   }
    38 
    39   if ( !iop->handlers )
    40     set_errno_and_return_minus_one( EBADF );
    41 
    42   if ( !iop->handlers->close )
    43     set_errno_and_return_minus_one( ENOTSUP );
    44 
    45   rc = (*iop->handlers->close)( iop );
     28  rc = RTEMS_SUCCESSFUL;
     29  if ( iop->handlers->close )
     30    rc = (*iop->handlers->close)( iop );
    4631
    4732  rtems_libio_free( iop );
    48 
    49   if (rc != RTEMS_SUCCESSFUL)
    50     set_errno_and_return_minus_one( rc );
    5133
    5234  return rc;
  • cpukit/libcsupport/src/fchmod.c

    re069cdc3 r73f6236  
    3333
    3434  /*
    35    *  If this is not a file system based entity, it is an error.
    36    */
    37 
    38   if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK )
    39     set_errno_and_return_minus_one( EBADF );
    40 
    41   /*
    4235   *  Now process the fchmod().
    4336   */
  • cpukit/libcsupport/src/fcntl.c

    re069cdc3 r73f6236  
    3636  iop = rtems_libio_iop( fd );
    3737  rtems_libio_check_is_open(iop);
    38 
    39   /*
    40    *  If this is not a file system based entity, it is an error.
    41    */
    42 
    43   if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK )
    44     set_errno_and_return_minus_one( EBADF );
    4538
    4639  /*
  • cpukit/libcsupport/src/fdatasync.c

    re069cdc3 r73f6236  
    2929
    3030  /*
    31    *  If this file descriptor is mapped to an external set of handlers,
    32    *  then pass the request on to them.
    33    */
    34 
    35   if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK )
    36     set_errno_and_return_minus_one( EBADF );
    37 
    38   /*
    3931   *  Now process the fdatasync().
    4032   */
  • cpukit/libcsupport/src/fpathconf.c

    re069cdc3 r73f6236  
    3131  rtems_libio_check_is_open(iop);
    3232  rtems_libio_check_permissions(iop, LIBIO_FLAGS_READ);
    33 
    34   /*
    35    *  If this file descriptor is mapped to an external set of handlers,
    36    *  then it is an error since fpathconf() is not included in the
    37    *  set.
    38    */
    39 
    40   if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK )
    41     set_errno_and_return_minus_one( EBADF );
    4233
    4334  /*
  • cpukit/libcsupport/src/fstat.c

    re069cdc3 r73f6236  
    3434
    3535  /*
    36    *  Zero out the stat structure so the various support
    37    *  versions of stat don't have to.
    38    */
    39 
    40   memset( sbuf, 0, sizeof(struct stat) );
    41 
    42   /*
    43    *  If this file descriptor is mapped to an external set of handlers,
    44    *  then pass the request on to them.
    45    */
    46 
    47   if (rtems_file_descriptor_type(fd)) {
    48     switch (rtems_file_descriptor_type (fd)) {
    49       case RTEMS_FILE_DESCRIPTOR_TYPE_FILE:
    50         break;
    51 
    52       case RTEMS_FILE_DESCRIPTOR_TYPE_SOCKET:
    53 #if !defined(__GO32__)
    54         sbuf->st_mode = S_IFSOCK;
    55         break;
    56 #endif
    57 
    58       default:
    59         set_errno_and_return_minus_one( EBADF );
    60     }
    61   }
    62 
    63   /*
    6436   *  Now process the stat() request.
    6537   */
     
    6941  rtems_libio_check_is_open(iop);
    7042
     43  if ( !iop->handlers )
     44    set_errno_and_return_minus_one( EBADF );
     45
    7146  if ( !iop->handlers->fstat )
    7247    set_errno_and_return_minus_one( ENOTSUP );
     48
     49  /*
     50   *  Zero out the stat structure so the various support
     51   *  versions of stat don't have to.
     52   */
     53  memset( sbuf, 0, sizeof(struct stat) );
    7354
    7455  return (*iop->handlers->fstat)( &iop->pathinfo, sbuf );
  • cpukit/libcsupport/src/fsync.c

    re069cdc3 r73f6236  
    2929
    3030  /*
    31    *  If this file descriptor is mapped to an external set of handlers,
    32    *  then pass the request on to them.
    33    */
    34 
    35   if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK )
    36     set_errno_and_return_minus_one( EBADF );
    37 
    38   /*
    3931   *  Now process the fsync().
    4032   */
  • cpukit/libcsupport/src/ftruncate.c

    re069cdc3 r73f6236  
    3131
    3232  /*
    33    *  If this is not a file system based entity, it is an error.
    34    */
    35 
    36   if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK )
    37     set_errno_and_return_minus_one( EBADF );
    38 
    39   /*
    4033   *  Now process the ftruncate() request.
    4134   */
  • cpukit/libcsupport/src/ioctl.c

    re069cdc3 r73f6236  
    3232
    3333  /*
    34    *  If this file descriptor is mapped to an external set of handlers,
    35    *  then pass the request on to them.
    36    */
    37 
    38   if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) {
    39     rtems_libio_ioctl_t fp;
    40 
    41     fp = rtems_libio_handlers[
    42            (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].ioctl;
    43     if ( fp == NULL )
    44       set_errno_and_return_minus_one( EBADF );
    45 
    46     return (*fp)( fd, command, buffer );
    47   }
    48 
    49   /*
    5034   *  Now process the ioctl().
    5135   */
  • cpukit/libcsupport/src/libio.c

    re069cdc3 r73f6236  
    5151
    5252/*
    53  *  External I/O Handlers Table
    54  *
    55  *  Space for all possible handlers is preallocated
    56  *  to speed up dispatch to external handlers.
    57  */
    58 
    59 rtems_libio_handler_t   rtems_libio_handlers[15];
    60 
    61 /*
    6253 *  Default mode for all files.
    6354 */
    6455
    6556mode_t    rtems_filesystem_umask;
    66 
    67 /*
    68  *  rtems_register_libio_handler
    69  *
    70  *  This function registers an external IO handler set.  This lets
    71  *  other subsystems have their own versions of many of the system
    72  *  calls.  For example, the networking code registers handlers which
    73  *  map the system calls for read() and write() to socket calls.
    74  *
    75  */
    76 
    77 void rtems_register_libio_handler(
    78   int                          handler_flag,
    79   const rtems_libio_handler_t *handler
    80 )
    81 {
    82   int handler_index = (handler_flag >> LIBIO_FLAGS_HANDLER_SHIFT) - 1;
    83 
    84   if ((handler_index < 0) || (handler_index >= 15))
    85     rtems_fatal_error_occurred( RTEMS_INVALID_NUMBER );
    86 
    87   rtems_libio_handlers[handler_index] = *handler;
    88 }
    8957
    9058/*
  • cpukit/libcsupport/src/libio_sockets.c

    re069cdc3 r73f6236  
    1919#include <errno.h>
    2020
    21 
    2221/*
    2322 * Convert an RTEMS file descriptor to a BSD socket pointer.
     
    3029  rtems_libio_t *iop;
    3130
    32   if ((unsigned32)fd >= rtems_libio_number_iops)
    33       return NULL;
     31  if ((unsigned32)fd >= rtems_libio_number_iops) {
     32    errno = EBADF;
     33    return NULL;
     34  }
    3435  iop = &rtems_libio_iops[fd];
    35   if ((iop->flags & LIBIO_FLAGS_HANDLER_MASK) != LIBIO_FLAGS_HANDLER_SOCK)
    36       return NULL;
     36  if (iop->data1 == NULL)
     37    errno = EBADF;
    3738  return iop->data1;
    3839}
     
    4344
    4445int rtems_bsdnet_makeFdForSocket(
    45   void *so
     46  void *so,
     47  const rtems_filesystem_file_handlers_r *h
    4648)
    4749{
    4850  rtems_libio_t *iop;
     51  int fd;
    4952
    5053  iop = rtems_libio_allocate();
     
    5356      return -1;
    5457  }
    55   iop->flags |= LIBIO_FLAGS_HANDLER_SOCK | LIBIO_FLAGS_WRITE | LIBIO_FLAGS_READ;
     58  fd = iop - rtems_libio_iops;
     59  iop->flags |= LIBIO_FLAGS_WRITE | LIBIO_FLAGS_READ;
     60  iop->data0 = fd;
    5661  iop->data1 = so;
    57   return iop - rtems_libio_iops;
     62  iop->handlers = h;
     63  return fd;
    5864}
  • cpukit/libcsupport/src/lseek.c

    re069cdc3 r73f6236  
    2828  iop = rtems_libio_iop( fd );
    2929  rtems_libio_check_is_open(iop);
    30 
    31   /*
    32    *  If this file descriptor is mapped to an external set of handlers,
    33    *  then pass the request on to them.
    34    */
    35 
    36   if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) {
    37     rtems_libio_lseek_t fp;
    38 
    39     fp = rtems_libio_handlers[
    40            (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].lseek;
    41     if ( fp == NULL )
    42       set_errno_and_return_minus_one( EBADF );
    43 
    44     return (*fp)( fd, offset, whence );
    45   }
    4630
    4731  /*
  • cpukit/libcsupport/src/read.c

    re069cdc3 r73f6236  
    3030  rtems_libio_check_count( count );
    3131  rtems_libio_check_permissions( iop, LIBIO_FLAGS_READ );
    32 
    33   /*
    34    *  If this file descriptor is mapped to an external set of handlers,
    35    *  then pass the request on to them.
    36    */
    37 
    38   if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) {
    39     rtems_libio_read_t fp;
    40 
    41     fp = rtems_libio_handlers[
    42            (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].read;
    43     if ( fp == NULL )
    44       set_errno_and_return_minus_one( EBADF );
    45 
    46     return (*fp)( fd, buffer, count );
    47   }
    4832
    4933  /*
  • cpukit/libcsupport/src/write.c

    re069cdc3 r73f6236  
    4040
    4141  /*
    42    *  If this file descriptor is mapped to an external set of handlers,
    43    *  then pass the request on to them.
    44    */
    45 
    46   if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK ) {
    47     rtems_libio_write_t fp;
    48 
    49     fp = rtems_libio_handlers[
    50            (iop->flags >> LIBIO_FLAGS_HANDLER_SHIFT) - 1].write;
    51     if ( fp == NULL )
    52       set_errno_and_return_minus_one( EBADF );
    53 
    54     return (*fp)( fd, buffer, count );
    55   }
    56 
    57   /*
    5842   *  Now process the write() request.
    5943   */
  • cpukit/libnetworking/rtems/rtems_bsdnet_internal.h

    re069cdc3 r73f6236  
    175175int socket (int, int, int);
    176176int ioctl (int, unsigned long, ...);
    177 struct socket *rtems_bsdnet_fdToSocket (int fd);
    178 int rtems_bsdnet_makeFdForSocket (void *);
    179177
    180178/*
  • cpukit/libnetworking/rtems/rtems_glue.c

    re069cdc3 r73f6236  
    7878                        sizeof rtems_bsdnet_config.name_server[0]];
    7979int rtems_bsdnet_nameserver_count;
    80 
    81 extern rtems_libio_handler_t rtems_bsdnet_io_handler;
    8280
    8381/*
     
    230228         */
    231229        networkDaemonTid = rtems_bsdnet_newproc ("ntwk", 4096, networkDaemon, NULL);
    232 
    233         /*
    234          * Register as an external I/O handler
    235          */
    236         rtems_register_libio_handler (LIBIO_FLAGS_HANDLER_SOCK,
    237                                                 &rtems_bsdnet_io_handler);
    238230
    239231        /*
  • cpukit/libnetworking/rtems/rtems_select.c

    re069cdc3 r73f6236  
    4747
    4848static __inline int imin(int a, int b) { return (a < b ? a : b); }
     49struct socket *rtems_bsdnet_fdToSocket(int fd);
    4950
    5051static int
  • cpukit/libnetworking/rtems/rtems_syscall.c

    re069cdc3 r73f6236  
    2525#include <net/if.h>
    2626#include <net/route.h>
     27
     28/*
     29 * Hooks to RTEMS I/O system
     30 */
     31static const rtems_filesystem_file_handlers_r socket_handlers;
     32int rtems_bsdnet_makeFdForSocket(void *so, const rtems_filesystem_file_handlers_r *h);
     33struct socket *rtems_bsdnet_fdToSocket(int fd);
    2734
    2835/*
     
    6572        error = socreate(domain, &so, type, protocol, NULL);
    6673        if (error == 0) {
    67                 fd = rtems_bsdnet_makeFdForSocket (so);
     74                fd = rtems_bsdnet_makeFdForSocket (so, &socket_handlers);
    6875                if (fd < 0)
    6976                        soclose (so);
     
    214221        head->so_qlen--;
    215222
    216         fd = rtems_bsdnet_makeFdForSocket (so);
     223        fd = rtems_bsdnet_makeFdForSocket (so, &socket_handlers);
    217224        if (fd < 0) {
    218225                TAILQ_INSERT_HEAD(&head->so_comp, so, so_list);
     
    601608/*
    602609 ************************************************************************
    603  *                 RTEMS EXTERNAL I/O HANDLER ROUTINES                  *
     610 *                      RTEMS I/O HANDLER ROUTINES                      *
    604611 ************************************************************************
    605612 */
    606613static int
    607 rtems_bsdnet_close (int fd)
    608 {
    609         struct socket *so;
    610         int error;
    611 
    612         rtems_bsdnet_semaphore_obtain ();
    613         if ((so = rtems_bsdnet_fdToSocket (fd)) == NULL) {
     614rtems_bsdnet_close (rtems_libio_t *iop)
     615{
     616        struct socket *so;
     617        int error;
     618
     619        rtems_bsdnet_semaphore_obtain ();
     620        if ((so = iop->data1) == NULL) {
     621                errno = EBADF;
    614622                rtems_bsdnet_semaphore_release ();
    615623                return -1;
     
    625633
    626634static int
    627 rtems_bsdnet_read (int fd, void *buffer, unsigned32 count)
    628 {
    629         return recv (fd, buffer, count, 0);
     635rtems_bsdnet_read (rtems_libio_t *iop, void *buffer, unsigned32 count)
     636{
     637        return recv (iop->data0, buffer, count, 0);
    630638}
    631639
    632640static int
    633 rtems_bsdnet_write (int fd, const void *buffer, unsigned32 count)
    634 {
    635         return send (fd, buffer, count, 0);
     641rtems_bsdnet_write (rtems_libio_t *iop, const void *buffer, unsigned32 count)
     642{
     643        return send (iop->data0, buffer, count, 0);
    636644}
    637645
     
    660668
    661669static int
    662 rtems_bsdnet_ioctl (int fd, unsigned32 command, void *buffer)
    663 {
    664         struct socket *so;
    665         int error;
    666 
    667         rtems_bsdnet_semaphore_obtain ();
    668         if ((so = rtems_bsdnet_fdToSocket (fd)) == NULL) {
     670rtems_bsdnet_ioctl (rtems_libio_t *iop, unsigned32 command, void *buffer)
     671{
     672        struct socket *so;
     673        int error;
     674
     675        rtems_bsdnet_semaphore_obtain ();
     676        if ((so = iop->data1) == NULL) {
     677                errno = EBADF;
    669678                rtems_bsdnet_semaphore_release ();
    670679                return -1;
     
    679688}
    680689
    681 rtems_libio_handler_t rtems_bsdnet_io_handler = {
     690static int
     691rtems_bsdnet_fstat (rtems_filesystem_location_info_t *loc, struct stat *sp)
     692{
     693        sp->st_mode = S_IFSOCK;
     694        return 0;
     695}
     696
     697static const rtems_filesystem_file_handlers_r socket_handlers = {
    682698        NULL,                   /* open */
    683699        rtems_bsdnet_close,     /* close */
     
    686702        rtems_bsdnet_ioctl,     /* ioctl */
    687703        NULL,                   /* lseek */
     704        rtems_bsdnet_fstat,     /* fstat */
     705        NULL,                   /* fchmod */
     706        NULL,                   /* ftruncate */
     707        NULL,                   /* fpathconf */
     708        NULL,                   /* fsync */
     709        NULL,                   /* fdatasync */
    688710};
    689 
Note: See TracChangeset for help on using the changeset viewer.