Index: cpukit/ChangeLog
===================================================================
--- cpukit/ChangeLog	(revision 5b5772ae313eb2dd8d211749bc2eb3fea63758f8)
+++ cpukit/ChangeLog	(revision 241f4c96378ff3ca0ad811290c1dac49b571d1cc)
@@ -1,2 +1,13 @@
+2010-06-08	Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+	* libfs/src/imfs/fifoimfs_init.c: New file.
+	* libfs/Makefile.am: Reflect change above.
+	* libfs/src/imfs/imfs.h, libfs/src/imfs/imfs_eval.c,
+	libfs/src/imfs/imfs_init.c, libfs/src/imfs/imfs_initsupp.c,
+	libfs/src/imfs/miniimfs_init.c, libfs/src/pipe/fifo.c,
+	libfs/src/pipe/pipe.c, libfs/src/pipe/pipe.h: Pipe support is now
+	link-time optional.
+	* sapi/include/confdefs.h: Reflect changes above.
+
 2010-06-08	Sebastian Huber <sebastian.huber@embedded-brains.de>
 
Index: cpukit/libfs/Makefile.am
===================================================================
--- cpukit/libfs/Makefile.am	(revision 5b5772ae313eb2dd8d211749bc2eb3fea63758f8)
+++ cpukit/libfs/Makefile.am	(revision 241f4c96378ff3ca0ad811290c1dac49b571d1cc)
@@ -32,5 +32,5 @@
     src/imfs/imfs_readlink.c src/imfs/imfs_fdatasync.c src/imfs/imfs_fcntl.c \
     src/imfs/ioman.c src/imfs/miniimfs_init.c src/imfs/imfs_load_tar.c \
-    src/imfs/imfs_rename.c src/imfs/imfs.h \
+    src/imfs/imfs_rename.c src/imfs/fifoimfs_init.c src/imfs/imfs.h \
     src/imfs/deviceerrno.c \
     src/devfs/devfs_init.c src/devfs/devfs_eval.c src/devfs/devfs_mknod.c \
Index: cpukit/libfs/src/imfs/fifoimfs_init.c
===================================================================
--- cpukit/libfs/src/imfs/fifoimfs_init.c	(revision 241f4c96378ff3ca0ad811290c1dac49b571d1cc)
+++ cpukit/libfs/src/imfs/fifoimfs_init.c	(revision 241f4c96378ff3ca0ad811290c1dac49b571d1cc)
@@ -0,0 +1,61 @@
+/**
+ * @file
+ *
+ * @ingroup LibFSIMFS
+ *
+ * @brief IMFS without fifo support initialization.
+ */
+
+/*
+ * Copyright (c) 2010
+ * embedded brains GmbH
+ * Obere Lagerstr. 30
+ * D-82178 Puchheim
+ * Germany
+ * <rtems@embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "imfs.h"
+
+static const rtems_filesystem_operations_table fifoIMFS_ops = {
+  .evalpath_h = IMFS_eval_path,
+  .evalformake_h = IMFS_evaluate_for_make,
+  .link_h = IMFS_link,
+  .unlink_h = IMFS_unlink,
+  .node_type_h = IMFS_node_type,
+  .mknod_h = IMFS_mknod,
+  .chown_h = IMFS_chown,
+  .freenod_h = IMFS_freenodinfo,
+  .mount_h = IMFS_mount,
+  .fsmount_me_h = fifoIMFS_initialize,
+  .unmount_h = IMFS_unmount,
+  .fsunmount_me_h = IMFS_fsunmount,
+  .utime_h = IMFS_utime,
+  .eval_link_h = IMFS_evaluate_link,
+  .symlink_h = IMFS_symlink,
+  .readlink_h = IMFS_readlink,
+  .rename_h = IMFS_rename,
+  .statvfs_h = NULL
+};
+
+int fifoIMFS_initialize(
+  rtems_filesystem_mount_table_entry_t *mt_entry,
+  const void *data
+)
+{
+  return IMFS_initialize_support(
+    mt_entry,
+    &fifoIMFS_ops,
+    &IMFS_memfile_handlers,
+    &IMFS_directory_handlers,
+    &IMFS_fifo_handlers
+  );
+}
Index: cpukit/libfs/src/imfs/imfs.h
===================================================================
--- cpukit/libfs/src/imfs/imfs.h	(revision 5b5772ae313eb2dd8d211749bc2eb3fea63758f8)
+++ cpukit/libfs/src/imfs/imfs.h	(revision 241f4c96378ff3ca0ad811290c1dac49b571d1cc)
@@ -224,4 +224,5 @@
   const rtems_filesystem_file_handlers_r *memfile_handlers;
   const rtems_filesystem_file_handlers_r *directory_handlers;
+  const rtems_filesystem_file_handlers_r *fifo_handlers;
 } IMFS_fs_info_t;
 
@@ -248,5 +249,4 @@
 extern const rtems_filesystem_file_handlers_r       IMFS_fifo_handlers;
 extern const rtems_filesystem_operations_table      IMFS_ops;
-extern const rtems_filesystem_operations_table      miniIMFS_ops;
 extern const rtems_filesystem_limits_and_options_t  IMFS_LIMITS_AND_OPTIONS;
 
@@ -258,4 +258,9 @@
    rtems_filesystem_mount_table_entry_t *mt_entry,
    const void                           *data
+);
+
+extern int fifoIMFS_initialize(
+  rtems_filesystem_mount_table_entry_t  *mt_entry,
+  const void                            *data
 );
 
@@ -269,5 +274,6 @@
    const rtems_filesystem_operations_table    *op_table,
    const rtems_filesystem_file_handlers_r     *memfile_handlers,
-   const rtems_filesystem_file_handlers_r     *directory_handlers
+   const rtems_filesystem_file_handlers_r     *directory_handlers,
+   const rtems_filesystem_file_handlers_r     *fifo_handlers
 );
 
Index: cpukit/libfs/src/imfs/imfs_eval.c
===================================================================
--- cpukit/libfs/src/imfs/imfs_eval.c	(revision 5b5772ae313eb2dd8d211749bc2eb3fea63758f8)
+++ cpukit/libfs/src/imfs/imfs_eval.c	(revision 241f4c96378ff3ca0ad811290c1dac49b571d1cc)
@@ -59,5 +59,5 @@
       break;
     case IMFS_FIFO:
-      loc->handlers = &IMFS_fifo_handlers;
+      loc->handlers = fs_info->fifo_handlers;
       break;
   }
Index: cpukit/libfs/src/imfs/imfs_init.c
===================================================================
--- cpukit/libfs/src/imfs/imfs_init.c	(revision 5b5772ae313eb2dd8d211749bc2eb3fea63758f8)
+++ cpukit/libfs/src/imfs/imfs_init.c	(revision 241f4c96378ff3ca0ad811290c1dac49b571d1cc)
@@ -1,5 +1,11 @@
+/**
+ * @file
+ *
+ * @ingroup LibFSIMFS
+ *
+ * @brief IMFS initialization.
+ */
+
 /*
- *  IMFS Initialization
- *
  *  COPYRIGHT (c) 1989-1999.
  *  On-Line Applications Research Corporation (OAR).
@@ -16,57 +22,40 @@
 #endif
 
-#include <sys/types.h>         /* for mkdir */
-#include <fcntl.h>
-#include <unistd.h>
-#include <stdlib.h>
-
-#include <assert.h>
+#include <rtems/libio_.h>
 
 #include "imfs.h"
-#include <rtems/libio_.h>
 
