Skip to content

Commit 30ad31e

Browse files
yamtxiaoxiang781216
authored andcommitted
uio api tweaks
* Make readv/writev implementations update struct uio This can simplify partial result handling. * change the error number on the overflow from EOVERFLOW to EINVAL to match NetBSD * add a commented out uio_offset field. I used "#if 0" here as C comments can't nest. * add a few helper functions Note on uio_copyfrom/uio_copyto: although i'm not quite happy with the "offset" functionality, it's necessary to simplify the adaptation of some drivers like drivers/serial/serial.c, which (ab)uses the user-supplied buffer as a line-buffer.
1 parent 2749510 commit 30ad31e

File tree

8 files changed

+293
-64
lines changed

8 files changed

+293
-64
lines changed

drivers/loop/loop.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,8 @@
4040
* Private Function Prototypes
4141
****************************************************************************/
4242

43-
static ssize_t loop_readv(FAR struct file *filep,
44-
FAR const struct uio *uio);
45-
static ssize_t loop_writev(FAR struct file *filep,
46-
FAR const struct uio *uio);
43+
static ssize_t loop_readv(FAR struct file *filep, FAR struct uio *uio);
44+
static ssize_t loop_writev(FAR struct file *filep, FAR struct uio *uio);
4745
static int loop_ioctl(FAR struct file *filep, int cmd,
4846
unsigned long arg);
4947

@@ -74,8 +72,7 @@ static const struct file_operations g_loop_fops =
7472
* Name: loop_readv
7573
****************************************************************************/
7674

