From a3063497d9aaf6bf06a3797804135105ad5f3bad Mon Sep 17 00:00:00 2001 From: Emery Hemingway Date: Thu, 3 Dec 2020 12:19:10 +0100 Subject: [PATCH 1/3] vfs: create missing root directories for writeable sessions This is the expected behavior. --- repos/os/src/server/vfs/main.cc | 47 ++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/repos/os/src/server/vfs/main.cc b/repos/os/src/server/vfs/main.cc index b780b1fdd7..358afd28a9 100644 --- a/repos/os/src/server/vfs/main.cc +++ b/repos/os/src/server/vfs/main.cc @@ -841,6 +841,41 @@ class Vfs_server::Root : public Genode::Root_component, Genode::Signal_transmitter(_reactivate_handler).submit(); } + /** + * Open a directory, ensuring all parent directories exists. + */ + void _create_session_dir(Path const &path) + { + using namespace Genode; + typedef Vfs::Directory_service::Opendir_result Result; + + Vfs_handle *handle { nullptr }; + Vfs::File_system &vfs = _vfs_env.root_dir(); + + switch (vfs.opendir(path.string(), true, &handle, _vfs_heap)) { + case Result::OPENDIR_OK: + handle->close(); + return; + case Result::OPENDIR_ERR_NODE_ALREADY_EXISTS: + if (vfs.directory(path.string())) return; + break; + case Result::OPENDIR_ERR_LOOKUP_FAILED: { + Path parent = path; + parent.strip_last_element(); + _create_session_dir(parent.string()); + auto res = vfs.opendir(path.string(), true, &handle, _vfs_heap); + if (res == Result::OPENDIR_OK) { + handle->close(); + return; + } + } + default: break; + } + + error("cannot create session root at ", path); + throw Service_denied(); + } + protected: Session_component *_create_session(const char *args) override @@ -916,10 +951,14 @@ class Vfs_server::Root : public Genode::Root_component, } /* check if the session root exists */ - if (!((session_root == "/") - || _vfs_env.root_dir().directory(session_root.base()))) { - error("session root '", session_root, "' not found for '", label, "'"); - throw Service_denied(); + if (session_root != "/") { + if (!_vfs_env.root_dir().directory(session_root.base())) { + if (writeable) { _create_session_dir(session_root); } + else { + error("session root '", session_root, "' not found for '", label, "'"); + throw Service_denied(); + } + } } Session_component *session = new (md_alloc()) -- 2.30.0 From 0c91101db93422a4ff0aa2407b0ac7610abcf14f Mon Sep 17 00:00:00 2001 From: Emery Hemingway Date: Wed, 3 Feb 2021 15:20:39 +0100 Subject: [PATCH 2/3] vfs: support for loading plugins by label MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make the VFS plugin recognize nodes. --- repos/os/src/lib/vfs/file_system_factory.cc | 33 ++++++++++++++++----- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/repos/os/src/lib/vfs/file_system_factory.cc b/repos/os/src/lib/vfs/file_system_factory.cc index 5cdf20e8e3..1cf5d587ea 100644 --- a/repos/os/src/lib/vfs/file_system_factory.cc +++ b/repos/os/src/lib/vfs/file_system_factory.cc @@ -56,8 +56,16 @@ struct Vfs::Global_file_system_factory::Entry_base : Vfs::File_system_factory, Entry_base(Fs_type_name const &name) : name(name) { } - bool matches(Genode::Xml_node node) const { - return node.has_type(name.string()); } + bool matches(Genode::Xml_node node) const + { + if (node.has_type(name.string())) + return true; + + if (node.has_type("plugin") && node.has_attribute("load")) + return node.attribute("load").has_value(name.string()); + + return false; + } }; @@ -165,14 +173,25 @@ Vfs::File_system_factory &Vfs::Global_file_system_factory::_load_factory(Vfs::En bool Vfs::Global_file_system_factory::_probe_external_factory(Vfs::Env &env, Genode::Xml_node node) { - Library_name const lib_name = _library_name(node.type()); - try { - _list.insert(new (env.alloc()) - External_entry(node.type().string(), _load_factory(env, lib_name))); - return true; + if (node.has_type("plugin")) { + Library_name const lib_name = node.attribute_value("load", Library_name("")); + + if (lib_name == "") { + error("missing \"load\" attribute at ", node); + return false; + } + _list.insert(new (env.alloc()) + External_entry(lib_name.string(), _load_factory(env, lib_name))); + } else { + Library_name const lib_name = _library_name(node.type()); + + _list.insert(new (env.alloc()) + External_entry(node.type().string(), _load_factory(env, lib_name))); + } } catch (Factory_not_available) { return false; } + return true; } -- 2.30.0 From d2b15cb52415d18b9611862d9d184effc596bba6 Mon Sep 17 00:00:00 2001 From: Emery Hemingway Date: Wed, 3 Feb 2021 17:33:24 +0100 Subject: [PATCH 3/3] vfs: increase the capacity of tar ROM labels to 128 --- repos/os/src/lib/vfs/tar_file_system.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/repos/os/src/lib/vfs/tar_file_system.h b/repos/os/src/lib/vfs/tar_file_system.h index d9941deb5f..fcb06a1459 100644 --- a/repos/os/src/lib/vfs/tar_file_system.h +++ b/repos/os/src/lib/vfs/tar_file_system.h @@ -27,7 +27,7 @@ class Vfs::Tar_file_system : public File_system Genode::Env &_env; Genode::Allocator &_alloc; - typedef Genode::String<64> Rom_name; + typedef Genode::String<128> Rom_name; Rom_name _rom_name; Genode::Attached_rom_dataspace _tar_ds { _env, _rom_name.string() }; -- 2.30.0