-#if defined(IMFS_DEBUG)
-#include <stdio.h>
-#endif
-
-/*
- *  IMFS file system operations table
- */
-
-const rtems_filesystem_operations_table  IMFS_ops = {
-  IMFS_eval_path,
-  IMFS_evaluate_for_make,
-  IMFS_link,
-  IMFS_unlink,
-  IMFS_node_type,
-  IMFS_mknod,
-  IMFS_chown,
-  IMFS_freenodinfo,
-  IMFS_mount,
-  IMFS_initialize,
-  IMFS_unmount,
-  IMFS_fsunmount,
-  IMFS_utime,
-  IMFS_evaluate_link,
-  IMFS_symlink,
-  IMFS_readlink,
-  IMFS_rename,
-  NULL
+const rtems_filesystem_operations_table IMFS_ops = {
+  .evalpath_h = IMFS_eval_path,
+  .evalformake_h = IMFS_evaluate_for_make,
+  .link_h = IMFS_link,
+  .unlink_h = IMFS_unlink,
+  .node_type_h = IMFS_node_type,
+  .mknod_h = IMFS_mknod,
+  .chown_h = IMFS_chown,
+  .freenod_h = IMFS_freenodinfo,
+  .mount_h = IMFS_mount,
+  .fsmount_me_h = IMFS_initialize,
+  .unmount_h = IMFS_unmount,
+  .fsunmount_me_h = IMFS_fsunmount,
+  .utime_h = IMFS_utime,
+  .eval_link_h = IMFS_evaluate_link,
+  .symlink_h = IMFS_symlink,
+  .readlink_h = IMFS_readlink,
+  .rename_h = IMFS_rename,
+  .statvfs_h = NULL
 };
 
-/*
- *  IMFS_initialize
- */
-
 int IMFS_initialize(
-  rtems_filesystem_mount_table_entry_t *temp_mt_entry,
+  rtems_filesystem_mount_table_entry_t *mt_entry,
   const void                           *data
 )
 {
-   return IMFS_initialize_support(
-     temp_mt_entry,
-     &IMFS_ops,
-     &IMFS_memfile_handlers,
-     &IMFS_directory_handlers
-   );
+  return IMFS_initialize_support(
+    mt_entry,
+    &IMFS_ops,
+    &IMFS_memfile_handlers,
+    &IMFS_directory_handlers,
+    &rtems_filesystem_null_handlers  /* for fifos */
+  );
 }
Index: cpukit/libfs/src/imfs/imfs_initsupp.c
===================================================================
--- cpukit/libfs/src/imfs/imfs_initsupp.c	(revision 5b5772ae313eb2dd8d211749bc2eb3fea63758f8)
+++ cpukit/libfs/src/imfs/imfs_initsupp.c	(revision 241f4c96378ff3ca0ad811290c1dac49b571d1cc)
@@ -67,5 +67,6 @@
    const rtems_filesystem_operations_table    *op_table,
    const rtems_filesystem_file_handlers_r     *memfile_handlers,
-   const rtems_filesystem_file_handlers_r     *directory_handlers
+   const rtems_filesystem_file_handlers_r     *directory_handlers,
+   const rtems_filesystem_file_handlers_r     *fifo_handlers
 )
 {
@@ -109,11 +110,9 @@
   fs_info->memfile_handlers      = memfile_handlers;
   fs_info->directory_handlers    = directory_handlers;
+  fs_info->fifo_handlers         = fifo_handlers;
 
   jnode = temp_mt_entry->mt_fs_root.node_access;
   jnode->st_ino = fs_info->ino_count;
 
-  /* Initialize POSIX FIFO/pipe module */
-  rtems_pipe_initialize();
-
   return 0;
 }
Index: cpukit/libfs/src/imfs/miniimfs_init.c
===================================================================
--- cpukit/libfs/src/imfs/miniimfs_init.c	(revision 5b5772ae313eb2dd8d211749bc2eb3fea63758f8)
+++ cpukit/libfs/src/imfs/miniimfs_init.c	(revision 241f4c96378ff3ca0ad811290c1dac49b571d1cc)
@@ -1,5 +1,11 @@
+/**
+ * @file
+ *
+ * @ingroup LibFSIMFS
+ *
+ * @brief Mini-IMFS initialization.
+ */
+
 /*
- *  Mini-IMFS Initialization
- *
  *  COPYRIGHT (c) 1989-1999.
  *  On-Line Applications Research Corporation (OAR).
@@ -16,57 +22,40 @@
 #endif
 
-#include <sys/types.h>         /* for mkdir */
-#include <fcntl.h>
-#include <unistd.h>
-#include <stdlib.h>
-
-#include <assert.h>
+#include <rtems/libio_.h>
 
 #include "imfs.h"
