Skip to content

Commit

Permalink
fixup: libc: implement read and write by async_read and async_write
Browse files Browse the repository at this point in the history
  • Loading branch information
atopia committed Sep 9, 2024
1 parent cb6333c commit 9decdce
Showing 1 changed file with 19 additions and 21 deletions.
40 changes: 19 additions & 21 deletions repos/libports/src/lib/libc/vfs_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ int Libc::Vfs_plugin::stat(char const *path, struct stat *buf)
return Errno(EFAULT);
}

typedef Vfs::Directory_service::Stat_result Result;
using Result = Vfs::Directory_service::Stat_result;

Vfs::Directory_service::Stat stat;

Expand Down Expand Up @@ -892,24 +892,24 @@ bool Libc::Vfs_plugin::async_read(File_descriptor *fd,
}

switch (out_result) {
case Result::READ_ERR_WOULD_BLOCK:
result_errno = EWOULDBLOCK;
result = -1;
break;
case Result::READ_ERR_INVALID:
result_errno = EINVAL;
result = -1;
break;
case Result::READ_ERR_IO:
result_errno = EIO;
result = -1;
case Result::READ_OK:
result_errno = 0;
result = out_count;
break;
case Result::READ_QUEUED:
/* handled above, so never reached */
break;
case Result::READ_ERR_WOULD_BLOCK:
result_errno = EWOULDBLOCK;
result = -1;
break;
case Result::READ_ERR_INVALID:
result_errno = EINVAL;
result = -1;
break;
case Result::READ_ERR_IO:
result_errno = EIO;
result = -1;
case Result::READ_OK:
result_errno = 0;
result = out_count;
break;
case Result::READ_QUEUED:
/* handled above, so never reached */
break;
}

return true;
Expand All @@ -936,7 +936,6 @@ ssize_t Libc::Vfs_plugin::read(File_descriptor *fd, void *buf,

Plugin::resume_all();

/* XXX double getting the handle is a bit unfortunate */
Vfs::Vfs_handle *handle = vfs_handle(fd);
handle->advance_seek(out_count);

Expand Down Expand Up @@ -972,7 +971,6 @@ bool Libc::Vfs_plugin::async_write(File_descriptor *fd,

if (fd->flags & O_NONBLOCK) {
out_result = handle->fs().write(handle, src, write_state.bytes_written);
// XXX are we supposed to advance seek even with a fixed-offset async write?
handle->advance_seek(write_state.bytes_written);
} else {
auto _fd_refers_to_continuous_file = [&]
Expand Down

0 comments on commit 9decdce

Please sign in to comment.