[PATCH 10/18] libio: Add flags to rtems_libio_allocate()

Sebastian Huber sebastian.huber at embedded-brains.de
Wed Sep 13 13:39:43 UTC 2017


Update #3082.
---
 cpukit/libcsupport/include/rtems/libio_.h  |  2 +-
 cpukit/libcsupport/src/fcntl.c             | 11 +++++------
 cpukit/libcsupport/src/libio.c             |  4 ++--
 cpukit/libcsupport/src/open.c              |  3 +--
 cpukit/libnetworking/rtems/rtems_syscall.c |  3 +--
 cpukit/posix/src/shmopen.c                 | 16 +++++++++-------
 6 files changed, 19 insertions(+), 20 deletions(-)

diff --git a/cpukit/libcsupport/include/rtems/libio_.h b/cpukit/libcsupport/include/rtems/libio_.h
index ed5cd27c31..d9ba176ef0 100644
--- a/cpukit/libcsupport/include/rtems/libio_.h
+++ b/cpukit/libcsupport/include/rtems/libio_.h
@@ -320,7 +320,7 @@ static inline void rtems_filesystem_instance_unlock(
  * This routine searches the IOP Table for an unused entry.  If it
  * finds one, it returns it.  Otherwise, it returns NULL.
  */
-rtems_libio_t *rtems_libio_allocate(void);
+rtems_libio_t *rtems_libio_allocate(uint32_t flags);
 
 /**
  * Convert UNIX fnctl(2) flags to ones that RTEMS drivers understand
diff --git a/cpukit/libcsupport/src/fcntl.c b/cpukit/libcsupport/src/fcntl.c
index 0fe734d61c..7dc2c8110f 100644
--- a/cpukit/libcsupport/src/fcntl.c
+++ b/cpukit/libcsupport/src/fcntl.c
@@ -26,15 +26,14 @@
 
 static int duplicate_iop( rtems_libio_t *iop )
 {
-  int rv = 0;
+  int            rv;
+  int            oflag;
+  rtems_libio_t *diop;
 
-  rtems_libio_t *diop = rtems_libio_allocate();
+  oflag = rtems_libio_to_fcntl_flags( iop->flags );
+  diop = rtems_libio_allocate( rtems_libio_fcntl_flags( oflag ) );
 
   if (diop != NULL) {
-    int oflag = rtems_libio_to_fcntl_flags( iop->flags );
-
-    rtems_libio_iop_flags_set( diop, rtems_libio_fcntl_flags( oflag ) );
-
     rtems_filesystem_instance_lock( &iop->pathinfo );
     rtems_filesystem_location_clone( &diop->pathinfo, &iop->pathinfo );
     rtems_filesystem_instance_unlock( &iop->pathinfo );
diff --git a/cpukit/libcsupport/src/libio.c b/cpukit/libcsupport/src/libio.c
index cd3a4420f6..ab8779aa12 100644
--- a/cpukit/libcsupport/src/libio.c
+++ b/cpukit/libcsupport/src/libio.c
@@ -106,7 +106,7 @@ int rtems_libio_to_fcntl_flags( uint32_t flags )
   return fcntl_flags;
 }
 
-rtems_libio_t *rtems_libio_allocate( void )
+rtems_libio_t *rtems_libio_allocate( uint32_t flags )
 {
   rtems_libio_t *iop = NULL;
 
@@ -116,7 +116,7 @@ rtems_libio_t *rtems_libio_allocate( void )
     iop = rtems_libio_iop_freelist;
     rtems_libio_iop_freelist = iop->data1;
     memset( iop, 0, sizeof(*iop) );
-    iop->flags = LIBIO_FLAGS_OPEN;
+    iop->flags = LIBIO_FLAGS_OPEN | flags;
   }
 
   rtems_libio_unlock();
diff --git a/cpukit/libcsupport/src/open.c b/cpukit/libcsupport/src/open.c
index 2ee99f1f4c..d6b2341a2f 100644
--- a/cpukit/libcsupport/src/open.c
+++ b/cpukit/libcsupport/src/open.c
@@ -96,7 +96,6 @@ static int do_open(
     }
   }
 
-  rtems_libio_iop_flags_set( iop, rtems_libio_fcntl_flags( oflag ) );
   rtems_filesystem_eval_path_extract_currentloc( &ctx, &iop->pathinfo );
   rtems_filesystem_eval_path_cleanup( &ctx );
 
@@ -138,7 +137,7 @@ int open( const char *path, int oflag, ... )
 
   mode = va_arg( ap, mode_t );
 
-  iop = rtems_libio_allocate();
+  iop = rtems_libio_allocate( rtems_libio_fcntl_flags( oflag ) );
   if ( iop != NULL ) {
     rv = do_open( iop, path, oflag, mode );
   } else {
diff --git a/cpukit/libnetworking/rtems/rtems_syscall.c b/cpukit/libnetworking/rtems/rtems_syscall.c
index a5418e7aaf..dc4ee7a63c 100644
--- a/cpukit/libnetworking/rtems/rtems_syscall.c
+++ b/cpukit/libnetworking/rtems/rtems_syscall.c
@@ -76,12 +76,11 @@ rtems_bsdnet_makeFdForSocket (void *so)
   rtems_libio_t *iop;
   int fd;
 
-  iop = rtems_libio_allocate();
+  iop = rtems_libio_allocate(LIBIO_FLAGS_READ_WRITE);
   if (iop == 0)
       rtems_set_errno_and_return_minus_one( ENFILE );
 
   fd = rtems_libio_iop_to_descriptor(iop);
-  rtems_libio_iop_flags_set(iop, LIBIO_FLAGS_READ_WRITE);
   iop->data0 = fd;
   iop->data1 = so;
   iop->pathinfo.handlers = &socket_handlers;
diff --git a/cpukit/posix/src/shmopen.c b/cpukit/posix/src/shmopen.c
index e00869e30d..3776e7a95b 100644
--- a/cpukit/posix/src/shmopen.c
+++ b/cpukit/posix/src/shmopen.c
@@ -225,12 +225,20 @@ int shm_open( const char *name, int oflag, mode_t mode )
   POSIX_Shm_Control *shm;
   size_t len;
   Objects_Get_by_name_error obj_err;
+  uint32_t flags;
 
   if ( shm_check_oflag( oflag ) != 0 ) {
     return -1;
   }
 
-  iop = rtems_libio_allocate();
+  flags = LIBIO_FLAGS_CLOSE_ON_EXEC;
+  if ( oflag & O_RDONLY ) {
+    flags |= LIBIO_FLAGS_READ;
+  } else {
+    flags |= LIBIO_FLAGS_READ_WRITE;
+  }
+
+  iop = rtems_libio_allocate( flags );
   if ( iop == NULL ) {
     rtems_set_errno_and_return_minus_one( EMFILE );
   }
@@ -275,12 +283,6 @@ int shm_open( const char *name, int oflag, mode_t mode )
   }
 
   fd = rtems_libio_iop_to_descriptor( iop );
-  rtems_libio_iop_flags_set( iop, LIBIO_FLAGS_CLOSE_ON_EXEC );
-  if ( oflag & O_RDONLY ) {
-    rtems_libio_iop_flags_set( iop, LIBIO_FLAGS_READ );
-  } else {
-    rtems_libio_iop_flags_set( iop, LIBIO_FLAGS_READ_WRITE );
-  }
   iop->data0 = fd;
   iop->data1 = shm;
   iop->pathinfo.node_access = shm;
-- 
2.12.3



More information about the devel mailing list