2014-04-07 16:15:40 +02:00
|
|
|
/*
|
|
|
|
* \brief Adapter from Genode 'File_system' session to VFS
|
|
|
|
* \author Norman Feske
|
2017-02-01 21:07:14 +01:00
|
|
|
* \author Emery Hemingway
|
|
|
|
* \author Christian Helmuth
|
2014-04-07 16:15:40 +02:00
|
|
|
* \date 2011-02-17
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-01 21:07:14 +01:00
|
|
|
* Copyright (C) 2012-2017 Genode Labs GmbH
|
2014-04-07 16:15:40 +02:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
|
|
|
* under the terms of the GNU General Public License version 2.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _INCLUDE__VFS__FS_FILE_SYSTEM_H_
|
|
|
|
#define _INCLUDE__VFS__FS_FILE_SYSTEM_H_
|
|
|
|
|
|
|
|
/* Genode includes */
|
|
|
|
#include <base/allocator_avl.h>
|
2017-02-01 21:07:14 +01:00
|
|
|
#include <base/id_space.h>
|
2014-04-07 16:15:40 +02:00
|
|
|
#include <file_system_session/connection.h>
|
|
|
|
|
2017-02-01 21:07:14 +01:00
|
|
|
|
2014-04-07 16:15:40 +02:00
|
|
|
namespace Vfs { class Fs_file_system; }
|
|
|
|
|
|
|
|
|
|
|
|
class Vfs::Fs_file_system : public File_system
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
2016-05-25 15:47:22 +02:00
|
|
|
|
2014-04-07 16:15:40 +02:00
|
|
|
/*
|
|
|
|
* Lock used to serialize the interaction with the packet stream of the
|
|
|
|
* file-system session.
|
|
|
|
*
|
|
|
|
* XXX Once, we change the VFS file-system interface to use
|
|
|
|
* asynchronous read/write operations, we can possibly remove it.
|
|
|
|
*/
|
|
|
|
Lock _lock;
|
|
|
|
|
2016-05-25 15:47:22 +02:00
|
|
|
Genode::Env &_env;
|
|
|
|
Genode::Allocator_avl _fs_packet_alloc;
|
2017-02-01 21:07:14 +01:00
|
|
|
Io_response_handler &_io_handler;
|
2014-04-07 16:15:40 +02:00
|
|
|
|
2015-10-07 18:31:52 +02:00
|
|
|
typedef Genode::String<64> Label_string;
|
|
|
|
Label_string _label;
|
2014-04-07 16:15:40 +02:00
|
|
|
|
2015-10-07 18:31:52 +02:00
|
|
|
typedef Genode::String<::File_system::MAX_NAME_LEN> Root_string;
|
|
|
|
Root_string _root;
|
2014-04-07 16:15:40 +02:00
|
|
|
|
|
|
|
::File_system::Connection _fs;
|
|
|
|
|
2017-02-01 21:07:14 +01:00
|
|
|
struct Fs_vfs_handle;
|
|
|
|
|
|
|
|
struct Handle_space : Genode::Id_space<Fs_vfs_handle>
|
|
|
|
{
|
|
|
|
struct Id : Genode::Id_space<Fs_vfs_handle>::Id
|
|
|
|
{
|
|
|
|
Id(unsigned long v) { value = v; }
|
|
|
|
Id(::File_system::Node_handle h) { value = h.value; }
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
Handle_space _handle_space;
|
|
|
|
|
|
|
|
struct Handle_state
|
2014-04-07 16:15:40 +02:00
|
|
|
{
|
2017-02-01 21:07:14 +01:00
|
|
|
enum class Read_ready_state { IDLE, PENDING, READY };
|
|
|
|
Read_ready_state read_ready_state = Read_ready_state::IDLE;
|
2014-04-07 16:15:40 +02:00
|
|
|
|
2017-02-01 21:07:14 +01:00
|
|
|
enum class Queued_state { IDLE, QUEUED, ACK };
|
|
|
|
Queued_state queued_read_state = Queued_state::IDLE;
|
|
|
|
Queued_state queued_write_state = Queued_state::IDLE;
|
|
|
|
|
|
|
|
::File_system::Packet_descriptor queued_read_packet;
|
|
|
|
::File_system::Packet_descriptor queued_write_packet;
|
|
|
|
};
|
2014-04-07 16:15:40 +02:00
|
|
|
|
2017-02-01 21:07:14 +01:00
|
|
|
struct Fs_vfs_handle : Vfs_handle, Handle_space::Element, Handle_state
|
|
|
|
{
|
|
|
|
Handle_space::Id const id;
|
2014-04-07 16:15:40 +02:00
|
|
|
|
2017-02-01 21:07:14 +01:00
|
|
|
Fs_vfs_handle(File_system &fs, Allocator &alloc, int status_flags,
|
|
|
|
Handle_space &space, Handle_space::Id id)
|
|
|
|
:
|
|
|
|
Vfs_handle(fs, fs, alloc, status_flags),
|
|
|
|
Handle_space::Element(*this, space, id),
|
|
|
|
id(id)
|
|
|
|
{ }
|
2014-04-07 16:15:40 +02:00
|
|
|
|
2017-02-01 21:07:14 +01:00
|
|
|
::File_system::File_handle file_handle() const { return id.value; }
|
2014-04-07 16:15:40 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper for managing the lifetime of temporary open node handles
|
|
|
|
*/
|
2017-02-01 21:07:14 +01:00
|
|
|
struct Fs_handle_guard : Fs_vfs_handle
|
2014-04-07 16:15:40 +02:00
|
|
|
{
|
2017-02-01 21:07:14 +01:00
|
|
|
::File_system::Session &_fs_session;
|
|
|
|
::File_system::Node_handle _fs_handle;
|
|
|
|
|
|
|
|
Fs_handle_guard(File_system &fs,
|
|
|
|
::File_system::Session &fs_session,
|
|
|
|
::File_system::Node_handle fs_handle,
|
|
|
|
Handle_space &space)
|
|
|
|
:
|
|
|
|
Fs_vfs_handle(fs, *(Allocator*)nullptr, 0, space, Handle_space::Id(fs_handle)),
|
|
|
|
_fs_session(fs_session), _fs_handle(fs_handle)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
~Fs_handle_guard() { _fs_session.close(_fs_handle); }
|
|
|
|
};
|
2014-04-07 16:15:40 +02:00
|
|
|
|
2017-02-01 21:07:14 +01:00
|
|
|
struct Post_signal_hook : Genode::Entrypoint::Post_signal_hook
|
|
|
|
{
|
|
|
|
Genode::Entrypoint &_ep;
|
|
|
|
Io_response_handler &_io_handler;
|
|
|
|
Vfs_handle::Context *_context = nullptr;
|
|
|
|
|
|
|
|
Post_signal_hook(Genode::Entrypoint &ep,
|
|
|
|
Io_response_handler &io_handler)
|
|
|
|
: _ep(ep), _io_handler(io_handler) { }
|
|
|
|
|
|
|
|
void arm(Vfs_handle::Context *context)
|
|
|
|
{
|
|
|
|
_context = context;
|
|
|
|
_ep.schedule_post_signal_hook(this);
|
|
|
|
}
|
2014-04-07 16:15:40 +02:00
|
|
|
|
2017-02-01 21:07:14 +01:00
|
|
|
void function() override
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* XXX The current implementation executes the post signal hook
|
|
|
|
* for the last armed context only. When changing this,
|
|
|
|
* beware that the called handle_io_response() may change
|
|
|
|
* this object in a signal handler.
|
|
|
|
*/
|
|
|
|
|
|
|
|
_io_handler.handle_io_response(_context);
|
|
|
|
_context = nullptr;
|
|
|
|
}
|
2014-04-07 16:15:40 +02:00
|
|
|
};
|
|
|
|
|
2017-02-01 21:07:14 +01:00
|
|
|
Post_signal_hook _post_signal_hook { _env.ep(), _io_handler };
|
|
|
|
|
|
|
|
file_size _read(Fs_vfs_handle &handle, void *buf,
|
2014-09-09 14:32:31 +02:00
|
|
|
file_size const count, file_size const seek_offset)
|
2014-04-07 16:15:40 +02:00
|
|
|
{
|
|
|
|
::File_system::Session::Tx::Source &source = *_fs.tx();
|
2017-02-01 21:07:14 +01:00
|
|
|
using ::File_system::Packet_descriptor;
|
2014-04-07 16:15:40 +02:00
|
|
|
|
2014-09-09 14:32:31 +02:00
|
|
|
file_size const max_packet_size = source.bulk_buffer_size() / 2;
|
|
|
|
file_size const clipped_count = min(max_packet_size, count);
|
2014-04-07 16:15:40 +02:00
|
|
|
|
2017-02-01 21:07:14 +01:00
|
|
|
/* XXX check if alloc_packet() and submit_packet() will succeed! */
|
|
|
|
|
|
|
|
Packet_descriptor const packet_in(source.alloc_packet(clipped_count),
|
|
|
|
handle.file_handle(),
|
|
|
|
Packet_descriptor::READ,
|
|
|
|
clipped_count,
|
|
|
|
seek_offset);
|
2014-04-07 16:15:40 +02:00
|
|
|
|
|
|
|
/* pass packet to server side */
|
|
|
|
source.submit_packet(packet_in);
|
|
|
|
|
2017-02-01 21:07:14 +01:00
|
|
|
/* wait until packet was acknowledged */
|
|
|
|
handle.queued_read_state = Handle_state::Queued_state::QUEUED;
|
|
|
|
do {
|
|
|
|
_env.ep().wait_and_dispatch_one_signal();
|
|
|
|
} while (handle.queued_read_state != Handle_state::Queued_state::ACK);
|
|
|
|
|
2014-04-07 16:15:40 +02:00
|
|
|
/* obtain result packet descriptor with updated status info */
|
2017-02-01 21:07:14 +01:00
|
|
|
Packet_descriptor const packet_out = handle.queued_read_packet;
|
|
|
|
|
|
|
|
handle.queued_read_state = Handle_state::Queued_state::IDLE;
|
|
|
|
handle.queued_read_packet = Packet_descriptor();
|
|
|
|
|
|
|
|
if (!packet_out.succeeded()) {
|
|
|
|
/* could be EOF or a real error */
|
|
|
|
::File_system::Status status = _fs.status(handle.file_handle());
|
|
|
|
if (seek_offset < status.size)
|
|
|
|
Genode::warning("unexpected failure on file-system read");
|
|
|
|
}
|
2014-04-07 16:15:40 +02:00
|
|
|
|
2014-09-09 14:32:31 +02:00
|
|
|
file_size const read_num_bytes = min(packet_out.length(), count);
|
2014-04-07 16:15:40 +02:00
|
|
|
|
|
|
|
memcpy(buf, source.packet_content(packet_out), read_num_bytes);
|
|
|
|
|
|
|
|
source.release_packet(packet_out);
|
|
|
|
|
|
|
|
return read_num_bytes;
|
|
|
|
}
|
|
|
|
|
2017-02-01 21:07:14 +01:00
|
|
|
file_size _write(Fs_vfs_handle &handle,
|
2014-09-09 14:32:31 +02:00
|
|
|
const char *buf, file_size count, file_size seek_offset)
|
2014-04-07 16:15:40 +02:00
|
|
|
{
|
|
|
|
::File_system::Session::Tx::Source &source = *_fs.tx();
|
2017-02-01 21:07:14 +01:00
|
|
|
using ::File_system::Packet_descriptor;
|
2014-04-07 16:15:40 +02:00
|
|
|
|
2014-09-09 14:32:31 +02:00
|
|
|
file_size const max_packet_size = source.bulk_buffer_size() / 2;
|
2014-04-07 16:15:40 +02:00
|
|
|
count = min(max_packet_size, count);
|
|
|
|
|
2017-02-01 21:07:14 +01:00
|
|
|
/* XXX check if alloc_packet() and submit_packet() will succeed! */
|
2014-04-07 16:15:40 +02:00
|
|
|
|
2017-02-01 21:07:14 +01:00
|
|
|
Packet_descriptor packet_in(source.alloc_packet(count),
|
|
|
|
handle.file_handle(),
|
|
|
|
Packet_descriptor::WRITE,
|
|
|
|
count,
|
|
|
|
seek_offset);
|
|
|
|
|
|
|
|
memcpy(source.packet_content(packet_in), buf, count);
|
2014-04-07 16:15:40 +02:00
|
|
|
|
|
|
|
/* pass packet to server side */
|
2017-02-01 21:07:14 +01:00
|
|
|
source.submit_packet(packet_in);
|
|
|
|
|
|
|
|
/* wait until packet was acknowledged */
|
|
|
|
handle.queued_write_state = Handle_state::Queued_state::QUEUED;
|
|
|
|
do {
|
|
|
|
_env.ep().wait_and_dispatch_one_signal();
|
|
|
|
} while (handle.queued_write_state != Handle_state::Queued_state::ACK);
|
2016-04-04 15:00:43 +02:00
|
|
|
|
|
|
|
/* obtain result packet descriptor with updated status info */
|
2017-02-01 21:07:14 +01:00
|
|
|
Packet_descriptor const packet_out = handle.queued_write_packet;
|
2014-04-07 16:15:40 +02:00
|
|
|
|
2017-02-01 21:07:14 +01:00
|
|
|
handle.queued_write_state = Handle_state::Queued_state::IDLE;
|
|
|
|
handle.queued_write_packet = Packet_descriptor();
|
2014-04-07 16:15:40 +02:00
|
|
|
|
2016-04-04 15:00:43 +02:00
|
|
|
file_size const write_num_bytes = min(packet_out.length(), count);
|
|
|
|
|
2017-02-01 21:07:14 +01:00
|
|
|
source.release_packet(packet_out);
|
2014-04-07 16:15:40 +02:00
|
|
|
|
2016-04-04 15:00:43 +02:00
|
|
|
return write_num_bytes;
|
2014-04-07 16:15:40 +02:00
|
|
|
}
|
|
|
|
|
2017-02-01 21:07:14 +01:00
|
|
|
void _handle_ack()
|
|
|
|
{
|
|
|
|
::File_system::Session::Tx::Source &source = *_fs.tx();
|
|
|
|
using ::File_system::Packet_descriptor;
|
|
|
|
|
|
|
|
while (source.ack_avail()) {
|
|
|
|
|
|
|
|
Packet_descriptor const packet = source.get_acked_packet();
|
|
|
|
|
|
|
|
Handle_space::Id const id(packet.handle());
|
|
|
|
|
|
|
|
_handle_space.apply<Fs_vfs_handle>(id, [&] (Fs_vfs_handle &handle)
|
|
|
|
{
|
|
|
|
switch (packet.operation()) {
|
|
|
|
case Packet_descriptor::READ_READY:
|
|
|
|
handle.read_ready_state = Handle_state::Read_ready_state::READY;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Packet_descriptor::READ:
|
|
|
|
handle.queued_read_packet = packet;
|
|
|
|
handle.queued_read_state = Handle_state::Queued_state::ACK;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Packet_descriptor::WRITE:
|
|
|
|
handle.queued_write_packet = packet;
|
|
|
|
handle.queued_write_state = Handle_state::Queued_state::ACK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
_post_signal_hook.arm(handle.context);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Genode::Signal_handler<Fs_file_system> _ack_handler {
|
|
|
|
_env.ep(), *this, &Fs_file_system::_handle_ack };
|
|
|
|
|
2014-04-07 16:15:40 +02:00
|
|
|
public:
|
|
|
|
|
2017-02-01 21:07:14 +01:00
|
|
|
Fs_file_system(Genode::Env &env,
|
|
|
|
Genode::Allocator &alloc,
|
|
|
|
Genode::Xml_node config,
|
|
|
|
Io_response_handler &io_handler)
|
2014-04-07 16:15:40 +02:00
|
|
|
:
|
2016-05-25 15:47:22 +02:00
|
|
|
_env(env),
|
|
|
|
_fs_packet_alloc(&alloc),
|
2017-02-01 21:07:14 +01:00
|
|
|
_io_handler(io_handler),
|
2015-10-07 18:31:52 +02:00
|
|
|
_label(config.attribute_value("label", Label_string())),
|
|
|
|
_root( config.attribute_value("root", Root_string())),
|
2017-01-31 16:38:23 +01:00
|
|
|
_fs(env, _fs_packet_alloc,
|
2015-10-07 18:31:52 +02:00
|
|
|
_label.string(), _root.string(),
|
2017-01-31 16:38:23 +01:00
|
|
|
config.attribute_value("writeable", true),
|
|
|
|
::File_system::DEFAULT_TX_BUF_SIZE)
|
2017-02-01 21:07:14 +01:00
|
|
|
{
|
|
|
|
_fs.sigh_ack_avail(_ack_handler);
|
|
|
|
}
|
2014-04-07 16:15:40 +02:00
|
|
|
|
|
|
|
/*********************************
|
|
|
|
** Directory-service interface **
|
|
|
|
*********************************/
|
|
|
|
|
|
|
|
Dataspace_capability dataspace(char const *path) override
|
|
|
|
{
|
|
|
|
Lock::Guard guard(_lock);
|
|
|
|
|
|
|
|
Absolute_path dir_path(path);
|
|
|
|
dir_path.strip_last_element();
|
|
|
|
|
|
|
|
Absolute_path file_name(path);
|
|
|
|
file_name.keep_only_last_element();
|
|
|
|
|
|
|
|
Ram_dataspace_capability ds_cap;
|
|
|
|
char *local_addr = 0;
|
|
|
|
|
|
|
|
try {
|
|
|
|
::File_system::Dir_handle dir = _fs.dir(dir_path.base(),
|
|
|
|
false);
|
2017-02-01 21:07:14 +01:00
|
|
|
Fs_handle_guard dir_guard(*this, _fs, dir, _handle_space);
|
2014-04-07 16:15:40 +02:00
|
|
|
|
|
|
|
::File_system::File_handle file =
|
|
|
|
_fs.file(dir, file_name.base() + 1,
|
|
|
|
::File_system::READ_ONLY, false);
|
2017-02-01 21:07:14 +01:00
|
|
|
Fs_handle_guard file_guard(*this, _fs, file, _handle_space);
|
2014-04-07 16:15:40 +02:00
|
|
|
|
|
|
|
::File_system::Status status = _fs.status(file);
|
|
|
|
|
|
|
|
Ram_dataspace_capability ds_cap =
|
2016-05-25 15:47:22 +02:00
|
|
|
_env.ram().alloc(status.size);
|
2014-04-07 16:15:40 +02:00
|
|
|
|
2016-05-25 15:47:22 +02:00
|
|
|
local_addr = _env.rm().attach(ds_cap);
|
2014-04-07 16:15:40 +02:00
|
|
|
|
|
|
|
::File_system::Session::Tx::Source &source = *_fs.tx();
|
2014-09-09 14:32:31 +02:00
|
|
|
file_size const max_packet_size = source.bulk_buffer_size() / 2;
|
2014-04-07 16:15:40 +02:00
|
|
|
|
2014-09-09 14:32:31 +02:00
|
|
|
for (file_size seek_offset = 0; seek_offset < status.size;
|
2014-04-07 16:15:40 +02:00
|
|
|
seek_offset += max_packet_size) {
|
|
|
|
|
2014-09-09 14:32:31 +02:00
|
|
|
file_size const count = min(max_packet_size, status.size -
|
|
|
|
seek_offset);
|
2014-04-07 16:15:40 +02:00
|
|
|
|
2017-02-01 21:07:14 +01:00
|
|
|
_read(file_guard, local_addr + seek_offset, count, seek_offset);
|
2014-04-07 16:15:40 +02:00
|
|
|
}
|
|
|
|
|
2016-05-25 15:47:22 +02:00
|
|
|
_env.rm().detach(local_addr);
|
2014-04-07 16:15:40 +02:00
|
|
|
|
|
|
|
return ds_cap;
|
|
|
|
} catch(...) {
|
2016-05-25 15:47:22 +02:00
|
|
|
_env.rm().detach(local_addr);
|
|
|
|
_env.ram().free(ds_cap);
|
2014-04-07 16:15:40 +02:00
|
|
|
return Dataspace_capability();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void release(char const *path, Dataspace_capability ds_cap) override
|
|
|
|
{
|
2015-10-07 19:15:47 +02:00
|
|
|
if (ds_cap.valid())
|
2016-05-25 15:47:22 +02:00
|
|
|
_env.ram().free(static_cap_cast<Genode::Ram_dataspace>(ds_cap));
|
2014-04-07 16:15:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Stat_result stat(char const *path, Stat &out) override
|
|
|
|
{
|
|
|
|
::File_system::Status status;
|
|
|
|
|
|
|
|
try {
|
|
|
|
::File_system::Node_handle node = _fs.node(path);
|
2017-02-01 21:07:14 +01:00
|
|
|
Fs_handle_guard node_guard(*this, _fs, node, _handle_space);
|
2014-04-07 16:15:40 +02:00
|
|
|
status = _fs.status(node);
|
|
|
|
}
|
2016-03-17 15:09:07 +01:00
|
|
|
catch (::File_system::Lookup_failed) { return STAT_ERR_NO_ENTRY; }
|
|
|
|
catch (::File_system::Out_of_metadata) { return STAT_ERR_NO_PERM; }
|
2014-04-07 16:15:40 +02:00
|
|
|
|
2016-06-22 15:38:42 +02:00
|
|
|
out = Stat();
|
2014-04-07 16:15:40 +02:00
|
|
|
|
|
|
|
out.size = status.size;
|
|
|
|
out.mode = STAT_MODE_FILE | 0777;
|
|
|
|
|
2016-05-11 18:21:47 +02:00
|
|
|
if (status.symlink())
|
2014-04-07 16:15:40 +02:00
|
|
|
out.mode = STAT_MODE_SYMLINK | 0777;
|
|
|
|
|
2016-05-11 18:21:47 +02:00
|
|
|
if (status.directory())
|
2014-04-07 16:15:40 +02:00
|
|
|
out.mode = STAT_MODE_DIRECTORY | 0777;
|
|
|
|
|
|
|
|
out.uid = 0;
|
|
|
|
out.gid = 0;
|
2016-03-17 15:09:07 +01:00
|
|
|
out.inode = status.inode;
|
|
|
|
out.device = (Genode::addr_t)this;
|
2014-04-07 16:15:40 +02:00
|
|
|
return STAT_OK;
|
|
|
|
}
|
|
|
|
|
2014-09-09 14:32:31 +02:00
|
|
|
Dirent_result dirent(char const *path, file_offset index, Dirent &out) override
|
2014-04-07 16:15:40 +02:00
|
|
|
{
|
|
|
|
Lock::Guard guard(_lock);
|
|
|
|
|
2017-02-01 21:07:14 +01:00
|
|
|
using ::File_system::Directory_entry;
|
2014-04-07 16:15:40 +02:00
|
|
|
|
|
|
|
if (strcmp(path, "") == 0)
|
|
|
|
path = "/";
|
|
|
|
|
2016-03-17 15:09:07 +01:00
|
|
|
::File_system::Dir_handle dir_handle;
|
|
|
|
try { dir_handle = _fs.dir(path, false); }
|
|
|
|
catch (::File_system::Lookup_failed) { return DIRENT_ERR_INVALID_PATH; }
|
|
|
|
catch (::File_system::Name_too_long) { return DIRENT_ERR_INVALID_PATH; }
|
|
|
|
catch (...) { return DIRENT_ERR_NO_PERM; }
|
2014-04-07 16:15:40 +02:00
|
|
|
|
2017-02-01 21:07:14 +01:00
|
|
|
Fs_handle_guard dir_guard(*this, _fs, dir_handle, _handle_space);
|
|
|
|
Directory_entry entry;
|
2014-04-07 16:15:40 +02:00
|
|
|
|
2017-02-01 21:07:14 +01:00
|
|
|
enum { DIRENT_SIZE = sizeof(Directory_entry) };
|
2014-04-07 16:15:40 +02:00
|
|
|
|
2017-02-01 21:07:14 +01:00
|
|
|
_read(dir_guard, &entry, DIRENT_SIZE, index*DIRENT_SIZE);
|
2014-04-07 16:15:40 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The default value has no meaning because the switch below
|
|
|
|
* assigns a value in each possible branch. But it is needed to
|
|
|
|
* keep the compiler happy.
|
|
|
|
*/
|
|
|
|
Dirent_type type = DIRENT_TYPE_END;
|
|
|
|
|
2017-02-01 21:07:14 +01:00
|
|
|
/* copy-out payload into destination buffer */
|
|
|
|
switch (entry.type) {
|
2014-04-07 16:15:40 +02:00
|
|
|
case Directory_entry::TYPE_DIRECTORY: type = DIRENT_TYPE_DIRECTORY; break;
|
|
|
|
case Directory_entry::TYPE_FILE: type = DIRENT_TYPE_FILE; break;
|
|
|
|
case Directory_entry::TYPE_SYMLINK: type = DIRENT_TYPE_SYMLINK; break;
|
|
|
|
}
|
|
|
|
|
2017-02-01 21:07:14 +01:00
|
|
|
out.fileno = entry.inode;
|
2014-04-07 16:15:40 +02:00
|
|
|
out.type = type;
|
2017-02-01 21:07:14 +01:00
|
|
|
strncpy(out.name, entry.name, sizeof(out.name));
|
2014-04-07 16:15:40 +02:00
|
|
|
|
|
|
|
return DIRENT_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
Unlink_result unlink(char const *path) override
|
|
|
|
{
|
|
|
|
Absolute_path dir_path(path);
|
|
|
|
dir_path.strip_last_element();
|
|
|
|
|
|
|
|
Absolute_path file_name(path);
|
|
|
|
file_name.keep_only_last_element();
|
|
|
|
|
|
|
|
try {
|
|
|
|
::File_system::Dir_handle dir = _fs.dir(dir_path.base(), false);
|
2017-02-01 21:07:14 +01:00
|
|
|
Fs_handle_guard dir_guard(*this, _fs, dir, _handle_space);
|
2014-04-07 16:15:40 +02:00
|
|
|
|
|
|
|
_fs.unlink(dir, file_name.base() + 1);
|
|
|
|
}
|
2016-03-17 15:09:07 +01:00
|
|
|
catch (::File_system::Invalid_handle) { return UNLINK_ERR_NO_ENTRY; }
|
|
|
|
catch (::File_system::Invalid_name) { return UNLINK_ERR_NO_ENTRY; }
|
|
|
|
catch (::File_system::Lookup_failed) { return UNLINK_ERR_NO_ENTRY; }
|
2015-10-30 12:33:26 +01:00
|
|
|
catch (::File_system::Not_empty) { return UNLINK_ERR_NOT_EMPTY; }
|
2016-03-17 15:09:07 +01:00
|
|
|
catch (::File_system::Permission_denied) { return UNLINK_ERR_NO_PERM; }
|
2014-04-07 16:15:40 +02:00
|
|
|
|
|
|
|
return UNLINK_OK;
|
|
|
|
}
|
|
|
|
|
2014-09-09 14:32:31 +02:00
|
|
|
Readlink_result readlink(char const *path, char *buf, file_size buf_size,
|
|
|
|
file_size &out_len) override
|
2014-04-07 16:15:40 +02:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Canonicalize path (i.e., path must start with '/')
|
|
|
|
*/
|
|
|
|
Absolute_path abs_path(path);
|
|
|
|
abs_path.strip_last_element();
|
|
|
|
|
|
|
|
Absolute_path symlink_name(path);
|
|
|
|
symlink_name.keep_only_last_element();
|
|
|
|
|
|
|
|
try {
|
|
|
|
::File_system::Dir_handle dir_handle = _fs.dir(abs_path.base(), false);
|
2017-02-01 21:07:14 +01:00
|
|
|
Fs_handle_guard from_dir_guard(*this, _fs, dir_handle, _handle_space);
|
2014-04-07 16:15:40 +02:00
|
|
|
|
|
|
|
::File_system::Symlink_handle symlink_handle =
|
|
|
|
_fs.symlink(dir_handle, symlink_name.base() + 1, false);
|
2017-02-01 21:07:14 +01:00
|
|
|
Fs_handle_guard symlink_guard(*this, _fs, symlink_handle, _handle_space);
|
2014-04-07 16:15:40 +02:00
|
|
|
|
2017-02-01 21:07:14 +01:00
|
|
|
out_len = _read(symlink_guard, buf, buf_size, 0);
|
2014-04-07 16:15:40 +02:00
|
|
|
|
|
|
|
return READLINK_OK;
|
2016-03-17 15:09:07 +01:00
|
|
|
}
|
|
|
|
catch (::File_system::Lookup_failed) { return READLINK_ERR_NO_ENTRY; }
|
|
|
|
catch (::File_system::Invalid_handle) { return READLINK_ERR_NO_ENTRY; }
|
|
|
|
catch (...) { return READLINK_ERR_NO_PERM; }
|
2014-04-07 16:15:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Rename_result rename(char const *from_path, char const *to_path) override
|
|
|
|
{
|
2016-03-02 14:32:43 +01:00
|
|
|
if ((strcmp(from_path, to_path) == 0) && leaf_path(from_path))
|
|
|
|
return RENAME_OK;
|
|
|
|
|
2014-04-07 16:15:40 +02:00
|
|
|
Absolute_path from_dir_path(from_path);
|
|
|
|
from_dir_path.strip_last_element();
|
|
|
|
|
|
|
|
Absolute_path from_file_name(from_path);
|
|
|
|
from_file_name.keep_only_last_element();
|
|
|
|
|
|
|
|
Absolute_path to_dir_path(to_path);
|
|
|
|
to_dir_path.strip_last_element();
|
|
|
|
|
|
|
|
Absolute_path to_file_name(to_path);
|
|
|
|
to_file_name.keep_only_last_element();
|
|
|
|
|
|
|
|
try {
|
|
|
|
::File_system::Dir_handle from_dir = _fs.dir(from_dir_path.base(), false);
|
2017-02-01 21:07:14 +01:00
|
|
|
Fs_handle_guard from_dir_guard(*this, _fs, from_dir, _handle_space);
|
2014-04-07 16:15:40 +02:00
|
|
|
::File_system::Dir_handle to_dir = _fs.dir(to_dir_path.base(), false);
|
2017-02-01 21:07:14 +01:00
|
|
|
Fs_handle_guard to_dir_guard(*this, _fs, to_dir, _handle_space);
|
2014-04-07 16:15:40 +02:00
|
|
|
|
|
|
|
_fs.move(from_dir, from_file_name.base() + 1,
|
|
|
|
to_dir, to_file_name.base() + 1);
|
2015-10-07 19:15:47 +02:00
|
|
|
}
|
|
|
|
catch (::File_system::Lookup_failed) { return RENAME_ERR_NO_ENTRY; }
|
|
|
|
catch (...) { return RENAME_ERR_NO_PERM; }
|
2014-04-07 16:15:40 +02:00
|
|
|
|
|
|
|
return RENAME_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
Mkdir_result mkdir(char const *path, unsigned mode) override
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Canonicalize path (i.e., path must start with '/')
|
|
|
|
*/
|
|
|
|
Absolute_path abs_path(path);
|
|
|
|
|
|
|
|
try {
|
2015-10-07 18:45:34 +02:00
|
|
|
_fs.close(_fs.dir(abs_path.base(), true));
|
2014-04-07 16:15:40 +02:00
|
|
|
}
|
|
|
|
catch (::File_system::Permission_denied) { return MKDIR_ERR_NO_PERM; }
|
|
|
|
catch (::File_system::Node_already_exists) { return MKDIR_ERR_EXISTS; }
|
|
|
|
catch (::File_system::Lookup_failed) { return MKDIR_ERR_NO_ENTRY; }
|
|
|
|
catch (::File_system::Name_too_long) { return MKDIR_ERR_NAME_TOO_LONG; }
|
|
|
|
catch (::File_system::No_space) { return MKDIR_ERR_NO_SPACE; }
|
2016-03-17 15:09:07 +01:00
|
|
|
catch (::File_system::Out_of_metadata) { return MKDIR_ERR_NO_ENTRY; }
|
2014-04-07 16:15:40 +02:00
|
|
|
|
2015-10-07 19:15:47 +02:00
|
|
|
return MKDIR_OK;
|
2014-04-07 16:15:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Symlink_result symlink(char const *from, char const *to) override
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* We write to the symlink via the packet stream. Hence we need
|
|
|
|
* to serialize with other packet-stream operations.
|
|
|
|
*/
|
|
|
|
Lock::Guard guard(_lock);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Canonicalize path (i.e., path must start with '/')
|
|
|
|
*/
|
|
|
|
Absolute_path abs_path(to);
|
|
|
|
abs_path.strip_last_element();
|
|
|
|
|
|
|
|
Absolute_path symlink_name(to);
|
|
|
|
symlink_name.keep_only_last_element();
|
|
|
|
|
|
|
|
try {
|
|
|
|
::File_system::Dir_handle dir_handle = _fs.dir(abs_path.base(), false);
|
2017-02-01 21:07:14 +01:00
|
|
|
Fs_handle_guard from_dir_guard(*this, _fs, dir_handle, _handle_space);
|
2014-04-07 16:15:40 +02:00
|
|
|
|
|
|
|
::File_system::Symlink_handle symlink_handle =
|
|
|
|
_fs.symlink(dir_handle, symlink_name.base() + 1, true);
|
2017-02-01 21:07:14 +01:00
|
|
|
Fs_handle_guard symlink_guard(*this, _fs, symlink_handle, _handle_space);
|
2014-04-07 16:15:40 +02:00
|
|
|
|
2017-02-01 21:07:14 +01:00
|
|
|
_write(symlink_guard, from, strlen(from) + 1, 0);
|
2014-04-07 16:15:40 +02:00
|
|
|
}
|
|
|
|
catch (::File_system::Invalid_handle) { return SYMLINK_ERR_NO_ENTRY; }
|
2015-10-07 19:15:47 +02:00
|
|
|
catch (::File_system::Node_already_exists) { return SYMLINK_ERR_EXISTS; }
|
2014-04-07 16:15:40 +02:00
|
|
|
catch (::File_system::Invalid_name) { return SYMLINK_ERR_NAME_TOO_LONG; }
|
|
|
|
catch (::File_system::Lookup_failed) { return SYMLINK_ERR_NO_ENTRY; }
|
2015-10-07 19:15:47 +02:00
|
|
|
catch (::File_system::Permission_denied) { return SYMLINK_ERR_NO_PERM; }
|
|
|
|
catch (::File_system::No_space) { return SYMLINK_ERR_NO_SPACE; }
|
2016-03-17 15:09:07 +01:00
|
|
|
catch (::File_system::Out_of_metadata) { return SYMLINK_ERR_NO_ENTRY; }
|
2014-04-07 16:15:40 +02:00
|
|
|
|
2015-10-07 19:15:47 +02:00
|
|
|
return SYMLINK_OK;
|
2014-04-07 16:15:40 +02:00
|
|
|
}
|
|
|
|
|
2014-09-09 14:32:31 +02:00
|
|
|
file_size num_dirent(char const *path) override
|
2014-04-07 16:15:40 +02:00
|
|
|
{
|
|
|
|
if (strcmp(path, "") == 0)
|
|
|
|
path = "/";
|
|
|
|
|
2014-05-15 16:19:43 +02:00
|
|
|
::File_system::Node_handle node;
|
2016-03-17 15:09:07 +01:00
|
|
|
try { node = _fs.node(path); } catch (...) { return 0; }
|
2017-02-01 21:07:14 +01:00
|
|
|
Fs_handle_guard node_guard(*this, _fs, node, _handle_space);
|
2014-04-07 16:15:40 +02:00
|
|
|
|
|
|
|
::File_system::Status status = _fs.status(node);
|
|
|
|
|
|
|
|
return status.size / sizeof(::File_system::Directory_entry);
|
|
|
|
}
|
|
|
|
|
2016-05-11 18:21:47 +02:00
|
|
|
bool directory(char const *path) override
|
2014-04-07 16:15:40 +02:00
|
|
|
{
|
|
|
|
try {
|
|
|
|
::File_system::Node_handle node = _fs.node(path);
|
2017-02-01 21:07:14 +01:00
|
|
|
Fs_handle_guard node_guard(*this, _fs, node, _handle_space);
|
2014-04-07 16:15:40 +02:00
|
|
|
|
|
|
|
::File_system::Status status = _fs.status(node);
|
|
|
|
|
2016-05-11 18:21:47 +02:00
|
|
|
return status.directory();
|
2014-04-07 16:15:40 +02:00
|
|
|
}
|
|
|
|
catch (...) { return false; }
|
|
|
|
}
|
|
|
|
|
|
|
|
char const *leaf_path(char const *path) override
|
|
|
|
{
|
|
|
|
/* check if node at path exists within file system */
|
|
|
|
try {
|
|
|
|
::File_system::Node_handle node = _fs.node(path);
|
|
|
|
_fs.close(node);
|
|
|
|
}
|
2015-10-07 19:15:47 +02:00
|
|
|
catch (...) { return 0; }
|
2014-04-07 16:15:40 +02:00
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2016-03-30 15:24:19 +02:00
|
|
|
Open_result open(char const *path, unsigned vfs_mode, Vfs_handle **out_handle, Genode::Allocator& alloc) override
|
2014-04-07 16:15:40 +02:00
|
|
|
{
|
|
|
|
Lock::Guard guard(_lock);
|
|
|
|
|
|
|
|
Absolute_path dir_path(path);
|
|
|
|
dir_path.strip_last_element();
|
|
|
|
|
|
|
|
Absolute_path file_name(path);
|
|
|
|
file_name.keep_only_last_element();
|
|
|
|
|
|
|
|
::File_system::Mode mode;
|
|
|
|
|
|
|
|
switch (vfs_mode & OPEN_MODE_ACCMODE) {
|
|
|
|
default: mode = ::File_system::STAT_ONLY; break;
|
|
|
|
case OPEN_MODE_RDONLY: mode = ::File_system::READ_ONLY; break;
|
|
|
|
case OPEN_MODE_WRONLY: mode = ::File_system::WRITE_ONLY; break;
|
|
|
|
case OPEN_MODE_RDWR: mode = ::File_system::READ_WRITE; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool const create = vfs_mode & OPEN_MODE_CREATE;
|
|
|
|
|
|
|
|
try {
|
|
|
|
::File_system::Dir_handle dir = _fs.dir(dir_path.base(), false);
|
2017-02-01 21:07:14 +01:00
|
|
|
Fs_handle_guard dir_guard(*this, _fs, dir, _handle_space);
|
2014-04-07 16:15:40 +02:00
|
|
|
|
|
|
|
::File_system::File_handle file = _fs.file(dir, file_name.base() + 1,
|
|
|
|
mode, create);
|
|
|
|
|
2017-02-01 21:07:14 +01:00
|
|
|
Handle_space::Id id { file };
|
|
|
|
*out_handle = new (alloc)
|
|
|
|
Fs_vfs_handle(*this, alloc, vfs_mode, _handle_space, id);
|
2014-04-07 16:15:40 +02:00
|
|
|
}
|
2016-03-17 15:09:07 +01:00
|
|
|
catch (::File_system::Lookup_failed) { return OPEN_ERR_UNACCESSIBLE; }
|
|
|
|
catch (::File_system::Permission_denied) { return OPEN_ERR_NO_PERM; }
|
|
|
|
catch (::File_system::Invalid_handle) { return OPEN_ERR_UNACCESSIBLE; }
|
|
|
|
catch (::File_system::Node_already_exists) { return OPEN_ERR_EXISTS; }
|
2015-10-07 19:15:47 +02:00
|
|
|
catch (::File_system::Invalid_name) { return OPEN_ERR_NAME_TOO_LONG; }
|
2016-03-17 15:09:07 +01:00
|
|
|
catch (::File_system::Name_too_long) { return OPEN_ERR_NAME_TOO_LONG; }
|
|
|
|
catch (::File_system::No_space) { return OPEN_ERR_NO_SPACE; }
|
|
|
|
catch (::File_system::Out_of_metadata) { return OPEN_ERR_NO_PERM; }
|
2014-04-07 16:15:40 +02:00
|
|
|
|
2015-10-07 19:15:47 +02:00
|
|
|
return OPEN_OK;
|
2014-04-07 16:15:40 +02:00
|
|
|
}
|
|
|
|
|
2016-03-30 15:24:19 +02:00
|
|
|
void close(Vfs_handle *vfs_handle) override
|
|
|
|
{
|
2016-03-17 15:09:07 +01:00
|
|
|
if (!vfs_handle) return;
|
|
|
|
|
2016-03-30 15:24:19 +02:00
|
|
|
Lock::Guard guard(_lock);
|
|
|
|
|
2016-03-17 15:09:07 +01:00
|
|
|
Fs_vfs_handle *fs_handle = static_cast<Fs_vfs_handle *>(vfs_handle);
|
2016-03-30 15:24:19 +02:00
|
|
|
|
2016-03-17 15:09:07 +01:00
|
|
|
if (fs_handle) {
|
|
|
|
_fs.close(fs_handle->file_handle());
|
|
|
|
destroy(fs_handle->alloc(), fs_handle);
|
2016-03-30 15:24:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-07 16:15:40 +02:00
|
|
|
|
|
|
|
/***************************
|
|
|
|
** File_system interface **
|
|
|
|
***************************/
|
|
|
|
|
2017-02-07 19:03:23 +01:00
|
|
|
static char const *name() { return "fs"; }
|
|
|
|
char const *type() override { return "fs"; }
|
2014-04-07 16:15:40 +02:00
|
|
|
|
2015-10-07 17:02:52 +02:00
|
|
|
void sync(char const *path) override
|
2014-04-07 16:15:40 +02:00
|
|
|
{
|
2015-10-07 17:02:52 +02:00
|
|
|
try {
|
|
|
|
::File_system::Node_handle node = _fs.node(path);
|
|
|
|
_fs.sync(node);
|
2016-03-17 15:09:07 +01:00
|
|
|
_fs.close(node);
|
2015-10-07 17:02:52 +02:00
|
|
|
} catch (...) { }
|
2014-04-07 16:15:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/********************************
|
|
|
|
** File I/O service interface **
|
|
|
|
********************************/
|
|
|
|
|
2014-09-09 14:32:31 +02:00
|
|
|
Write_result write(Vfs_handle *vfs_handle, char const *buf,
|
|
|
|
file_size buf_size, file_size &out_count) override
|
2014-04-07 16:15:40 +02:00
|
|
|
{
|
|
|
|
Lock::Guard guard(_lock);
|
|
|
|
|
2017-02-01 21:07:14 +01:00
|
|
|
Fs_vfs_handle &handle = static_cast<Fs_vfs_handle &>(*vfs_handle);
|
2014-04-07 16:15:40 +02:00
|
|
|
|
2017-02-01 21:07:14 +01:00
|
|
|
out_count = _write(handle, buf, buf_size, handle.seek());
|
2014-04-07 16:15:40 +02:00
|
|
|
|
|
|
|
return WRITE_OK;
|
|
|
|
}
|
|
|
|
|
2014-09-09 14:32:31 +02:00
|
|
|
Read_result read(Vfs_handle *vfs_handle, char *dst, file_size count,
|
|
|
|
file_size &out_count) override
|
2014-04-07 16:15:40 +02:00
|
|
|
{
|
|
|
|
Lock::Guard guard(_lock);
|
|
|
|
|
2017-02-01 21:07:14 +01:00
|
|
|
Fs_vfs_handle &handle = static_cast<Fs_vfs_handle &>(*vfs_handle);
|
|
|
|
|
|
|
|
/* reset the ready_ready state */
|
|
|
|
handle.read_ready_state = Handle_state::Read_ready_state::IDLE;
|
|
|
|
|
|
|
|
out_count = _read(handle, dst, count, handle.seek());
|
|
|
|
|
|
|
|
return READ_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool queue_read(Vfs_handle *vfs_handle, char *dst, file_size count,
|
|
|
|
Read_result &out_result, file_size &out_count) override
|
|
|
|
{
|
|
|
|
Lock::Guard guard(_lock);
|
|
|
|
|
|
|
|
Fs_vfs_handle *handle = static_cast<Fs_vfs_handle *>(vfs_handle);
|
|
|
|
|
|
|
|
if (handle->queued_read_state != Handle_state::Queued_state::IDLE)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
::File_system::Session::Tx::Source &source = *_fs.tx();
|
|
|
|
|
|
|
|
/* if not ready to submit suggest retry */
|
|
|
|
if (!source.ready_to_submit()) return false;
|
|
|
|
|
|
|
|
file_size const max_packet_size = source.bulk_buffer_size() / 2;
|
|
|
|
file_size const clipped_count = min(max_packet_size, count);
|
|
|
|
|
|
|
|
::File_system::Packet_descriptor p;
|
|
|
|
try {
|
|
|
|
p = source.alloc_packet(clipped_count);
|
|
|
|
} catch (::File_system::Session::Tx::Source::Packet_alloc_failed) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
::File_system::Packet_descriptor const
|
|
|
|
packet(p, handle->file_handle(),
|
|
|
|
::File_system::Packet_descriptor::READ,
|
|
|
|
clipped_count, handle->seek());
|
|
|
|
|
|
|
|
/* pass packet to server side */
|
|
|
|
source.submit_packet(packet);
|
2014-04-07 16:15:40 +02:00
|
|
|
|
2017-02-01 21:07:14 +01:00
|
|
|
handle->read_ready_state = Handle_state::Read_ready_state::IDLE;
|
|
|
|
handle->queued_read_state = Handle_state::Queued_state::QUEUED;
|
2014-04-07 16:15:40 +02:00
|
|
|
|
2017-02-01 21:07:14 +01:00
|
|
|
out_result = READ_QUEUED;
|
2014-04-07 16:15:40 +02:00
|
|
|
|
2017-02-01 21:07:14 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Read_result complete_read(Vfs_handle *vfs_handle, char *dst, file_size count,
|
|
|
|
file_size &out_count) override
|
|
|
|
{
|
|
|
|
Lock::Guard guard(_lock);
|
|
|
|
|
|
|
|
Fs_vfs_handle *handle = static_cast<Fs_vfs_handle *>(vfs_handle);
|
|
|
|
|
|
|
|
if (handle->queued_read_state != Handle_state::Queued_state::ACK)
|
|
|
|
return READ_QUEUED;
|
|
|
|
|
|
|
|
/* obtain result packet descriptor with updated status info */
|
|
|
|
::File_system::Packet_descriptor const
|
|
|
|
packet = handle->queued_read_packet;
|
|
|
|
|
|
|
|
file_size const read_num_bytes = min(packet.length(), count);
|
|
|
|
|
|
|
|
::File_system::Session::Tx::Source &source = *_fs.tx();
|
2014-04-07 16:15:40 +02:00
|
|
|
|
2017-02-01 21:07:14 +01:00
|
|
|
memcpy(dst, source.packet_content(packet), read_num_bytes);
|
|
|
|
|
|
|
|
source.release_packet(packet);
|
|
|
|
handle->queued_read_state = Handle_state::Queued_state::IDLE;
|
|
|
|
handle->queued_read_packet = ::File_system::Packet_descriptor();
|
|
|
|
|
|
|
|
out_count = read_num_bytes;
|
2014-04-07 16:15:40 +02:00
|
|
|
|
|
|
|
return READ_OK;
|
|
|
|
}
|
|
|
|
|
2017-02-01 21:07:14 +01:00
|
|
|
bool read_ready(Vfs_handle *vfs_handle) override
|
|
|
|
{
|
|
|
|
Fs_vfs_handle *handle = static_cast<Fs_vfs_handle *>(vfs_handle);
|
|
|
|
|
|
|
|
return handle->read_ready_state == Handle_state::Read_ready_state::READY;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool notify_read_ready(Vfs_handle *vfs_handle) override
|
|
|
|
{
|
|
|
|
Fs_vfs_handle *handle = static_cast<Fs_vfs_handle *>(vfs_handle);
|
|
|
|
if (handle->read_ready_state != Handle_state::Read_ready_state::IDLE)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
::File_system::Session::Tx::Source &source = *_fs.tx();
|
|
|
|
|
|
|
|
/* if not ready to submit suggest retry */
|
|
|
|
if (!source.ready_to_submit()) return false;
|
|
|
|
|
|
|
|
using ::File_system::Packet_descriptor;
|
|
|
|
|
|
|
|
Packet_descriptor packet(Packet_descriptor(),
|
|
|
|
handle->file_handle(),
|
|
|
|
Packet_descriptor::READ_READY,
|
|
|
|
0, 0);
|
|
|
|
|
|
|
|
source.submit_packet(packet);
|
|
|
|
handle->read_ready_state = Handle_state::Read_ready_state::PENDING;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* When the packet is acknowledged the application is notified via
|
|
|
|
* Io_response_handler::handle_io_response().
|
|
|
|
*/
|
|
|
|
return true;
|
|
|
|
}
|
2017-02-01 11:28:15 +01:00
|
|
|
|
2014-09-09 14:32:31 +02:00
|
|
|
Ftruncate_result ftruncate(Vfs_handle *vfs_handle, file_size len) override
|
2014-04-07 16:15:40 +02:00
|
|
|
{
|
|
|
|
Fs_vfs_handle const *handle = static_cast<Fs_vfs_handle *>(vfs_handle);
|
|
|
|
|
|
|
|
try {
|
|
|
|
_fs.truncate(handle->file_handle(), len);
|
2015-10-07 19:15:47 +02:00
|
|
|
}
|
2014-04-07 16:15:40 +02:00
|
|
|
catch (::File_system::Invalid_handle) { return FTRUNCATE_ERR_NO_PERM; }
|
|
|
|
catch (::File_system::Permission_denied) { return FTRUNCATE_ERR_NO_PERM; }
|
2015-10-07 19:15:47 +02:00
|
|
|
catch (::File_system::No_space) { return FTRUNCATE_ERR_NO_SPACE; }
|
2014-04-07 16:15:40 +02:00
|
|
|
|
|
|
|
return FTRUNCATE_OK;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* _INCLUDE__VFS__FS_FILE_SYSTEM_H_ */
|