vfs: make 'File_io_service::read_ready' const

... and replace pointer argument to const reference.

Issue #4706
This commit is contained in:
Norman Feske 2022-12-07 17:12:21 +01:00 committed by Christian Helmuth
parent 1b1a9ca95c
commit ca0d3757cc
38 changed files with 113 additions and 130 deletions

View File

@ -267,7 +267,7 @@ struct Vfs::Lxip_vfs_handle : Vfs::Vfs_handle
/**
* Check if the file attached to this handle is ready to read
*/
virtual bool read_ready() = 0;
virtual bool read_ready() const = 0;
virtual Read_result read(char *dst,
file_size count, file_size &out_count) = 0;
@ -312,7 +312,7 @@ struct Vfs::Lxip_vfs_file_handle final : Vfs::Lxip_vfs_handle
file->handles.remove(&file_le);
}
bool read_ready() override {
bool read_ready() const override {
return (file) ? file->poll() : false; }
Read_result read(char *dst, file_size count, file_size &out_count) override
@ -364,7 +364,7 @@ struct Vfs::Lxip_vfs_dir_handle final : Vfs::Lxip_vfs_handle
: Vfs::Lxip_vfs_handle(fs, alloc, status_flags),
dir(dir) { }
bool read_ready() override { return true; }
bool read_ready() const override { return true; }
Read_result read(char *dst, file_size count, file_size &out_count) override
{
@ -1202,7 +1202,7 @@ struct Vfs::Lxip_socket_handle final : Vfs::Lxip_vfs_handle
socket_dir(alloc, parent, sock)
{ }
bool read_ready() override { return true; }
bool read_ready() const override { return true; }
Read_result read(char *dst, file_size count, file_size &out_count) override
{
@ -1994,10 +1994,11 @@ class Vfs::Lxip_file_system : public Vfs::File_system,
return false;
}
bool read_ready(Vfs_handle *vfs_handle) override
bool read_ready(Vfs_handle const &vfs_handle) const override
{
Lxip_vfs_handle &handle =
*static_cast<Lxip_vfs_handle *>(vfs_handle);
Lxip_vfs_handle const &handle =
static_cast<Lxip_vfs_handle const &>(vfs_handle);
return handle.read_ready();
}

View File

@ -807,8 +807,7 @@ class Vfs::Rump_file_system : public File_system
return READ_ERR_INVALID;
}
bool read_ready(Vfs_handle *) override { return true; }
bool read_ready (Vfs_handle const &) const override { return true; }
bool write_ready(Vfs_handle const &) const override { return true; }
Ftruncate_result ftruncate(Vfs_handle *vfs_handle, file_size len) override

View File

@ -268,16 +268,21 @@ class Vfs_audit::File_system : public Vfs::File_system
return result;
}
bool read_ready(Vfs_handle *vfs_handle) override
bool read_ready(Vfs_handle const &vfs_handle) const override
{
Handle &h = *static_cast<Handle*>(vfs_handle);
h.sync_state();
return h.audit->fs().read_ready(h.audit);
Handle const &h = static_cast<Handle const &>(vfs_handle);
const_cast<Handle &>(h).sync_state();
return h.audit->fs().read_ready(*h.audit);
}
bool write_ready(Vfs_handle const &vfs_handle) const override
{
Handle const &h = static_cast<Handle const &>(vfs_handle);
const_cast<Handle &>(h).sync_state();
return h.audit->fs().write_ready(*h.audit);
}

View File

