[PATCH 09/18] libio: Add iop set/clear flags

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


Update #3132.
---
 cpukit/libcsupport/include/rtems/libio_.h  | 40 ++++++++++++++++++++++++++++++
 cpukit/libcsupport/src/close.c             |  2 +-
 cpukit/libcsupport/src/fcntl.c             | 11 ++++----
 cpukit/libcsupport/src/open.c              |  2 +-
 cpukit/libfs/src/imfs/imfs_fifo.c          |  4 +--
 cpukit/libfs/src/pipe/fifo.c               |  2 +-
 cpukit/libfs/src/pipe/pipe.c               |  2 +-
 cpukit/libnetworking/rtems/rtems_syscall.c |  2 +-
 cpukit/posix/src/shmopen.c                 |  6 ++---
 9 files changed, 56 insertions(+), 15 deletions(-)

diff --git a/cpukit/libcsupport/include/rtems/libio_.h b/cpukit/libcsupport/include/rtems/libio_.h
index ba6866e5a4..ed5cd27c31 100644
--- a/cpukit/libcsupport/include/rtems/libio_.h
+++ b/cpukit/libcsupport/include/rtems/libio_.h
@@ -90,6 +90,46 @@ extern rtems_filesystem_mount_table_entry_t rtems_filesystem_null_mt_entry;
 extern rtems_filesystem_global_location_t rtems_filesystem_global_location_null;
 
 /**
+ * @brief Sets the specified flags in the iop.
+ *
+ * @param[in] iop The iop.
+ * @param[in] set The flags to set.
+ *
+ * @return The previous flags.
+ */
+static inline uint32_t rtems_libio_iop_flags_set(
+  rtems_libio_t *iop,
+  uint32_t       set
+)
+{
+  uint32_t flags;
+
+  flags = iop->flags;
+  iop->flags = flags | set;
+  return flags;
+}
+
+/**
+ * @brief Clears the specified flags in the iop.
+ *
+ * @param[in] iop The iop.
+ * @param[in] clear The flags to clear.
+ *
+ * @return The previous flags.
+ */
+static inline uint32_t rtems_libio_iop_flags_clear(
+  rtems_libio_t *iop,
+  uint32_t       clear
+)
+{
+  uint32_t flags;
+
+  flags = iop->flags;
+  iop->flags = flags & ~clear;
+  return flags;
+}
+
+/**
  * @brief Maps a file descriptor to the iop.
  *
  * The file descriptor must be a valid index into the iop table.
diff --git a/cpukit/libcsupport/src/close.c b/cpukit/libcsupport/src/close.c
index 139ffd266a..649107dff0 100644
--- a/cpukit/libcsupport/src/close.c
+++ b/cpukit/libcsupport/src/close.c
@@ -31,7 +31,7 @@ int close(
   iop = rtems_libio_iop(fd);
   rtems_libio_check_is_open(iop);
 
-  iop->flags &= ~LIBIO_FLAGS_OPEN;
+  rtems_libio_iop_flags_clear( iop, LIBIO_FLAGS_OPEN );
 
   rc = (*iop->pathinfo.handlers->close_h)( iop );
 
diff --git a/cpukit/libcsupport/src/fcntl.c b/cpukit/libcsupport/src/fcntl.c
index e7a9868980..0fe734d61c 100644
--- a/cpukit/libcsupport/src/fcntl.c
+++ b/cpukit/libcsupport/src/fcntl.c
@@ -33,7 +33,7 @@ static int duplicate_iop( rtems_libio_t *iop )
   if (diop != NULL) {
     int oflag = rtems_libio_to_fcntl_flags( iop->flags );
 
-    diop->flags |= rtems_libio_fcntl_flags( oflag );
+    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 );
@@ -75,7 +75,7 @@ static int duplicate2_iop( rtems_libio_t *iop, int fd2 )
 
     if (rv == 0) {
       oflag = rtems_libio_to_fcntl_flags( iop->flags );
-      iop2->flags |= rtems_libio_fcntl_flags( oflag );
+      rtems_libio_iop_flags_set( iop2, rtems_libio_fcntl_flags( oflag ) );
 
       rtems_filesystem_instance_lock( &iop->pathinfo );
       rtems_filesystem_location_clone( &iop2->pathinfo, &iop->pathinfo );
@@ -145,9 +145,9 @@ static int vfcntl(
        */
 
       if ( va_arg( ap, int ) )
-        iop->flags |= LIBIO_FLAGS_CLOSE_ON_EXEC;
+        rtems_libio_iop_flags_set( iop, LIBIO_FLAGS_CLOSE_ON_EXEC );
       else
-        iop->flags &= ~LIBIO_FLAGS_CLOSE_ON_EXEC;
+        rtems_libio_iop_flags_clear( iop, LIBIO_FLAGS_CLOSE_ON_EXEC );
       break;
 
     case F_GETFL:        /* more flags (cloexec) */
@@ -162,7 +162,8 @@ static int vfcntl(
        *  XXX If we are turning on append, should we seek to the end?
        */
 
-      iop->flags = (iop->flags & ~mask) | (flags & mask);
+      rtems_libio_iop_flags_clear( iop, mask );
+      rtems_libio_iop_flags_set( iop, flags & mask );
       break;
 
     case F_GETLK:
diff --git a/cpukit/libcsupport/src/open.c b/cpukit/libcsupport/src/open.c
index 62ce507284..2ee99f1f4c 100644
--- a/cpukit/libcsupport/src/open.c
+++ b/cpukit/libcsupport/src/open.c
@@ -96,7 +96,7 @@ static int do_open(
     }
   }
 
-  iop->flags |= rtems_libio_fcntl_flags( oflag );
+  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 );
 
diff --git a/cpukit/libfs/src/imfs/imfs_fifo.c b/cpukit/libfs/src/imfs/imfs_fifo.c
index b97694e38a..d972b8b051 100644
--- a/cpukit/libfs/src/imfs/imfs_fifo.c
+++ b/cpukit/libfs/src/imfs/imfs_fifo.c
@@ -102,9 +102,9 @@ static int IMFS_fifo_ioctl(
       err = -EFAULT;
     else {
       if (*(int *)buffer)
-        iop->flags |= LIBIO_FLAGS_NO_DELAY;
+        rtems_libio_iop_flags_set( iop, LIBIO_FLAGS_NO_DELAY );
       else
-        iop->flags &= ~LIBIO_FLAGS_NO_DELAY;
+        rtems_libio_iop_flags_clear( iop, LIBIO_FLAGS_NO_DELAY );
       return 0;
     }
   }
diff --git a/cpukit/libfs/src/pipe/fifo.c b/cpukit/libfs/src/pipe/fifo.c
index 49694d9953..15fb0d58eb 100644
--- a/cpukit/libfs/src/pipe/fifo.c
+++ b/cpukit/libfs/src/pipe/fifo.c
@@ -265,7 +265,7 @@ void pipe_release(
     return;
 
   /* This is safe for IMFS, but how about other FSes? */
-  iop->flags &= ~LIBIO_FLAGS_OPEN;
+  rtems_libio_iop_flags_clear( iop, LIBIO_FLAGS_OPEN );
   if(iop->pathinfo.ops->unlink_h(&iop->pathinfo))
     return;
 #endif
diff --git a/cpukit/libfs/src/pipe/pipe.c b/cpukit/libfs/src/pipe/pipe.c
index e46e8f58e7..8693bd489e 100644
--- a/cpukit/libfs/src/pipe/pipe.c
+++ b/cpukit/libfs/src/pipe/pipe.c
@@ -64,7 +64,7 @@ int pipe_create(
   else {
   /* Reset open file to blocking mode */
     iop = rtems_libio_iop(filsdes[0]);
-    iop->flags &= ~LIBIO_FLAGS_NO_DELAY;
+    rtems_libio_iop_flags_clear( iop, LIBIO_FLAGS_NO_DELAY );
 
     filsdes[1] = open(fifopath, O_WRONLY);
 
diff --git a/cpukit/libnetworking/rtems/rtems_syscall.c b/cpukit/libnetworking/rtems/rtems_syscall.c
index 9d9b64c423..a5418e7aaf 100644
--- a/cpukit/libnetworking/rtems/rtems_syscall.c
+++ b/cpukit/libnetworking/rtems/rtems_syscall.c
@@ -81,7 +81,7 @@ rtems_bsdnet_makeFdForSocket (void *so)
       rtems_set_errno_and_return_minus_one( ENFILE );
 
   fd = rtems_libio_iop_to_descriptor(iop);
-  iop->flags |= LIBIO_FLAGS_WRITE | LIBIO_FLAGS_READ;
+  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 e729f9bd4e..e00869e30d 100644
--- a/cpukit/posix/src/shmopen.c
+++ b/cpukit/posix/src/shmopen.c
@@ -275,11 +275,11 @@ int shm_open( const char *name, int oflag, mode_t mode )
   }
 
   fd = rtems_libio_iop_to_descriptor( iop );
-  iop->flags |= LIBIO_FLAGS_CLOSE_ON_EXEC;
+  rtems_libio_iop_flags_set( iop, LIBIO_FLAGS_CLOSE_ON_EXEC );
   if ( oflag & O_RDONLY ) {
-    iop->flags |= LIBIO_FLAGS_READ;
+    rtems_libio_iop_flags_set( iop, LIBIO_FLAGS_READ );
   } else {
-    iop->flags |= LIBIO_FLAGS_READ_WRITE;
+    rtems_libio_iop_flags_set( iop, LIBIO_FLAGS_READ_WRITE );
   }
   iop->data0 = fd;
   iop->data1 = shm;
-- 
2.12.3




More information about the devel mailing list