Exemple #1
0
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;

  /* Only one command supported */

  if (cmd == PIPEIOC_POLICY)
    {
      if (arg != 0)
        {
          PIPE_POLICY_1(dev->d_flags);
        }
      else
        {
          PIPE_POLICY_0(dev->d_flags);
        }

      return OK;
    }

  return -ENOTTY;
}
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;
  int                    ret   = -EINVAL;

#ifdef CONFIG_DEBUG
  /* Some sanity checking */

  if (dev == NULL)
    {
       return -EBADF;
    }
#endif

  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;
            }

          *(FAR 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;
            }

          *(FAR int *)arg = count;
          ret = 0;
        }
        break;

      default:
        break;
    }

  sem_post(&dev->d_bfsem);
  return ret;
}
Exemple #3
0
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;
  int                    ret   = -EINVAL;

#ifdef CONFIG_DEBUG_FEATURES
  /* Some sanity checking */

  if (dev == NULL)
    {
       return -EBADF;
    }
#endif

  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 FIONWRITE:  /* Number of bytes waiting in send queue */
      case FIONREAD:   /* Number of bytes available for reading */
        {
          int count;

          /* Determine the number of bytes written to the buffer.  This is,
           * of course, also the number of bytes that may be read from the
           * buffer.
           *
           *   d_rdndx - index to remove next byte from the buffer
           *   d_wrndx - Index to next location to add a byte to the buffer.
           */

          if (dev->d_wrndx < dev->d_rdndx)
            {
              count = (dev->d_bufsize - dev->d_rdndx) + dev->d_wrndx;
            }
          else
            {
              count = dev->d_wrndx - dev->d_rdndx;
            }

          *(FAR int *)((uintptr_t)arg) = count;
          ret = 0;
        }
        break;

      /* Free space in buffer */

      case FIONSPACE:
        {
          int count;

          /* Determine the number of bytes free in the buffer.
           *
           *   d_rdndx - index to remove next byte from the buffer
           *   d_wrndx - Index to next location to add a byte to the buffer.
           */

          if (dev->d_wrndx < dev->d_rdndx)
            {
              count = (dev->d_rdndx - dev->d_wrndx) - 1;
            }
          else
            {
              count = ((dev->d_bufsize - dev->d_wrndx) + dev->d_rdndx) - 1;
            }

          *(FAR int *)((uintptr_t)arg) = count;
          ret = 0;
        }
        break;

      default:
        break;
    }

  sem_post(&dev->d_bfsem);
  return ret;
}