2008-07-20 22:58:32 +02:00
|
|
|
/****************************************************************************
|
2009-10-18 15:52:21 +02:00
|
|
|
* drivers/pipes/fifo.c
|
2008-07-20 22:58:32 +02:00
|
|
|
*
|
2021-03-04 07:10:42 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2008-07-20 22:58:32 +02:00
|
|
|
*
|
2021-03-04 07:10:42 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2008-07-20 22:58:32 +02:00
|
|
|
*
|
2021-03-04 07:10:42 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2008-07-20 22:58:32 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
2014-01-14 20:30:22 +01:00
|
|
|
#include <sys/stat.h>
|
2009-12-15 15:25:14 +01:00
|
|
|
#include <stdint.h>
|
2008-07-26 15:12:11 +02:00
|
|
|
#include <errno.h>
|
|
|
|
|
2016-07-20 21:15:37 +02:00
|
|
|
#include <nuttx/fs/fs.h>
|
|
|
|
|
2008-08-10 18:57:15 +02:00
|
|
|
#include "pipe_common.h"
|
2008-07-20 22:58:32 +02:00
|
|
|
|
2016-07-19 21:34:18 +02:00
|
|
|
#if CONFIG_DEV_FIFO_SIZE > 0
|
2008-07-22 02:52:07 +02:00
|
|
|
|
2008-07-20 22:58:32 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
2009-06-10 17:22:49 +02:00
|
|
|
static const struct file_operations fifo_fops =
|
2008-07-20 22:58:32 +02:00
|
|
|
{
|
2022-01-10 15:51:17 +01:00
|
|
|
pipecommon_open, /* open */
|
|
|
|
pipecommon_close, /* close */
|
|
|
|
pipecommon_read, /* read */
|
|
|
|
pipecommon_write, /* write */
|
|
|
|
NULL, /* seek */
|
|
|
|
pipecommon_ioctl, /* ioctl */
|
|
|
|
pipecommon_poll /* poll */
|
2015-02-18 16:34:58 +01:00
|
|
|
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
|
2022-01-10 15:51:17 +01:00
|
|
|
, pipecommon_unlink /* unlink */
|
2015-02-18 16:34:58 +01:00
|
|
|
#endif
|
2008-07-20 22:58:32 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2020-05-04 08:49:38 +02:00
|
|
|
* Name: nx_mkfifo
|
2008-07-20 22:58:32 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2020-05-04 08:49:38 +02:00
|
|
|
* nx_mkfifo() makes a FIFO device driver file with name 'pathname.' Unlike
|
2015-01-31 19:05:01 +01:00
|
|
|
* Linux, a NuttX FIFO is not a special file type but simply a device
|
|
|
|
* driver instance. 'mode' specifies the FIFO's permissions.
|
2008-07-20 22:58:32 +02:00
|
|
|
*
|
2020-05-04 08:49:38 +02:00
|
|
|
* Once the FIFO has been created by nx_mkfifo(), any thread can open it
|
|
|
|
* for reading or writing, in the same way as an ordinary file. However, it
|
2015-01-31 19:05:01 +01:00
|
|
|
* must have been opened from both reading and writing before input or
|
|
|
|
* output can be performed. This FIFO implementation will block all
|
|
|
|
* attempts to open a FIFO read-only until at least one thread has opened
|
|
|
|
* the FIFO for writing.
|
2008-07-26 16:24:17 +02:00
|
|
|
*
|
|
|
|
* If all threads that write to the FIFO have closed, subsequent calls to
|
|
|
|
* read() on the FIFO will return 0 (end-of-file).
|
2008-07-20 22:58:32 +02:00
|
|
|
*
|
2020-05-04 08:49:38 +02:00
|
|
|
* NOTE: nx_mkfifo is a special, non-standard, NuttX-only interface. Since
|
2016-07-19 21:51:05 +02:00
|
|
|
* the NuttX FIFOs are based in in-memory, circular buffers, the ability
|
|
|
|
* to control the size of those buffers is critical for system tuning.
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Input Parameters:
|
2008-07-20 22:58:32 +02:00
|
|
|
* pathname - The full path to the FIFO instance to attach to or to create
|
|
|
|
* (if not already created).
|
|
|
|
* mode - Ignored for now
|
2016-07-19 21:51:05 +02:00
|
|
|
* bufsize - The size of the in-memory, circular buffer in bytes.
|
2008-07-20 22:58:32 +02:00
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2020-10-28 15:54:40 +01:00
|
|
|
* 0 is returned on success; a negated errno value is returned on a
|
|
|
|
* failure.
|
2008-07-20 22:58:32 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
2012-07-15 16:56:25 +02:00
|
|
|
|
2020-05-04 08:49:38 +02:00
|
|
|
int nx_mkfifo(FAR const char *pathname, mode_t mode, size_t bufsize)
|
2008-07-20 22:58:32 +02:00
|
|
|
{
|
2015-10-10 18:41:00 +02:00
|
|
|
FAR struct pipe_dev_s *dev;
|
2008-07-26 15:12:11 +02:00
|
|
|
int ret;
|
2014-04-13 22:32:20 +02:00
|
|
|
|
2008-07-26 15:12:11 +02:00
|
|
|
/* Allocate and initialize a new device structure instance */
|
|
|
|
|
2016-07-19 21:51:05 +02:00
|
|
|
dev = pipecommon_allocdev(bufsize);
|
2008-07-26 15:12:11 +02:00
|
|
|
if (!dev)
|
|
|
|
{
|
2020-05-04 08:49:38 +02:00
|
|
|
return -ENOMEM;
|
2008-07-26 15:12:11 +02:00
|
|
|
}
|
|
|
|
|
2015-10-10 18:41:00 +02:00
|
|
|
ret = register_driver(pathname, &fifo_fops, mode, (FAR void *)dev);
|
2008-07-26 15:12:11 +02:00
|
|
|
if (ret != 0)
|
|
|
|
{
|
|
|
|
pipecommon_freedev(dev);
|
|
|
|
}
|
2012-07-15 16:56:25 +02:00
|
|
|
|
2020-05-04 08:49:38 +02:00
|
|
|
return ret;
|
2008-07-20 22:58:32 +02:00
|
|
|
}
|
2012-07-15 16:56:25 +02:00
|
|
|
|
2016-07-19 21:34:18 +02:00
|
|
|
#endif /* CONFIG_DEV_FIFO_SIZE > 0 */
|