Skip to content
Snippets Groups Projects
Commit 38eb8bb1 authored by Andrew Tridgell's avatar Andrew Tridgell Committed by Gregory Nutt
Browse files

pipes: support FIONREAD and FIONWRITE ioctl on pipes; use semaphores for pipecommon_ioctl().

parent 03a77c1d
No related branches found
No related tags found
No related merge requests found
arch @ 2a3c9628
Subproject commit 2c6b85793f26fb265e88ff2fc3d4e71707f9ab2b
Subproject commit 2a3c96286af41c261411d9cdd17e98e2ee18dc2e
......@@ -50,18 +50,6 @@
#if CONFIG_DEV_PIPE_SIZE > 0
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
......@@ -82,10 +70,6 @@ static const struct file_operations fifo_fops =
#endif
};
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
......
......@@ -55,6 +55,7 @@
#include <nuttx/kmalloc.h>
#include <nuttx/fs/fs.h>
#include <nuttx/fs/ioctl.h>
#ifdef CONFIG_DEBUG
# include <nuttx/arch.h>
#endif
......@@ -77,20 +78,12 @@
# define pipe_dumpbuffer(m,a,n)
#endif
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
static void pipecommon_semtake(sem_t *sem);
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
......@@ -746,32 +739,90 @@ errout:
}
#endif
/****************************************************************************
/************************************************************************************
* Name: pipecommon_ioctl
****************************************************************************/
************************************************************************************/
int pipecommon_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
int pipecommon_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
{
FAR struct inode *inode = filep->f_inode;
FAR struct pipe_dev_s *dev = inode->i_private;
FAR struct inode *inode = filep->f_inode;
struct pipe_dev_s *dev = inode->i_private;
int ret = -EINVAL;
/* Only one command supported */
#ifdef CONFIG_DEBUG
/* Some sanity checking */
if (cmd == PIPEIOC_POLICY)
if (dev == NULL)
{
if (arg != 0)
return -EBADF;
}
#endif
pipecommon_semtake(&dev->d_bfsem);
switch (cmd)
{
case PIPEIOC_POLICY:
{
PIPE_POLICY_1(dev->d_flags);
if (arg != 0)
{
PIPE_POLICY_1(dev->d_flags);
}
else
{
PIPE_POLICY_0(dev->d_flags);
}
ret = OK;
}
else
break;
case FIONREAD:
{
int count;
/* Determine the number of bytes available in the buffer */
if (dev->d_wrndx < dev->d_rdndx)
{
count = (CONFIG_DEV_PIPE_SIZE - dev->d_rdndx) + dev->d_wrndx;
}
else
{
count = dev->d_wrndx - dev->d_rdndx;
}
*(int *)arg = count;
ret = 0;
}
break;
case FIONWRITE:
{
PIPE_POLICY_0(dev->d_flags);
int count;
/* Determine the number of bytes free in the buffer */
if (dev->d_wrndx < dev->d_rdndx)
{
count = (dev->d_rdndx - dev->d_wrndx) - 1;
}
else
{
count = ((CONFIG_DEV_PIPE_SIZE - dev->d_wrndx) + dev->d_rdndx) - 1;
}
*(int *)arg = count;
ret = 0;
}
break;
return OK;
default:
break;
}
return -ENOTTY;
sem_post(&dev->d_bfsem);
return ret;
}
/****************************************************************************
......
/****************************************************************************
* drivers/pipe/pipe_common.h
*
* Copyright (C) 2008-2009, 2015 Gregory Nutt. All rights reserved.
* Copyright (C) 2008-2009, 2015=2016 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment