diff --git a/arch b/arch index 2c6b85793f2..2a3c96286af 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 2c6b85793f26fb265e88ff2fc3d4e71707f9ab2b +Subproject commit 2a3c96286af41c261411d9cdd17e98e2ee18dc2e diff --git a/drivers/pipes/fifo.c b/drivers/pipes/fifo.c index 85905cb1114..b63f9a18561 100644 --- a/drivers/pipes/fifo.c +++ b/drivers/pipes/fifo.c @@ -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 ****************************************************************************/ diff --git a/drivers/pipes/pipe_common.c b/drivers/pipes/pipe_common.c index 346bb5dc692..fab22f7e5d4 100644 --- a/drivers/pipes/pipe_common.c +++ b/drivers/pipes/pipe_common.c @@ -55,6 +55,7 @@ #include #include +#include #ifdef CONFIG_DEBUG # include #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) - { - PIPE_POLICY_1(dev->d_flags); - } - else - { - PIPE_POLICY_0(dev->d_flags); - } + return -EBADF; + } +#endif - return OK; + pipecommon_semtake(&dev->d_bfsem); + + switch (cmd) + { + case PIPEIOC_POLICY: + { + if (arg != 0) + { + PIPE_POLICY_1(dev->d_flags); + } + else + { + PIPE_POLICY_0(dev->d_flags); + } + + ret = OK; + } + 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: + { + 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; + + default: + break; } - return -ENOTTY; + sem_post(&dev->d_bfsem); + return ret; } /**************************************************************************** diff --git a/drivers/pipes/pipe_common.h b/drivers/pipes/pipe_common.h index 5bbe850bb36..2000f8c7f3e 100644 --- a/drivers/pipes/pipe_common.h +++ b/drivers/pipes/pipe_common.h @@ -1,7 +1,7 @@ /**************************************************************************** * 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 * * Redistribution and use in source and binary forms, with or without