@ -2020,8 +2020,7 @@ class Vfs_cbe::Data_file_system : public Single_file_system
return SYNC_ERR_INVALID;
}
bool read_ready() override { return true; }
bool read_ready() const override { return true; }
bool write_ready() const override { return true; }
};
@ -2191,8 +2190,7 @@ class Vfs_cbe::Extend_file_system : public Vfs::Single_file_system
return WRITE_OK;
}
bool read_ready() override { return true; }
bool read_ready() const override { return true; }
bool write_ready() const override { return true; }
};
@ -2376,8 +2374,7 @@ class Vfs_cbe::Rekey_file_system : public Vfs::Single_file_system
return WRITE_OK;
}
bool read_ready() override { return true; }
bool read_ready() const override { return true; }
bool write_ready() const override { return true; }
};
@ -2561,8 +2558,7 @@ class Vfs_cbe::Deinitialize_file_system : public Vfs::Single_file_system
return WRITE_OK;
}
bool read_ready() override { return true; }
bool read_ready() const override { return true; }
bool write_ready() const override { return true; }
};
@ -2699,8 +2695,7 @@ class Vfs_cbe::Create_snapshot_file_system : public Vfs::Single_file_system
return WRITE_OK;
}
bool read_ready() override { return true; }
bool read_ready() const override { return true; }
bool write_ready() const override { return true; }
};
@ -2799,8 +2794,7 @@ class Vfs_cbe::Discard_snapshot_file_system : public Vfs::Single_file_system
return WRITE_ERR_IO;
}
bool read_ready() override { return true; }
bool read_ready() const override { return true; }
bool write_ready() const override { return true; }
};
@ -3065,7 +3059,7 @@ class Vfs_cbe::Snapshots_file_system : public Vfs::File_system
return SYNC_OK;
}
virtual bool read_ready() = 0;
virtual bool read_ready() const = 0;
};
@ -3159,7 +3153,7 @@ class Vfs_cbe::Snapshots_file_system : public Vfs::File_system
return WRITE_ERR_INVALID;
}
bool read_ready() override { return true; }
bool read_ready() const override { return true; }
};
struct Dir_snap_vfs_handle : Vfs::Vfs_handle
@ -3457,7 +3451,7 @@ class Vfs_cbe::Snapshots_file_system : public Vfs::File_system
return READ_ERR_IO;
}
bool read_ready(Vfs::Vfs_handle *) override
bool read_ready(Vfs::Vfs_handle const &) const override
{
return true;
}

View File

@ -123,8 +123,7 @@ class Vfs_cbe_crypto::Encrypt_file_system : public Vfs::Single_file_system
return WRITE_OK;
}
bool read_ready() override { return true; }
bool read_ready() const override { return true; }
bool write_ready() const override { return true; }
};
@ -257,8 +256,7 @@ class Vfs_cbe_crypto::Decrypt_file_system : public Vfs::Single_file_system
return WRITE_OK;
}
bool read_ready() override { return true; }
bool read_ready() const override { return true; }
bool write_ready() const override { return true; }
};
@ -512,7 +510,7 @@ class Vfs_cbe_crypto::Keys_file_system : public Vfs::File_system
return SYNC_OK;
}
virtual bool read_ready() = 0;
virtual bool read_ready() const = 0;
};
@ -606,7 +604,7 @@ class Vfs_cbe_crypto::Keys_file_system : public Vfs::File_system
return WRITE_ERR_INVALID;
}
bool read_ready() override { return true; }
bool read_ready() const override { return true; }
};
@ -892,7 +890,7 @@ class Vfs_cbe_crypto::Keys_file_system : public Vfs::File_system
return READ_ERR_IO;
}
bool read_ready(Vfs::Vfs_handle *) override
bool read_ready(Vfs::Vfs_handle const &) const override
{
return true;
}
@ -1006,8 +1004,7 @@ class Vfs_cbe_crypto::Management_file_system : public Vfs::Single_file_system
return WRITE_ERR_IO;
}
bool read_ready() override { return true; }
bool read_ready() const override { return true; }
bool write_ready() const override { return true; }
};

View File

