2008-07-21 04:58:32 +08:00
|
|
|
/****************************************************************************
|
2009-10-18 21:52:21 +08:00
|
|
|
* drivers/pipes/fifo.c
|
2008-07-21 04:58:32 +08:00
|
|
|
*
|
2021-03-04 14:10:42 +08: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-21 04:58:32 +08:00
|
|
|
*
|
2021-03-04 14:10:42 +08:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2008-07-21 04:58:32 +08:00
|
|
|
*
|
2021-03-04 14:10:42 +08: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-21 04:58:32 +08:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
2014-01-15 03:30:22 +08:00
|
|
|
#include <sys/stat.h>
|
2009-12-15 22:25:14 +08:00
|
|
|
#include <stdint.h>
|
2008-07-26 21:12:11 +08:00
|
|
|
#include <errno.h>
|
|
|
|
|
2016-07-21 03:15:37 +08:00
|
|
|
#include <nuttx/fs/fs.h>
|
|
|
|
|
2008-08-11 00:57:15 +08:00
|
|
|
#include "pipe_common.h"
|
2008-07-21 04:58:32 +08:00
|
|
|
|
2016-07-20 03:34:18 +08:00
|
|
|
#if CONFIG_DEV_FIFO_SIZE > 0
|
2008-07-22 08:52:07 +08:00
|
|
|
|
2008-07-21 04:58:32 +08:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
2022-02-06 00:03:15 +08:00
|
|
|
static const struct file_operations g_fifo_fops =
|
2008-07-21 04:58:32 +08:00
|
|
|
{
|
2022-01-10 22:51:17 +08:00
|
|
|
pipecommon_open, /* open */
|
|
|
|
pipecommon_close, /* close */
|
|
|
|
pipecommon_read, /* read */
|
|
|
|
pipecommon_write, /* write */
|
|
|
|
NULL, /* seek */
|
|
|
|
pipecommon_ioctl, /* ioctl */
|
2023-01-02 21:02:51 +08:00
|
|
|
NULL, /* mmap */
|
2023-01-03 01:06:12 +08:00
|
|
|
NULL, /* truncate */
|
2022-01-10 22:51:17 +08:00
|
|
|
pipecommon_poll /* poll */
|
2015-02-18 23:34:58 +08:00
|
|
|
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
|
2022-01-10 22:51:17 +08:00
|
|
|
, pipecommon_unlink /* unlink */
|
2015-02-18 23:34:58 +08:00
|
|
|
#endif
|
2008-07-21 04:58:32 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2020-05-04 14:49:38 +08:00
|
|
|
* Name: nx_mkfifo
|
2008-07-21 04:58:32 +08:00
|
|
|
*
|
|
|
|
* Description:
|
2020-05-04 14:49:38 +08:00
|
|
|
* nx_mkfifo() makes a FIFO device driver file with name 'pathname.' Unlike
|
2015-02-01 02:05:01 +08: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-21 04:58:32 +08:00
|
|
|
*
|
2020-05-04 14:49:38 +08: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-02-01 02:05:01 +08: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 22:24:17 +08: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-21 04:58:32 +08:00
|
|
|
*
|
2020-05-04 14:49:38 +08:00
|
|
|
* NOTE: nx_mkfifo is a special, non-standard, NuttX-only interface. Since
|
2016-07-20 03:51:05 +08: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-02 00:00:02 +08:00
|
|
|
* Input Parameters:
|
2008-07-21 04:58:32 +08: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-20 03:51:05 +08:00
|
|
|
* bufsize - The size of the in-memory, circular buffer in bytes.
|
2008-07-21 04:58:32 +08:00
|
|
|
*
|
2018-02-02 00:00:02 +08:00
|
|
|
* Returned Value:
|
2020-10-28 22:54:40 +08:00
|
|
|
* 0 is returned on success; a negated errno value is returned on a
|
|
|
|
* failure.
|
2008-07-21 04:58:32 +08:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
2012-07-15 22:56:25 +08:00
|
|
|
|
2020-05-04 14:49:38 +08:00
|
|
|
int nx_mkfifo(FAR const char *pathname, mode_t mode, size_t bufsize)
|
2008-07-21 04:58:32 +08:00
|
|
|
{
|
2015-10-11 00:41:00 +08:00
|
|
|
FAR struct pipe_dev_s *dev;
|
2008-07-26 21:12:11 +08:00
|
|
|
int ret;
|
2014-04-14 04:32:20 +08:00
|
|
|
|
2008-07-26 21:12:11 +08:00
|
|
|
/* Allocate and initialize a new device structure instance */
|
|
|
|
|
2016-07-20 03:51:05 +08:00
|
|
|
dev = pipecommon_allocdev(bufsize);
|
2008-07-26 21:12:11 +08:00
|
|
|
if (!dev)
|
|
|
|
{
|
2020-05-04 14:49:38 +08:00
|
|
|
return -ENOMEM;
|
2008-07-26 21:12:11 +08:00
|
|
|
}
|
|
|
|
|
2023-06-07 21:57:30 +08:00
|
|
|
ret = register_pipedriver(pathname, &g_fifo_fops, mode, (FAR void *)dev);
|
2008-07-26 21:12:11 +08:00
|
|
|
if (ret != 0)
|
|
|
|
{
|
|
|
|
pipecommon_freedev(dev);
|
|
|
|
}
|
2012-07-15 22:56:25 +08:00
|
|
|
|
2020-05-04 14:49:38 +08:00
|
|
|
return ret;
|
2008-07-21 04:58:32 +08:00
|
|
|
}
|
2012-07-15 22:56:25 +08:00
|
|
|
|
2016-07-20 03:34:18 +08:00
|
|
|
#endif /* CONFIG_DEV_FIFO_SIZE > 0 */
|