Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:13

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @brief POSIX FIFO/pipe File System Support
0007  *
0008  * This include file defines the interface to the POSIX FIFO/pipe file system
0009  * support.
0010  */
0011 
0012 /*
0013  * Author: Wei Shen <cquark@gmail.com>
0014  *
0015  * Redistribution and use in source and binary forms, with or without
0016  * modification, are permitted provided that the following conditions
0017  * are met:
0018  * 1. Redistributions of source code must retain the above copyright
0019  *    notice, this list of conditions and the following disclaimer.
0020  * 2. Redistributions in binary form must reproduce the above copyright
0021  *    notice, this list of conditions and the following disclaimer in the
0022  *    documentation and/or other materials provided with the distribution.
0023  *
0024  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0025  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0026  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0027  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0028  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0029  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0030  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0031  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0032  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0033  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0034  * POSSIBILITY OF SUCH DAMAGE.
0035  */
0036 
0037 #ifndef _RTEMS_PIPE_H
0038 #define _RTEMS_PIPE_H
0039 
0040 #include <rtems/libio.h>
0041 #include <rtems/thread.h>
0042 
0043 /**
0044  * @defgroup FIFO_PIPE FIFO/Pipe File System Support
0045  *
0046  * @ingroup FileSystemTypesAndMount
0047  *
0048  * @brief Interface to the POSIX FIFO/Pipe File System
0049  */
0050 /**@{*/
0051 
0052 #ifdef __cplusplus
0053 extern "C" {
0054 #endif
0055 
0056 /* Control block to manage each pipe */
0057 typedef struct pipe_control {
0058   char *Buffer;
0059   unsigned int Size;
0060   unsigned int Start;
0061   unsigned int Length;
0062   unsigned int Readers;
0063   unsigned int Writers;
0064   unsigned int waitingReaders;
0065   unsigned int waitingWriters;
0066   unsigned int readerCounter;     /* incremental counters */
0067   unsigned int writerCounter;     /* for differentiation of successive opens */
0068   rtems_mutex Mutex;
0069   rtems_condition_variable readBarrier;   /* wait queues */
0070   rtems_condition_variable writeBarrier;
0071 #if 0
0072   boolean Anonymous;      /* anonymous pipe or FIFO */
0073 #endif
0074 } pipe_control_t;
0075 
0076 /**
0077  * @brief Release a pipe.
0078  *
0079  * Interface to file system close.
0080  *
0081  * *pipep points to pipe control structure. When the last user releases pipe,
0082  * it will be set to NULL.
0083  */
0084 extern void pipe_release(
0085   pipe_control_t **pipep,
0086   rtems_libio_t *iop
0087 );
0088 
0089 /**
0090  * @brief File system open.
0091  * Interface to file system open.
0092  *
0093  * *pipep points to pipe control structure. If called with *pipep = NULL,
0094  * fifo_open will try allocating and initializing a control structure. If the
0095  * call succeeds, *pipep will be set to address of new control structure.
0096  */
0097 extern int fifo_open(
0098   pipe_control_t **pipep,
0099   rtems_libio_t *iop
0100 );
0101 
0102 /**
0103  * @brief File system read.
0104  *
0105  * Interface to file system read.
0106  */
0107 extern ssize_t pipe_read(
0108   pipe_control_t *pipe,
0109   void           *buffer,
0110   size_t          count,
0111   rtems_libio_t  *iop
0112 );
0113 
0114 /**
0115  * @brief File system write.
0116  *
0117  * Interface to file system write.
0118  */
0119 extern ssize_t pipe_write(
0120   pipe_control_t *pipe,
0121   const void     *buffer,
0122   size_t          count,
0123   rtems_libio_t  *iop
0124 );
0125 
0126 /**
0127  * @brief File system Input/Output control.
0128  *
0129  * Interface to file system ioctl.
0130  */
0131 extern int pipe_ioctl(
0132   pipe_control_t  *pipe,
0133   ioctl_command_t  cmd,
0134   void            *buffer,
0135   rtems_libio_t   *iop
0136 );
0137 
0138 /** @} */
0139 
0140 #ifdef __cplusplus
0141 }
0142 #endif
0143 
0144 #endif