@ -1369,8 +1369,7 @@ class Vfs_cbe_trust_anchor::Hashsum_file_system : public Vfs::Single_file_system
return WRITE_OK;
}
bool read_ready() override { return true; }
bool read_ready() const override { return true; }
bool write_ready() const override { return true; }
};
@ -1477,8 +1476,7 @@ class Vfs_cbe_trust_anchor::Generate_key_file_system : public Vfs::Single_file_s
return WRITE_ERR_IO;
}
bool read_ready() override { return true; }
bool read_ready() const override { return true; }
bool write_ready() const override { return false; }
};
@ -1607,8 +1605,7 @@ class Vfs_cbe_trust_anchor::Encrypt_file_system : public Vfs::Single_file_system
return WRITE_OK;
}
bool read_ready() override { return true; }
bool read_ready() const override { return true; }
bool write_ready() const override { return true; }
};
@ -1736,8 +1733,7 @@ class Vfs_cbe_trust_anchor::Decrypt_file_system : public Vfs::Single_file_system
return WRITE_OK;
}
bool read_ready() override { return true; }
bool read_ready() const override { return true; }
bool write_ready() const override { return true; }
};
@ -1858,8 +1854,7 @@ class Vfs_cbe_trust_anchor::Initialize_file_system : public Vfs::Single_file_sys
return WRITE_OK;
}
bool read_ready() override { return true; }
bool read_ready() const override { return true; }
bool write_ready() const override { return true; }
};

View File

@ -79,8 +79,7 @@ struct Vfs_gpu::File_system : Single_file_system
return WRITE_ERR_IO;
}
bool read_ready() override { return _complete; }
bool read_ready() const override { return _complete; }
bool write_ready() const override { return true; }
Id_space::Id id() const { return _elem.id(); }

View File

@ -284,7 +284,7 @@ class Vfs_import::File_system : public Vfs::File_system
file_size&) override {
return READ_ERR_INVALID; }
bool read_ready(Vfs_handle*) override {
bool read_ready(Vfs_handle const &) const override {
return true; }
bool write_ready(Vfs_handle const &) const override {

View File

@ -76,7 +76,7 @@ struct Vfs_pipe::Pipe_handle : Vfs::Vfs_handle, private Pipe_handle_registry_ele
file_size count,
file_size &out_count);
bool read_ready();
bool read_ready() const;
bool write_ready() const;
bool notify_read_ready();
};
@ -275,14 +275,16 @@ Vfs_pipe::Pipe_handle::write(const char *buf,
Vfs_pipe::Read_result
Vfs_pipe::Pipe_handle::read(char *buf,
file_size count,
file_size &out_count) {
return Pipe_handle::pipe.read(*this, buf, count, out_count); }
Vfs_pipe::Pipe_handle::read(char *buf, file_size count, file_size &out_count)
{
return Pipe_handle::pipe.read(*this, buf, count, out_count);
}
bool Vfs_pipe::Pipe_handle::read_ready() {
return !writer && !pipe.buffer.empty(); }
bool Vfs_pipe::Pipe_handle::read_ready() const
{
return !writer && !pipe.buffer.empty();
}
bool Vfs_pipe::Pipe_handle::write_ready() const
@ -599,9 +601,9 @@ class Vfs_pipe::File_system : public Vfs::File_system
return READ_ERR_INVALID;
}
bool read_ready(Vfs_handle *vfs_handle) override
bool read_ready(Vfs_handle const &vfs_handle) const override
{
if (Pipe_handle *handle = dynamic_cast<Pipe_handle*>(vfs_handle))
if (Pipe_handle const *handle = dynamic_cast<Pipe_handle const *>(&vfs_handle))
return handle->read_ready();
return true;
}

View File

@ -147,8 +147,7 @@ class Vfs_trace::Trace_buffer_file_system : public Single_file_system
return WRITE_ERR_INVALID;
}
bool read_ready() override { return true; }
bool read_ready() const override { return true; }
bool write_ready() const override { return false; }
};

View File

@ -106,8 +106,7 @@ class Vfs::Glyphs_file_system : public Vfs::Single_file_system
return WRITE_ERR_IO;
}
bool read_ready() override { return true; }
bool read_ready() const override { return true; }
bool write_ready() const override { return false; }
};

View File