77-
static ssize_t loop_readv(FAR struct file *filep,
78-
FAR const struct uio *uio)
75+
static ssize_t loop_readv(FAR struct file *filep, FAR struct uio *uio)
7976
{
8077
return 0; /* Return EOF */
8178
}
@@ -84,10 +81,14 @@ static ssize_t loop_readv(FAR struct file *filep,
8481
* Name: loop_writev
8582
****************************************************************************/
8683

87-
static ssize_t loop_writev(FAR struct file *filep,
88-
FAR const struct uio *uio)
84+
static ssize_t loop_writev(FAR struct file *filep, FAR struct uio *uio)
8985
{
90-
return uio_total_len(uio); /* Say that everything was written */
86+
/* Say that everything was written */
87+
88+
size_t ret = uio->uio_resid;
89+
90+
uio_advance(uio, ret);
91+
return ret;
9192
}
9293

9394
/****************************************************************************

drivers/misc/dev_null.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,8 @@
4040
* Private Function Prototypes
4141
****************************************************************************/
4242

43-
static ssize_t devnull_readv(FAR struct file *filep,
44-
FAR const struct uio *uio);
45-
static ssize_t devnull_writev(FAR struct file *filep,
46-
FAR const struct uio *uio);
43+
static ssize_t devnull_readv(FAR struct file *filep, FAR struct uio *uio);
44+
static ssize_t devnull_writev(FAR struct file *filep, FAR struct uio *uio);
4745
static int devnull_poll(FAR struct file *filep, FAR struct pollfd *fds,
4846
bool setup);
4947

@@ -74,8 +72,7 @@ static const struct file_operations g_devnull_fops =
7472
* Name: devnull_readv
7573
****************************************************************************/
7674

77-
static ssize_t devnull_readv(FAR struct file *filep,
78-
FAR const struct uio *uio)
75+
static ssize_t devnull_readv(FAR struct file *filep, FAR struct uio *uio)
7976
{
8077
UNUSED(filep);
8178
UNUSED(uio);
@@ -87,12 +84,16 @@ static ssize_t devnull_readv(FAR struct file *filep,
8784
* Name: devnull_writev
8885
****************************************************************************/
8986

90-
static ssize_t devnull_writev(FAR struct file *filep,
91-
FAR const struct uio *uio)
87+
static ssize_t devnull_writev(FAR struct file *filep, FAR struct uio *uio)
9288
{
9389
UNUSED(filep);
9490

95-
return uio_total_len(uio); /* Say that everything was written */
91+
/* Say that everything was written */
92+
93+
size_t ret = uio->uio_resid;
94+
95+
uio_advance(uio, ret);
96+
return ret;
9697
}
9798

9899
/****************************************************************************

drivers/misc/dev_zero.c

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,8 @@
4040
* Private Function Prototypes
4141
****************************************************************************/
4242

43-
static ssize_t devzero_readv(FAR struct file *filep,
44-
FAR const struct uio *uio);
45-
static ssize_t devzero_writev(FAR struct file *filep,
46-
FAR const struct uio *uio);
43+
static ssize_t devzero_readv(FAR struct file *filep, FAR struct uio *uio);
44+
static ssize_t devzero_writev(FAR struct file *filep, FAR struct uio *uio);
4745
static int devzero_poll(FAR struct file *filep, FAR struct pollfd *fds,
4846
bool setup);
4947

@@ -74,39 +72,38 @@ static const struct file_operations g_devzero_fops =
7472
* Name: devzero_readv
7573
****************************************************************************/
7674

77-
static ssize_t devzero_readv(FAR struct file *filep,
78-
FAR const struct uio *uio)
75+
static ssize_t devzero_readv(FAR struct file *filep, FAR struct uio *uio)
7976
{
80-
ssize_t total = uio_total_len(uio);
77+
size_t total = uio->uio_resid;
8178
FAR const struct iovec *iov = uio->uio_iov;
8279
int iovcnt = uio->uio_iovcnt;
8380
int i;
8481

8582
UNUSED(filep);
8683

87-
if (total < 0)
88-
{
89-
return total;
90-
}
91-
9284
for (i = 0; i < iovcnt; i++)
9385
{
9486
memset(iov[i].iov_base, 0, iov[i].iov_len);
9587
}
9688

89+
uio_advance(uio, total);
90+
9791
return total;
9892
}
9993

10094
/****************************************************************************
10195
* Name: devzero_writev
10296
****************************************************************************/
10397

104-
static ssize_t devzero_writev(FAR struct file *filep,
105-
FAR const struct uio *uio)
98+
static ssize_t devzero_writev(FAR struct file *filep, FAR struct uio *uio)
10699
{
100+
size_t total;
107101
UNUSED(filep);
108102

109-
return uio_total_len(uio);
103+
total = uio->uio_resid;
104+
105+
uio_advance(uio, total);
106+
return total;
110107
}
111108

112109
/****************************************************************************

fs/vfs/fs_read.c

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@
5050
*
5151
****************************************************************************/
5252

53-
static ssize_t file_readv_compat(FAR struct file *filep,
54-
FAR const struct uio *uio)
53+
static ssize_t file_readv_compat(FAR struct file *filep, FAR struct uio *uio)
5554
{
5655
FAR const struct iovec *iov = uio->uio_iov;
5756
int iovcnt = uio->uio_iovcnt;
@@ -102,6 +101,11 @@ static ssize_t file_readv_compat(FAR struct file *filep,
102101
remaining -= nread;
103102
}
104103

104+
if (ntotal >= 0)
105+
{
106+
uio_advance(uio, ntotal);
107+
}
108+
105109
return ntotal;
106110
}
107111

@@ -130,7 +134,7 @@ static ssize_t file_readv_compat(FAR struct file *filep,
130134
*
131135
****************************************************************************/
132136

133-
ssize_t file_readv(FAR struct file *filep, FAR const struct uio *uio)
137+
ssize_t file_readv(FAR struct file *filep, FAR struct uio *uio)
134138
{
135139
FAR struct inode *inode;
136140
ssize_t ret = -EBADF;
@@ -204,11 +208,16 @@ ssize_t file_read(FAR struct file *filep, FAR void *buf, size_t nbytes)
204208
{
205209
struct iovec iov;
206210
struct uio uio;
211+
ssize_t ret;
207212

208213
iov.iov_base = buf;
209214
iov.iov_len = nbytes;
210-
uio.uio_iov = &iov;
211-
uio.uio_iovcnt = 1;
215+
ret = uio_init(&uio, &iov, 1);
216+
if (ret != 0)
217+
{
218+
return ret;
219+
}
220+
212221
return file_readv(filep, &uio);
213222
}
214223

@@ -251,9 +260,12 @@ ssize_t nx_readv(int fd, FAR const struct iovec *iov, int iovcnt)
251260

252261
/* Then let file_readv do all of the work. */
253262

254-
uio.uio_iov = iov;
255-
uio.uio_iovcnt = iovcnt;
256-
ret = file_readv(filep, &uio);
263+
ret = uio_init(&uio, iov, iovcnt);
264+
if (ret == 0)
265+
{
266+
ret = file_readv(filep, &uio);
267+
}
268+
257269
fs_putfilep(filep);
258270
return ret;
259271
}

0 commit comments

Comments
 (0)