Skip to content

Commit 432e3b8

Browse files
aescolarDashingR
authored andcommitted
Revert "posix: device_io: implement pread() and pwrite()"
This reverts commit 2d72966. PR zephyrproject-rtos#73978 introduced a regression. Unfortunately this PR cannot be reverted without reverting also Let's revert both PRs to stabilize main again towards the 3.7 release. For more details on the issue see zephyrproject-rtos#75205 Signed-off-by: Alberto Escolar Piedras <[email protected]>
1 parent 4e3b1a0 commit 432e3b8

File tree

2 files changed

+17
-69
lines changed

2 files changed

+17
-69
lines changed

lib/os/fdtable.c

Lines changed: 13 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -308,62 +308,34 @@ int zvfs_alloc_fd(void *obj, const struct fd_op_vtable *vtable)
308308
return fd;
309309
}
310310

311-
static bool supports_pread_pwrite(uint32_t mode)
311+
static ssize_t zvfs_rw(int fd, void *buf, size_t sz, bool is_write)
312312
{
313-
switch (mode & ZVFS_MODE_IFMT) {
314-
case ZVFS_MODE_IFSHM:
315-
return true;
316-
default:
317-
return false;
318-
}
319-
}
320-
321-
static ssize_t zvfs_rw(int fd, void *buf, size_t sz, bool is_write, const size_t *from_offset)
322-
{
323-
bool prw;
324313
ssize_t res;
325-
const size_t *off;
326314

327315
if (_check_fd(fd) < 0) {
328316
return -1;
329317
}
330318

331319
(void)k_mutex_lock(&fdtable[fd].lock, K_FOREVER);
332320

333-
prw = supports_pread_pwrite(fdtable[fd].mode);
334-
if (from_offset != NULL && !prw) {
335-
/*
336-
* Seekable file types should support pread() / pwrite() and per-fd offset passing.
337-
* Otherwise, it's a bug.
338-
*/
339-
errno = ENOTSUP;
340-
res = -1;
341-
goto unlock;
342-
}
343-
344-
/* If there is no specified from_offset, then use the current offset of the fd */
345-
off = (from_offset == NULL) ? &fdtable[fd].offset : from_offset;
346-
347321
if (is_write) {
348-
if (fdtable[fd].vtable->write_offs == NULL) {
322+
if (fdtable[fd].vtable->write_offset == NULL) {
349323
res = -1;
350324
errno = EIO;
351325
} else {
352-
res = fdtable[fd].vtable->write_offs(fdtable[fd].obj, buf, sz, *off);
326+
res = fdtable[fd].vtable->write_offset(fdtable[fd].obj, buf, sz,
327+
fdtable[fd].offset);
353328
}
354329
} else {
355-
if (fdtable[fd].vtable->read_offs == NULL) {
330+
if (fdtable[fd].vtable->read == NULL) {
356331
res = -1;
357332
errno = EIO;
358333
} else {
359-
res = fdtable[fd].vtable->read_offs(fdtable[fd].obj, buf, sz, *off);
334+
res = fdtable[fd].vtable->read_offset(fdtable[fd].obj, buf, sz,
335+
fdtable[fd].offset);
360336
}
361337
}
362-
if (res > 0 && prw && from_offset == NULL) {
363-
/*
364-
* only update the fd offset when from_offset is not specified
365-
* See pread() / pwrite()
366-
*/
338+
if (res > 0) {
367339
fdtable[fd].offset += res;
368340
}
369341

@@ -373,14 +345,14 @@ static ssize_t zvfs_rw(int fd, void *buf, size_t sz, bool is_write, const size_t
373345
return res;
374346
}
375347

376-
ssize_t zvfs_read(int fd, void *buf, size_t sz, const size_t *from_offset)
348+
ssize_t zvfs_read(int fd, void *buf, size_t sz)
377349
{
378-
return zvfs_rw(fd, buf, sz, false, from_offset);
350+
return zvfs_rw(fd, buf, sz, false);
379351
}
380352

381-
ssize_t zvfs_write(int fd, const void *buf, size_t sz, const size_t *from_offset)
353+
ssize_t zvfs_write(int fd, const void *buf, size_t sz)
382354
{
383-
return zvfs_rw(fd, (void *)buf, sz, true, from_offset);
355+
return zvfs_rw(fd, (void *)buf, sz, true);
384356
}
385357

386358
int zvfs_close(int fd)
@@ -522,7 +494,7 @@ static ssize_t stdinout_read_vmeth(void *obj, void *buffer, size_t count)
522494
static ssize_t stdinout_write_vmeth(void *obj, const void *buffer, size_t count)
523495
{
524496
#if defined(CONFIG_BOARD_NATIVE_POSIX)
525-
return zvfs_write(1, buffer, count, NULL);
497+
return zvfs_write(1, buffer, count);
526498
#elif defined(CONFIG_NEWLIB_LIBC) || defined(CONFIG_ARCMWDT_LIBC)
527499
return z_impl_zephyr_write_stdout(buffer, count);
528500
#else

lib/posix/options/device_io.c

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
/* prototypes for external, not-yet-public, functions in fdtable.c or fs.c */
1616
int zvfs_close(int fd);
1717
int zvfs_open(const char *name, int flags);
18-
ssize_t zvfs_read(int fd, void *buf, size_t sz, size_t *from_offset);
19-
ssize_t zvfs_write(int fd, const void *buf, size_t sz, size_t *from_offset);
18+
ssize_t zvfs_read(int fd, void *buf, size_t sz);
19+
ssize_t zvfs_write(int fd, const void *buf, size_t sz);
2020

2121
int close(int fd)
2222
{
@@ -41,33 +41,9 @@ int poll(struct pollfd *fds, int nfds, int timeout)
4141
return zsock_poll(fds, nfds, timeout);
4242
}
4343

44-
ssize_t pread(int fd, void *buf, size_t count, off_t offset)
45-
{
46-
size_t off = (size_t)offset;
47-
48-
if (offset < 0) {
49-
errno = EINVAL;
50-
return -1;
51-
}
52-
53-
return zvfs_read(fd, buf, count, (size_t *)&off);
54-
}
55-
56-
ssize_t pwrite(int fd, void *buf, size_t count, off_t offset)
57-
{
58-
size_t off = (size_t)offset;
59-
60-
if (offset < 0) {
61-
errno = EINVAL;
62-
return -1;
63-
}
64-
65-
return zvfs_write(fd, buf, count, (size_t *)&off);
66-
}
67-
6844
ssize_t read(int fd, void *buf, size_t sz)
6945
{
70-
return zvfs_read(fd, buf, sz, NULL);
46+
return zvfs_read(fd, buf, sz);
7147
}
7248
#ifdef CONFIG_POSIX_DEVICE_IO_ALIAS_READ
7349
FUNC_ALIAS(read, _read, ssize_t);
@@ -81,7 +57,7 @@ int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struc
8157

8258
ssize_t write(int fd, const void *buf, size_t sz)
8359
{
84-
return zvfs_write(fd, buf, sz, NULL);
60+
return zvfs_write(fd, buf, sz);
8561
}
8662
#ifdef CONFIG_POSIX_DEVICE_IO_ALIAS_WRITE
8763
FUNC_ALIAS(write, _write, ssize_t);

0 commit comments

Comments
 (0)