@ -219,7 +219,7 @@ namespace Libc {
handle->fs().notify_read_ready(handle);
return handle->fs().read_ready(handle);
return handle->fs().read_ready(*handle);
}
bool write_ready_from_kernel(File_descriptor *fd)
@ -2721,7 +2721,7 @@ int Libc::Vfs_plugin::select(int nfds,
if (!handle) continue;
if (fd_in_readfds) {
if (handle->fs().read_ready(handle)) {
if (handle->fs().read_ready(*handle)) {
FD_SET(fd, readfds);
++nready;
} else {

View File

@ -777,7 +777,7 @@ class Fatfs::File_system : public Vfs::File_system
FTRUNCATE_OK : FTRUNCATE_ERR_NO_PERM;
}
bool read_ready(Vfs_handle *) override { return true; }
bool read_ready(Vfs_handle const &) const override { return true; }
bool write_ready(Vfs_handle const &) const override
{

View File

@ -94,8 +94,7 @@ class Jitterentropy_file_system : public Vfs::Single_file_system
return WRITE_ERR_IO;
}
bool read_ready() override { return true; }
bool read_ready() const override { return true; }
bool write_ready() const override { return false; }
};

View File

@ -77,9 +77,10 @@ class Libusb_file_system : public Vfs::Single_file_system
libusb_genode_usb_connection(&_usb_connection);
}
bool read_ready() override
bool read_ready() const override
{
return _usb_connection.source()->ack_avail();
auto &nonconst_this = const_cast<Libusb_vfs_handle &>(*this);
return nonconst_this._usb_connection.source()->ack_avail();
}
Read_result read(char *dst, Vfs::file_size count,

View File

@ -426,8 +426,7 @@ struct Lwip::Socket_dir : Lwip::Directory
char const *src, file_size count,
file_size &out_count) = 0;
virtual bool read_ready(Lwip_file_handle&) = 0;
virtual bool read_ready (Lwip_file_handle const &) const = 0;
virtual bool write_ready(Lwip_file_handle const &) const = 0;
/**
@ -891,7 +890,7 @@ class Lwip::Udp_socket_dir final :
** Socket_dir interface **
**************************/
bool read_ready(Lwip_file_handle &handle) override
bool read_ready(Lwip_file_handle const &handle) const override
{
switch (handle.kind) {
case Lwip_file_handle::DATA:
@ -1254,7 +1253,7 @@ class Lwip::Tcp_socket_dir final :
** Socket_dir interface **
**************************/
bool read_ready(Lwip_file_handle &handle) override
bool read_ready(Lwip_file_handle const &handle) const override
{
switch (handle.kind) {
case Lwip_file_handle::DATA:
@ -2111,12 +2110,13 @@ class Lwip::File_system final : public Vfs::File_system, public Lwip::Directory,
return false;
}
bool read_ready(Vfs_handle *vfs_handle) override
bool read_ready(Vfs_handle const &vfs_handle) const override
{
if (Lwip_file_handle *handle = dynamic_cast<Lwip_file_handle*>(vfs_handle)) {
if (handle->socket)
return handle->socket->read_ready(*handle);
}
Lwip_file_handle const * const handle_ptr =
dynamic_cast<Lwip_file_handle const *>(&vfs_handle);
if (handle_ptr && handle_ptr->socket)
return handle_ptr->socket->read_ready(*handle_ptr);
/*
* in this case the polled file is a 'new_socket'

View File

@ -285,7 +285,7 @@ struct Vfs::Oss_file_system::Audio
_in->overrun_sigh(sigh);
}
bool read_ready()
bool read_ready() const
{
return _info.ifrag_bytes > 0;
}
@ -681,7 +681,7 @@ class Vfs::Oss_file_system::Data_file_system : public Single_file_system
return result;
}
bool read_ready() override
bool read_ready() const override
{
return _audio.read_ready();
}

View File

@ -965,12 +965,12 @@ class Vfs::Dir_file_system : public File_system
return FTRUNCATE_ERR_NO_PERM;
}
bool read_ready(Vfs_handle *handle) override
bool read_ready(Vfs_handle const &handle) const override
{
if (&handle->fs() == this)
if (&handle.fs() == this)
return true;
return handle->fs().read_ready(handle);
return handle.fs().read_ready(handle);
}
bool write_ready(Vfs_handle const &handle) const override

View File

@ -67,7 +67,7 @@ struct Vfs::File_io_service : Interface
/**
* Return true if the handle has readable data
*/
virtual bool read_ready(Vfs_handle *) = 0;
virtual bool read_ready(Vfs_handle const &) const = 0;
/**
* Return true if the handle might accept a write operation

View File

@ -72,8 +72,7 @@ class Vfs::Readonly_value_file_system : public Vfs::Single_file_system
return WRITE_ERR_IO;
}
bool read_ready() override { return true; }
bool read_ready() const override { return true; }
bool write_ready() const override { return false; }
};

View File

@ -48,7 +48,7 @@ class Vfs::Single_file_system : public File_system
return SYNC_OK;
}
virtual bool read_ready() = 0;
virtual bool read_ready() const = 0;
virtual bool write_ready() const = 0;
@ -132,8 +132,7 @@ class Vfs::Single_file_system : public File_system
return WRITE_ERR_INVALID;
}
bool read_ready() override { return true; }
bool read_ready() const override { return true; }
bool write_ready() const override { return true; }
};
@ -281,15 +280,12 @@ class Vfs::Single_file_system : public File_system
return WRITE_ERR_INVALID;
}
bool read_ready(Vfs_handle *vfs_handle) override
bool read_ready(Vfs_handle const &vfs_handle) const override
{
Single_vfs_handle *handle =
static_cast<Single_vfs_handle*>(vfs_handle);
Single_vfs_handle const &handle =
static_cast<Single_vfs_handle const &>(vfs_handle);
if (handle)
return handle->read_ready();
return false;
return handle.read_ready();
}
bool write_ready(Vfs_handle const &vfs_handle) const override

View File

@ -84,8 +84,7 @@ class Vfs::Value_file_system : public Vfs::Single_file_system
return WRITE_OK;
}
bool read_ready() override { return true; }
bool read_ready() const override { return true; }
bool write_ready() const override { return true; }
private:

View File

@ -337,8 +337,7 @@ class Vfs::Block_file_system::Data_file_system : public Single_file_system
return SYNC_OK;
}
bool read_ready() override { return true; }
bool read_ready() const override { return true; }
bool write_ready() const override { return true; }
};

View File

@ -67,8 +67,7 @@ class Vfs_capture::Data_file_system : public Single_file_system
_capture(capture), _capture_ds(capture_ds)
{ }
bool read_ready() override { return true; }
bool read_ready() const override { return true; }
bool write_ready() const override { return true; }
Read_result read(char *dst, file_size count,

View File

@ -953,11 +953,11 @@ class Vfs::Fs_file_system : public File_system, private Remote_io
return result;
}
bool read_ready(Vfs_handle *vfs_handle) override
bool read_ready(Vfs_handle const &vfs_handle) const override
{
Fs_vfs_handle *handle = static_cast<Fs_vfs_handle *>(vfs_handle);
Fs_vfs_handle const &handle = static_cast<Fs_vfs_handle const &>(vfs_handle);
return handle->read_ready_state == Handle_state::Read_ready_state::READY;
return handle.read_ready_state == Handle_state::Read_ready_state::READY;
}
bool write_ready(Vfs_handle const &) const override

View File

@ -89,8 +89,7 @@ class Vfs::Inline_file_system : public Single_file_system
return WRITE_ERR_INVALID;
}
bool read_ready() override { return true; }
bool read_ready() const override { return true; }
bool write_ready() const override { return false; }
};

View File

@ -126,8 +126,7 @@ class Vfs::Log_file_system : public Single_file_system
return WRITE_OK;
}
bool read_ready() override { return false; }
bool read_ready() const override { return false; }
bool write_ready() const override { return true; }
Sync_result sync() override

View File

@ -53,8 +53,7 @@ struct Vfs::Null_file_system : Single_file_system
return WRITE_OK;
}
bool read_ready() override { return false; }
bool read_ready() const override { return false; }
bool write_ready() const override { return true; }
};

View File

@ -966,8 +966,7 @@ class Vfs::Ram_file_system : public Vfs::File_system
return handle->node.complete_read(dst, count, handle->seek(), out_count);
}
bool read_ready(Vfs_handle *) override { return true; }
bool read_ready (Vfs_handle const &) const override { return true; }
bool write_ready(Vfs_handle const &) const override { return true; }
Ftruncate_result ftruncate(Vfs_handle * const vfs_handle, file_size len) override

View File

@ -112,8 +112,7 @@ class Vfs::Rom_file_system : public Single_file_system
return WRITE_ERR_INVALID;
}
bool read_ready() override { return true; }
bool read_ready() const override { return true; }
bool write_ready() const override { return false; }
};

View File

@ -81,8 +81,7 @@ class Vfs::Rtc_file_system : public Single_file_system
return WRITE_ERR_IO;
}
bool read_ready() override { return true; }
bool read_ready() const override { return true; }
bool write_ready() const override { return false; }
};

View File

@ -53,8 +53,7 @@ class Vfs::Symlink_file_system : public Single_file_system
file_size&) override {
return WRITE_ERR_INVALID; }
bool read_ready() override { return true; }
bool read_ready() const override { return true; }
bool write_ready() const override { return false; }
};

View File

@ -131,8 +131,13 @@ class Vfs::Nic_file_system::Nic_vfs_handle : public Single_vfs_handle
* Vfs_handle interface *
************************/
bool read_ready() override {
return _link_state && _nic.rx()->packet_avail() && _nic.rx()->ready_to_ack(); }
bool read_ready() const override
{
auto &nonconst_this = const_cast<Nic_vfs_handle &>(*this);
auto &rx = *nonconst_this._nic.rx();
return _link_state && rx.packet_avail() && rx.ready_to_ack();
}
bool write_ready() const override
{

View File

@ -121,8 +121,13 @@ class Vfs::Uplink_file_system::Uplink_vfs_handle : public Single_vfs_handle,
* Vfs_handle interface *
************************/
bool read_ready() override {
return _drv_link_state && _conn->rx()->packet_avail() && _conn->rx()->ready_to_ack(); }
bool read_ready() const override
{
auto &nonconst_this = const_cast<Uplink_vfs_handle &>(*this);
auto &rx = *nonconst_this._conn->rx();
return _drv_link_state && rx.packet_avail() && rx.ready_to_ack();
}
bool write_ready() const override
{

View File

@ -775,8 +775,7 @@ class Vfs::Tar_file_system : public File_system
return FTRUNCATE_ERR_NO_PERM;
}
bool read_ready(Vfs_handle *) override { return true; }
bool read_ready (Vfs_handle const &) const override { return true; }
bool write_ready(Vfs_handle const &) const override { return false; }
};

View File

@ -134,7 +134,7 @@ class Vfs::Terminal_file_system::Data_file_system : public Single_file_system
_raw(raw)
{ }
bool read_ready() override {
bool read_ready() const override {
return !_read_buffer.empty(); }
bool write_ready() const override { return true; }

View File

@ -81,8 +81,7 @@ struct Vfs::Zero_file_system : Single_file_system
return WRITE_OK;
}
bool read_ready() override { return true; }
bool read_ready() const override { return true; }
bool write_ready() const override { return true; }
};

View File

@ -351,7 +351,7 @@ class Vfs_server::Io_node : public Vfs_server::Node,
{
_read_ready_state = Read_ready_state::REQUESTED;
if (_handle.fs().read_ready(&_handle)) {
if (_handle.fs().read_ready(_handle)) {
/* if the handle is ready, send a packet back immediately */
read_ready_response();
} else {