Skip to content

Commit

Permalink
drivers/iovec: revert vector io implement from loop/null/zero driver
Browse files Browse the repository at this point in the history
basic driver does not need such complex wrapper

Signed-off-by: chao an <[email protected]>
  • Loading branch information
anchao committed Jan 19, 2025
1 parent 90046d1 commit db6cd88
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 75 deletions.
31 changes: 15 additions & 16 deletions drivers/loop/loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@
* Private Function Prototypes
****************************************************************************/

static ssize_t loop_readv(FAR struct file *filep, FAR struct uio *uio);
static ssize_t loop_writev(FAR struct file *filep, FAR struct uio *uio);
static ssize_t loop_read(FAR struct file *filep, FAR char *buffer,
size_t buflen);
static ssize_t loop_write(FAR struct file *filep, FAR const char *buffer,
size_t buflen);
static int loop_ioctl(FAR struct file *filep, int cmd,
unsigned long arg);

Expand All @@ -53,42 +55,39 @@ static const struct file_operations g_loop_fops =
{
NULL, /* open */
NULL, /* close */
NULL, /* read */
NULL, /* write */
loop_read, /* read */
loop_write, /* write */
NULL, /* seek */
loop_ioctl, /* ioctl */
NULL, /* mmap */
NULL, /* truncate */
NULL, /* poll */
loop_readv, /* readv */
loop_writev /* writev */
NULL, /* readv */
NULL /* writev */
};

/****************************************************************************
* Private Functions
****************************************************************************/

/****************************************************************************
* Name: loop_readv
* Name: loop_read
****************************************************************************/

static ssize_t loop_readv(FAR struct file *filep, FAR struct uio *uio)
static ssize_t loop_read(FAR struct file *filep, FAR char *buffer,
size_t len)
{
return 0; /* Return EOF */
}

/****************************************************************************
* Name: loop_writev
* Name: loop_write
****************************************************************************/

static ssize_t loop_writev(FAR struct file *filep, FAR struct uio *uio)
static ssize_t loop_write(FAR struct file *filep, FAR const char *buffer,
size_t len)
{
/* Say that everything was written */

size_t ret = uio->uio_resid;

uio_advance(uio, ret);
return ret;
return len; /* Say that everything was written */
}

/****************************************************************************
Expand Down
49 changes: 25 additions & 24 deletions drivers/misc/dev_null.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@
* Private Function Prototypes
****************************************************************************/

static ssize_t devnull_readv(FAR struct file *filep, FAR struct uio *uio);
static ssize_t devnull_writev(FAR struct file *filep, FAR struct uio *uio);
static ssize_t devnull_read(FAR struct file *filep, FAR char *buffer,
size_t buflen);
static ssize_t devnull_write(FAR struct file *filep, FAR const char *buffer,
size_t buflen);
static int devnull_poll(FAR struct file *filep, FAR struct pollfd *fds,
bool setup);

Expand All @@ -51,49 +53,48 @@ static int devnull_poll(FAR struct file *filep, FAR struct pollfd *fds,

static const struct file_operations g_devnull_fops =
{
NULL, /* open */
NULL, /* close */
NULL, /* read */
NULL, /* writev */
NULL, /* seek */
NULL, /* ioctl */
NULL, /* mmap */
NULL, /* truncate */
devnull_poll, /* poll */
devnull_readv, /* readv */
devnull_writev /* writev */
NULL, /* open */
NULL, /* close */
devnull_read, /* read */
devnull_write, /* write */
NULL, /* seek */
NULL, /* ioctl */
NULL, /* mmap */
NULL, /* truncate */
devnull_poll, /* poll */
NULL, /* readv */
NULL /* writev */
};

/****************************************************************************
* Private Functions
****************************************************************************/

/****************************************************************************
* Name: devnull_readv
* Name: devnull_read
****************************************************************************/

static ssize_t devnull_readv(FAR struct file *filep, FAR struct uio *uio)
static ssize_t devnull_read(FAR struct file *filep, FAR char *buffer,
size_t len)
{
UNUSED(filep);
UNUSED(uio);
UNUSED(buffer);
UNUSED(len);

return 0; /* Return EOF */
}

/****************************************************************************
* Name: devnull_writev
* Name: devnull_write
****************************************************************************/

static ssize_t devnull_writev(FAR struct file *filep, FAR struct uio *uio)
static ssize_t devnull_write(FAR struct file *filep, FAR const char *buffer,
size_t len)
{
UNUSED(filep);
UNUSED(buffer);

/* Say that everything was written */

size_t ret = uio->uio_resid;

uio_advance(uio, ret);
return ret;
return len; /* Say that everything was written */
}

/****************************************************************************
Expand Down
60 changes: 25 additions & 35 deletions drivers/misc/dev_zero.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@
* Private Function Prototypes
****************************************************************************/

static ssize_t devzero_readv(FAR struct file *filep, FAR struct uio *uio);
static ssize_t devzero_writev(FAR struct file *filep, FAR struct uio *uio);
static ssize_t devzero_read(FAR struct file *filep, FAR char *buffer,
size_t buflen);
static ssize_t devzero_write(FAR struct file *filep, FAR const char *buffer,
size_t buflen);
static int devzero_poll(FAR struct file *filep, FAR struct pollfd *fds,
bool setup);

Expand All @@ -51,59 +53,47 @@ static int devzero_poll(FAR struct file *filep, FAR struct pollfd *fds,

static const struct file_operations g_devzero_fops =
{
NULL, /* open */
NULL, /* close */
NULL, /* read */
NULL, /* write */
NULL, /* seek */
NULL, /* ioctl */
NULL, /* mmap */
NULL, /* truncate */
devzero_poll, /* poll */
devzero_readv, /* readv */
devzero_writev /* writev */
NULL, /* open */
NULL, /* close */
devzero_read, /* read */
devzero_write, /* write */
NULL, /* seek */
NULL, /* ioctl */
NULL, /* mmap */
NULL, /* truncate */
devzero_poll, /* poll */
NULL, /* readv */
NULL /* writev */
};

/****************************************************************************
* Private Functions
****************************************************************************/

/****************************************************************************
* Name: devzero_readv
* Name: devzero_read
****************************************************************************/

static ssize_t devzero_readv(FAR struct file *filep, FAR struct uio *uio)
static ssize_t devzero_read(FAR struct file *filep, FAR char *buffer,
size_t len)
{
size_t total = uio->uio_resid;
FAR const struct iovec *iov = uio->uio_iov;
int iovcnt = uio->uio_iovcnt;
int i;

UNUSED(filep);

for (i = 0; i < iovcnt; i++)
{
memset(iov[i].iov_base, 0, iov[i].iov_len);
}

uio_advance(uio, total);

return total;
memset(buffer, 0, len);
return len;
}

/****************************************************************************
* Name: devzero_writev
* Name: devzero_write
****************************************************************************/

static ssize_t devzero_writev(FAR struct file *filep, FAR struct uio *uio)
static ssize_t devzero_write(FAR struct file *filep, FAR const char *buffer,
size_t len)
{
size_t total;
UNUSED(filep);
UNUSED(buffer);

total = uio->uio_resid;

uio_advance(uio, total);
return total;
return len;
}

/****************************************************************************
Expand Down

0 comments on commit db6cd88

Please sign in to comment.