-#include <rtems/libio_.h>
 
-#if defined(IMFS_DEBUG)
-#include <stdio.h>
-#endif
-
-/*
- *  miniIMFS file system operations table
- */
-
-const rtems_filesystem_operations_table  miniIMFS_ops = {
-  IMFS_eval_path,
-  IMFS_evaluate_for_make,
-  NULL, /* XXX IMFS_link, */
-  NULL, /* XXX IMFS_unlink, */
-  IMFS_node_type,
-  IMFS_mknod,
-  NULL, /* XXX IMFS_chown, */
-  NULL, /* XXX IMFS_freenodinfo, */
-  NULL, /* XXX IMFS_mount, */
-  miniIMFS_initialize,
-  NULL, /* XXX IMFS_unmount, */
-  NULL, /* XXX IMFS_fsunmount, */
-  NULL, /* XXX IMFS_utime, */
-  NULL, /* XXX IMFS_evaluate_link, */
-  NULL, /* XXX IMFS_symlink, */
-  NULL, /* XXX IMFS_readlink */
-  NULL, /* XXX IMFS_rename */
-  NULL  /* XXX IMFS_statvfs */
+static const rtems_filesystem_operations_table miniIMFS_ops = {
+  .evalpath_h = IMFS_eval_path,
+  .evalformake_h = IMFS_evaluate_for_make,
+  .link_h = NULL,
+  .unlink_h = NULL,
+  .node_type_h = IMFS_node_type,
+  .mknod_h = IMFS_mknod,
+  .chown_h = NULL,
+  .freenod_h = NULL,
+  .mount_h = IMFS_mount,
+  .fsmount_me_h = miniIMFS_initialize,
+  .unmount_h = NULL,
+  .fsunmount_me_h = NULL,
+  .utime_h = NULL,
+  .eval_link_h = NULL,
+  .symlink_h = NULL,
+  .readlink_h = NULL,
+  .rename_h = NULL,
+  .statvfs_h = NULL
 };
 
-/*
- *  miniIMFS_initialize
- */
-
 int miniIMFS_initialize(
-  rtems_filesystem_mount_table_entry_t *temp_mt_entry,
+  rtems_filesystem_mount_table_entry_t *mt_entry,
   const void                           *data
 )
 {
-    return IMFS_initialize_support(
-      temp_mt_entry,
-      &miniIMFS_ops,
-      &rtems_filesystem_null_handlers,  /* for memfiles */
-      &rtems_filesystem_null_handlers   /* for directories */
-   );
+  return IMFS_initialize_support(
+    mt_entry,
+    &miniIMFS_ops,
+    &rtems_filesystem_null_handlers, /* for memfiles */
+    &rtems_filesystem_null_handlers, /* for directories */
+    &rtems_filesystem_null_handlers  /* for fifos */
+  );
 }
Index: cpukit/libfs/src/pipe/fifo.c
===================================================================
--- cpukit/libfs/src/pipe/fifo.c	(revision 5b5772ae313eb2dd8d211749bc2eb3fea63758f8)
+++ cpukit/libfs/src/pipe/fifo.c	(revision 241f4c96378ff3ca0ad811290c1dac49b571d1cc)
@@ -22,4 +22,8 @@
 #include <errno.h>
 #include <stdlib.h>
+
+#include <rtems.h>
+#include <rtems/libio_.h>
+
 #include "pipe.h"
 
@@ -30,7 +34,5 @@
 #define LIBIO_NODELAY(_iop) ((_iop)->flags & LIBIO_FLAGS_NO_DELAY)
 
-extern uint16_t rtems_pipe_no;
-static rtems_id rtems_pipe_semaphore = 0;
-extern bool rtems_pipe_configured;
+static rtems_id pipe_semaphore = RTEMS_ID_NONE;
 
 
@@ -83,5 +85,5 @@
 /*
  * Alloc pipe control structure, buffer, and resources.
- * Called with rtems_pipe_semaphore held.
+ * Called with pipe_semaphore held.
  */
 static int pipe_alloc(
@@ -140,5 +142,5 @@
 }
 
-/* Called with rtems_pipe_semaphore held. */
+/* Called with pipe_semaphore held. */
 static inline void pipe_free(
   pipe_control_t *pipe
@@ -152,4 +154,46 @@
 }
 
+static rtems_status_code pipe_lock(void)
+{
+  rtems_status_code sc = RTEMS_SUCCESSFUL;
+
+  if (pipe_semaphore == RTEMS_ID_NONE) {
+    rtems_libio_lock();
+
+    if (pipe_semaphore == RTEMS_ID_NONE) {
+      sc = rtems_semaphore_create(
+        rtems_build_name('P', 'I', 'P', 'E'),
+        1,
+        RTEMS_BINARY_SEMAPHORE | RTEMS_INHERIT_PRIORITY | RTEMS_PRIORITY,
+        RTEMS_NO_PRIORITY,
+        &pipe_semaphore
+      );
+    }
+
+    rtems_libio_unlock();
+  }
+
+  if (sc == RTEMS_SUCCESSFUL) {
+    sc = rtems_semaphore_obtain(pipe_semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
+  }
+
+  if (sc == RTEMS_SUCCESSFUL) {
+    return 0;
+  } else {
+    return -EINTR;
+  }
+}
+
+static void pipe_unlock(void)
+{
+  rtems_status_code sc = RTEMS_SUCCESSFUL;
+
+  sc = rtems_semaphore_release(pipe_semaphore);
+  if (sc != RTEMS_SUCCESSFUL) {
+    /* FIXME */
+    rtems_fatal_error_occurred(0xdeadbeef);
+  }
+}
+
 /*
  * If called with *pipep = NULL, pipe_new will call pipe_alloc to allocate a
@@ -164,7 +208,7 @@
   int err = 0;
 
-  if (rtems_semaphore_obtain(rtems_pipe_semaphore,
-        RTEMS_WAIT, RTEMS_NO_TIMEOUT) != RTEMS_SUCCESSFUL)
-    return -EINTR;
+  err = pipe_lock();
+  if (err)
+    return err;
 
   pipe = *pipep;
@@ -186,5 +230,5 @@
 
 out:
-  rtems_semaphore_release(rtems_pipe_semaphore);
+  pipe_unlock();
   return err;
 }
@@ -205,9 +249,14 @@
 
   rtems_status_code sc;
-  sc = rtems_semaphore_obtain(pipe->Semaphore,
-                              RTEMS_WAIT, RTEMS_NO_TIMEOUT);
-  /* WARN pipe not released! */
-  if(sc != RTEMS_SUCCESSFUL)
-    rtems_fatal_error_occurred(sc);
+
+  if (pipe_lock())
+    /* WARN pipe not freed and pipep not set to NULL! */
+    /* FIXME */
+    rtems_fatal_error_occurred(0xdeadbeef);
+
+  if (!PIPE_LOCK(pipe))
+    /* WARN pipe not released! */
+    /* FIXME */
+    rtems_fatal_error_occurred(0xdeadbeef);
 
   mode = LIBIO_ACCMODE(iop);
@@ -217,10 +266,4 @@
      pipe->Writers --;
 
-  sc = rtems_semaphore_obtain(rtems_pipe_semaphore,
-                              RTEMS_WAIT, RTEMS_NO_TIMEOUT);
-  /* WARN pipe not freed and pipep not set to NULL! */
-  if(sc != RTEMS_SUCCESSFUL)
-    rtems_fatal_error_occurred(sc);
-
   PIPE_UNLOCK(pipe);
 
@@ -240,5 +283,5 @@
     PIPE_WAKEUPREADERS(pipe);
 
-  rtems_semaphore_release(rtems_pipe_semaphore);
+  pipe_unlock();
 
 #if 0
@@ -540,26 +583,2 @@
   return -ESPIPE;
 }
-
-/*
- * Initialization of FIFO/pipe module.
- */
-void rtems_pipe_initialize (void)
-{
-  if (!rtems_pipe_configured)
-    return;
-
-  if (rtems_pipe_semaphore)
-    return;
-
-  rtems_status_code sc;
-  sc = rtems_semaphore_create(
-        rtems_build_name ('P', 'I', 'P', 'E'), 1,
-        RTEMS_BINARY_SEMAPHORE | RTEMS_INHERIT_PRIORITY | RTEMS_PRIORITY,
-        RTEMS_NO_PRIORITY, &rtems_pipe_semaphore);
-  if (sc != RTEMS_SUCCESSFUL)
-    rtems_fatal_error_occurred (sc);
-
-  rtems_interval now;
-  now = rtems_clock_get_ticks_since_boot();
-  rtems_pipe_no = now;
-}
Index: cpukit/libfs/src/pipe/pipe.c
===================================================================
--- cpukit/libfs/src/pipe/pipe.c	(revision 5b5772ae313eb2dd8d211749bc2eb3fea63758f8)
+++ cpukit/libfs/src/pipe/pipe.c	(revision 241f4c96378ff3ca0ad811290c1dac49b571d1cc)
@@ -21,5 +21,6 @@
 
 /* Incremental number added to names of anonymous pipe files */
-uint16_t rtems_pipe_no = 0;
+/* FIXME: This approach is questionable */
+static uint16_t rtems_pipe_no = 0;
 
 /*
@@ -34,4 +35,5 @@
   int err = 0;
   /* Create /tmp if not exists */
+  /* FIXME: We should use a general mkdir function for this */
   if (rtems_filesystem_evaluate_path("/tmp", 3, RTEMS_LIBIO_PERMS_RWX, &loc, TRUE)
       != 0) {
Index: cpukit/libfs/src/pipe/pipe.h
===================================================================
--- cpukit/libfs/src/pipe/pipe.h	(revision 5b5772ae313eb2dd8d211749bc2eb3fea63758f8)
+++ cpukit/libfs/src/pipe/pipe.h	(revision 241f4c96378ff3ca0ad811290c1dac49b571d1cc)
@@ -110,9 +110,4 @@
 );
 
-/*
- * Initialization of FIFO/pipe module.
- */
-extern void rtems_pipe_initialize (void);
-
 #ifdef __cplusplus
 }
Index: cpukit/sapi/include/confdefs.h
===================================================================
--- cpukit/sapi/include/confdefs.h	(revision 5b5772ae313eb2dd8d211749bc2eb3fea63758f8)
+++ cpukit/sapi/include/confdefs.h	(revision 241f4c96378ff3ca0ad811290c1dac49b571d1cc)
@@ -294,5 +294,9 @@
 #if !defined(CONFIGURE_FILESYSTEM_ENTRY_IMFS) && \
     defined(CONFIGURE_FILESYSTEM_IMFS)
-#define CONFIGURE_FILESYSTEM_ENTRY_IMFS { "imfs", IMFS_initialize }
+  #if defined(CONFIGURE_PIPES_ENABLED)
+    #define CONFIGURE_FILESYSTEM_ENTRY_IMFS { "imfs", fifoIMFS_initialize }
+  #else
+    #define CONFIGURE_FILESYSTEM_ENTRY_IMFS { "imfs", IMFS_initialize }
+  #endif
 #endif
 
@@ -429,18 +433,4 @@
   #endif
 
-  /**
-   *  This disables the inclusion of pipe support in the full IMFS.
-   *
-   *  NOTE: When building for coverage, we need this variable all the time.
-   */
-  #if !defined(CONFIGURE_USE_DEVFS_AS_BASE_FILESYSTEM) || \
-      defined(RTEMS_COVERAGE)
-    #if defined(CONFIGURE_PIPES_ENABLED)
-      bool rtems_pipe_configured = true;
-    #else
-      bool rtems_pipe_configured = false;
-    #endif
-  #endif
-
   #ifndef CONFIGURE_HAS_OWN_MOUNT_TABLE
     const rtems_filesystem_mount_table_t configuration_mount_table = {
