vfs: pass root directory to plugins

This patch enables the use of the VFS from VFS plugins by passing a
reference of the root directory to the constructors of file-system
instances. Since it changes the signature of 'Vfs::Dir_file_system',
any code that uses the VFS directly requires an adaptation.

Fixes #2701
This commit is contained in:
Norman Feske 2018-03-02 13:30:10 +01:00 committed by Christian Helmuth
parent f61c0c6309
commit b0b92e4ee2
26 changed files with 118 additions and 102 deletions

View File

@ -1718,7 +1718,8 @@ struct Lxip_factory : Vfs::File_system_factory
Vfs::File_system *create(Genode::Env &env, Vfs::File_system *create(Genode::Env &env,
Genode::Allocator &alloc, Genode::Allocator &alloc,
Genode::Xml_node config, Genode::Xml_node config,
Vfs::Io_response_handler &io_handler) override Vfs::Io_response_handler &io_handler,
Vfs::File_system &) override
{ {
static Init inst(env, alloc); static Init inst(env, alloc);
return new (alloc) Vfs::Lxip_file_system(env, alloc, config, io_handler); return new (alloc) Vfs::Lxip_file_system(env, alloc, config, io_handler);

View File

@ -713,7 +713,8 @@ class Rump_factory : public Vfs::File_system_factory
Vfs::File_system *create(Genode::Env &env, Vfs::File_system *create(Genode::Env &env,
Genode::Allocator &alloc, Genode::Allocator &alloc,
Genode::Xml_node config, Genode::Xml_node config,
Vfs::Io_response_handler &) override Vfs::Io_response_handler &,
Vfs::File_system &) override
{ {
return new (alloc) Vfs::Rump_file_system(env, config); return new (alloc) Vfs::Rump_file_system(env, config);
} }
@ -727,10 +728,11 @@ extern "C" Vfs::File_system_factory *vfs_file_system_factory(void)
Vfs::File_system *create(Genode::Env &env, Vfs::File_system *create(Genode::Env &env,
Genode::Allocator &alloc, Genode::Allocator &alloc,
Genode::Xml_node node, Genode::Xml_node node,
Vfs::Io_response_handler &io_handler) override Vfs::Io_response_handler &io_handler,
Vfs::File_system &root_dir) override
{ {
static Rump_factory factory(env, alloc); static Rump_factory factory(env, alloc);
return factory.create(env, alloc, node, io_handler); return factory.create(env, alloc, node, io_handler, root_dir);
} }
}; };

View File

@ -224,7 +224,7 @@ struct Genode::Root_directory : public Vfs::Io_response_handler,
Root_directory(Env &env, Allocator &alloc, Xml_node config) Root_directory(Env &env, Allocator &alloc, Xml_node config)
: :
Vfs::Global_file_system_factory(alloc), Vfs::Global_file_system_factory(alloc),
Vfs::Dir_file_system(env, alloc, config, *this, *this, Dir_file_system::Root()), Vfs::Dir_file_system(env, alloc, config, *this, *this),
Directory(*this, env.ep(), alloc) Directory(*this, env.ep(), alloc)
{ } { }

View File

@ -97,7 +97,7 @@ class Libc::Env_implementation : public Libc::Env
: :
_env(env), _file_system_factory(alloc), _env(env), _file_system_factory(alloc),
_vfs(_env, alloc, _vfs_config(), io_response_handler, _vfs(_env, alloc, _vfs_config(), io_response_handler,
_file_system_factory, Vfs::Dir_file_system::Root()) _file_system_factory)
{ } { }

View File

@ -637,23 +637,25 @@ struct Fatfs_factory : Vfs::File_system_factory
Inner(Genode::Env &env, Genode::Allocator &alloc) { Inner(Genode::Env &env, Genode::Allocator &alloc) {
Fatfs::block_init(env, alloc); } Fatfs::block_init(env, alloc); }
Vfs::File_system *create(Genode::Env &env, Vfs::File_system *create(Genode::Env &env,
Genode::Allocator &alloc, Genode::Allocator &alloc,
Genode::Xml_node node, Genode::Xml_node node,
Vfs::Io_response_handler &) override Vfs::Io_response_handler &,
Vfs::File_system &) override
{ {
return new (alloc) return new (alloc)
Fatfs::File_system(env, alloc, node); Fatfs::File_system(env, alloc, node);
} }
}; };
Vfs::File_system *create(Genode::Env &env, Vfs::File_system *create(Genode::Env &env,
Genode::Allocator &alloc, Genode::Allocator &alloc,
Genode::Xml_node node, Genode::Xml_node node,
Vfs::Io_response_handler &io_handler) override Vfs::Io_response_handler &io_handler,
Vfs::File_system &root_dir) override
{ {
static Inner factory(env, alloc); static Inner factory(env, alloc);
return factory.create(env, alloc, node, io_handler); return factory.create(env, alloc, node, io_handler, root_dir);
} }
}; };

View File

@ -22,7 +22,7 @@ struct Jitterentropy_factory : Vfs::File_system_factory
{ {
Vfs::File_system *create(Genode::Env&, Genode::Allocator &alloc, Vfs::File_system *create(Genode::Env&, Genode::Allocator &alloc,
Genode::Xml_node node, Genode::Xml_node node,
Vfs::Io_response_handler &) override Vfs::Io_response_handler &, Vfs::File_system &) override
{ {
return new (alloc) Jitterentropy_file_system(alloc, node); return new (alloc) Jitterentropy_file_system(alloc, node);
} }

View File

@ -30,8 +30,6 @@ class Vfs::Dir_file_system : public File_system
enum { MAX_NAME_LEN = 128 }; enum { MAX_NAME_LEN = 128 };
struct Root { };
private: private:
/* /*
@ -45,7 +43,9 @@ class Vfs::Dir_file_system : public File_system
* *
* Additionally, the root has an empty _name. * Additionally, the root has an empty _name.
*/ */
bool _vfs_root; bool _vfs_root = false;
Dir_file_system &_root_dir;
struct Dir_vfs_handle : Vfs_handle struct Dir_vfs_handle : Vfs_handle
{ {
@ -95,7 +95,7 @@ class Vfs::Dir_file_system : public File_system
}; };
/* pointer to first child file system */ /* pointer to first child file system */
File_system *_first_file_system; File_system *_first_file_system = nullptr;
/* add new file system to the list of children */ /* add new file system to the list of children */
void _append_file_system(File_system *fs) void _append_file_system(File_system *fs)
@ -326,10 +326,10 @@ class Vfs::Dir_file_system : public File_system
Genode::Allocator &alloc, Genode::Allocator &alloc,
Genode::Xml_node node, Genode::Xml_node node,
Io_response_handler &io_handler, Io_response_handler &io_handler,
File_system_factory &fs_factory) File_system_factory &fs_factory,
Dir_file_system &root_dir)
: :
_vfs_root(false), _root_dir(root_dir)
_first_file_system(0)
{ {
using namespace Genode; using namespace Genode;
@ -346,11 +346,14 @@ class Vfs::Dir_file_system : public File_system
/* traverse into <dir> nodes */ /* traverse into <dir> nodes */
if (sub_node.has_type("dir")) { if (sub_node.has_type("dir")) {
_append_file_system(new (alloc) _append_file_system(new (alloc)
Dir_file_system(env, alloc, sub_node, io_handler, fs_factory)); Dir_file_system(env, alloc, sub_node, io_handler,
fs_factory, _root_dir));
continue; continue;
} }
File_system *fs = fs_factory.create(env, alloc, sub_node, io_handler); File_system * const fs =
fs_factory.create(env, alloc, sub_node, io_handler, _root_dir);
if (fs) { if (fs) {
_append_file_system(fs); _append_file_system(fs);
continue; continue;
@ -369,15 +372,19 @@ class Vfs::Dir_file_system : public File_system
} }
} }
/**
* Constructor used for creating the root directory
*/
Dir_file_system(Genode::Env &env, Dir_file_system(Genode::Env &env,
Genode::Allocator &alloc, Genode::Allocator &alloc,
Genode::Xml_node node, Genode::Xml_node node,
Io_response_handler &io_handler, Io_response_handler &io_handler,
File_system_factory &fs_factory, File_system_factory &fs_factory)
Dir_file_system::Root)
: :
Dir_file_system(env, alloc, node, io_handler, fs_factory) Dir_file_system(env, alloc, node, io_handler, fs_factory, *this)
{ _vfs_root = true; } {
_vfs_root = true;
}
/********************************* /*********************************
** Directory-service interface ** ** Directory-service interface **

View File

@ -28,15 +28,17 @@ struct Vfs::File_system_factory : Interface
/** /**
* Create and return a new file-system * Create and return a new file-system
* *
* \param env Env for service connections * \param env Env for service connections
* \param alloc internal file-system allocator * \param alloc internal file-system allocator
* \param config file-system configuration * \param config file-system configuration
* \param io_handler callback handler * \param io_handler callback handler
* \param root_dir VFS root directory
*/ */
virtual File_system *create(Genode::Env &env, virtual File_system *create(Genode::Env &env,
Genode::Allocator &alloc, Genode::Allocator &alloc,
Xml_node config, Xml_node config,
Io_response_handler &io_handler) = 0; Io_response_handler &io_handler,
File_system &root_dir) = 0;
}; };
@ -64,10 +66,11 @@ class Vfs::Global_file_system_factory : public Vfs::File_system_factory
template <typename FILE_SYSTEM> template <typename FILE_SYSTEM>
void _add_builtin_fs(); void _add_builtin_fs();
Vfs::File_system *_try_create(Genode::Env &env, Vfs::File_system *_try_create(Genode::Env &env,
Genode::Allocator &alloc, Genode::Allocator &alloc,
Genode::Xml_node node, Genode::Xml_node node,
Io_response_handler &io_handler); Io_response_handler &io_handler,
Vfs::File_system &root_dir);
/** /**
* Return name of factory provided by the shared library * Return name of factory provided by the shared library
@ -112,17 +115,11 @@ class Vfs::Global_file_system_factory : public Vfs::File_system_factory
Global_file_system_factory(Genode::Allocator &md_alloc); Global_file_system_factory(Genode::Allocator &md_alloc);
/** /**
* Create and return a new file-system * File_system_factory interface
*
* \param env Env for service connections
* \param alloc internal file-system allocator
* \param config file-system configuration
* \param io_handler callback handler
*/ */
Vfs::File_system *create(Genode::Env &env, File_system *create(Genode::Env &, Genode::Allocator &,
Genode::Allocator &alloc, Genode::Xml_node, Io_response_handler &,
Genode::Xml_node node, File_system &) override;
Io_response_handler &io_handler) override;
/** /**
* Register an additional factory for new file-system type * Register an additional factory for new file-system type

View File

@ -157,7 +157,7 @@ struct Cli_monitor::Main
/* initialize virtual file system */ /* initialize virtual file system */
Vfs::Dir_file_system _root_dir { _env, _heap, _vfs_config(), io_response_handler, Vfs::Dir_file_system _root_dir { _env, _heap, _vfs_config(), io_response_handler,
_global_file_system_factory, Vfs::Dir_file_system::Root() }; _global_file_system_factory };
Subsystem_config_registry _subsystem_config_registry { _root_dir, _heap, _env.ep() }; Subsystem_config_registry _subsystem_config_registry { _root_dir, _heap, _env.ep() };

View File

@ -337,7 +337,8 @@ class Vfs::Block_file_system : public Single_file_system
Block_file_system(Genode::Env &env, Block_file_system(Genode::Env &env,
Genode::Allocator &alloc, Genode::Allocator &alloc,
Genode::Xml_node config, Genode::Xml_node config,
Io_response_handler &) Io_response_handler &,
File_system &)
: :
Single_file_system(NODE_TYPE_BLOCK_DEVICE, name(), config), Single_file_system(NODE_TYPE_BLOCK_DEVICE, name(), config),
_alloc(alloc), _alloc(alloc),

View File

@ -66,12 +66,13 @@ struct Vfs::Builtin_entry : Vfs::Global_file_system_factory::Entry_base
{ {
Builtin_entry() : Entry_base(FILE_SYSTEM::name()) { } Builtin_entry() : Entry_base(FILE_SYSTEM::name()) { }
Vfs::File_system *create(Genode::Env &env, Vfs::File_system *create(Genode::Env &env,
Genode::Allocator &alloc, Genode::Allocator &alloc,
Genode::Xml_node node, Genode::Xml_node node,
Vfs::Io_response_handler &io_handler) override Io_response_handler &io_handler,
File_system &root_dir) override
{ {
return new (alloc) FILE_SYSTEM(env, alloc, node, io_handler); return new (alloc) FILE_SYSTEM(env, alloc, node, io_handler, root_dir);
} }
}; };
@ -80,16 +81,19 @@ struct Vfs::External_entry : Vfs::Global_file_system_factory::Entry_base
{ {
File_system_factory &_fs_factory; File_system_factory &_fs_factory;
External_entry(Fs_type_name const &name, External_entry(Fs_type_name const &name,
Vfs::File_system_factory &fs_factory) File_system_factory &fs_factory)
: :
Entry_base(name), _fs_factory(fs_factory) { } Entry_base(name), _fs_factory(fs_factory) { }
Vfs::File_system *create(Genode::Env &env, File_system *create(Genode::Env &env,
Genode::Allocator &alloc, Genode::Allocator &alloc,
Genode::Xml_node node, Genode::Xml_node node,
Vfs::Io_response_handler &io_handler) override { Io_response_handler &io_handler,
return _fs_factory.create(env, alloc, node, io_handler); } File_system &root_dir) override
{
return _fs_factory.create(env, alloc, node, io_handler, root_dir);
}
}; };
@ -106,14 +110,15 @@ void Vfs::Global_file_system_factory::_add_builtin_fs()
/** /**
* Lookup and create File_system instance * Lookup and create File_system instance
*/ */
Vfs::File_system *Vfs::Global_file_system_factory::_try_create(Genode::Env &env, Vfs::File_system *Vfs::Global_file_system_factory::_try_create(Genode::Env &env,
Genode::Allocator &alloc, Genode::Allocator &alloc,
Genode::Xml_node node, Genode::Xml_node node,
Io_response_handler &io_handler) Io_response_handler &io_handler,
File_system &root_dir)
{ {
for (Entry_base *e = _list.first(); e; e = e->next()) { for (Entry_base *e = _list.first(); e; e = e->next()) {
if (e->matches(node)) { if (e->matches(node)) {
return e->create(env, alloc, node, io_handler); return e->create(env, alloc, node, io_handler, root_dir);
} }
} }
@ -206,11 +211,12 @@ bool Vfs::Global_file_system_factory::_probe_external_factory(Genode::Env
Vfs::File_system *Vfs::Global_file_system_factory::create(Genode::Env &env, Vfs::File_system *Vfs::Global_file_system_factory::create(Genode::Env &env,
Genode::Allocator &alloc, Genode::Allocator &alloc,
Genode::Xml_node node, Genode::Xml_node node,
Io_response_handler &io_handler) Io_response_handler &io_handler,
File_system &root_dir)
{ {
try { try {
/* try if type is handled by the currently registered fs types */ /* try if type is handled by the currently registered fs types */
if (Vfs::File_system *fs = _try_create(env, alloc, node, io_handler)) if (Vfs::File_system *fs = _try_create(env, alloc, node, io_handler, root_dir))
return fs; return fs;
/* if the builtin fails, do not try loading an external */ /* if the builtin fails, do not try loading an external */
} catch (...) { return 0; } } catch (...) { return 0; }
@ -219,7 +225,7 @@ Vfs::File_system *Vfs::Global_file_system_factory::create(Genode::Env &e
/* probe for file system implementation available as shared lib */ /* probe for file system implementation available as shared lib */
if (_probe_external_factory(env, alloc, node)) { if (_probe_external_factory(env, alloc, node)) {
/* try again with the new file system type loaded */ /* try again with the new file system type loaded */
if (Vfs::File_system *fs = _try_create(env, alloc, node, io_handler)) if (Vfs::File_system *fs = _try_create(env, alloc, node, io_handler, root_dir))
return fs; return fs;
} }
} catch (...) { } } catch (...) { }

View File

@ -577,7 +577,8 @@ class Vfs::Fs_file_system : public File_system
Fs_file_system(Genode::Env &env, Fs_file_system(Genode::Env &env,
Genode::Allocator &alloc, Genode::Allocator &alloc,
Genode::Xml_node config, Genode::Xml_node config,
Io_response_handler &io_handler) Io_response_handler &io_handler,
File_system &)
: :
_env(env), _env(env),
_fs_packet_alloc(&alloc), _fs_packet_alloc(&alloc),

View File

@ -101,10 +101,11 @@ class Vfs::Inline_file_system : public Single_file_system
public: public:
Inline_file_system(Genode::Env&, Inline_file_system(Genode::Env &,
Genode::Allocator&, Genode::Allocator &,
Genode::Xml_node config, Genode::Xml_node config,
Io_response_handler &) Io_response_handler &,
File_system &)
: :
Single_file_system(NODE_TYPE_FILE, name(), config), Single_file_system(NODE_TYPE_FILE, name(), config),
_base(config.content_base()), _base(config.content_base()),

View File

@ -94,7 +94,8 @@ class Vfs::Log_file_system : public Single_file_system
Log_file_system(Genode::Env &env, Log_file_system(Genode::Env &env,
Genode::Allocator&, Genode::Allocator&,
Genode::Xml_node config, Genode::Xml_node config,
Io_response_handler &) Io_response_handler &,
File_system &)
: :
Single_file_system(NODE_TYPE_CHAR_DEVICE, name(), config), Single_file_system(NODE_TYPE_CHAR_DEVICE, name(), config),
_label(config.attribute_value("label", Label())), _label(config.attribute_value("label", Label())),

View File

@ -22,10 +22,9 @@ namespace Vfs { class Null_file_system; }
struct Vfs::Null_file_system : Single_file_system struct Vfs::Null_file_system : Single_file_system
{ {
Null_file_system(Genode::Env&, Null_file_system(Genode::Env&, Genode::Allocator&,
Genode::Allocator&,
Genode::Xml_node config, Genode::Xml_node config,
Io_response_handler &) Io_response_handler &, File_system &)
: :
Single_file_system(NODE_TYPE_CHAR_DEVICE, name(), config) Single_file_system(NODE_TYPE_CHAR_DEVICE, name(), config)
{ } { }

View File

@ -507,7 +507,7 @@ class Vfs::Ram_file_system : public Vfs::File_system
Ram_file_system(Genode::Env &env, Ram_file_system(Genode::Env &env,
Genode::Allocator &alloc, Genode::Allocator &alloc,
Genode::Xml_node, Genode::Xml_node,
Io_response_handler &) Io_response_handler &, File_system &)
: _env(env), _alloc(alloc) { } : _env(env), _alloc(alloc) { }
~Ram_file_system() { _root.empty(_alloc); } ~Ram_file_system() { _root.empty(_alloc); }

View File

@ -105,7 +105,8 @@ class Vfs::Rom_file_system : public Single_file_system
Rom_file_system(Genode::Env &env, Rom_file_system(Genode::Env &env,
Genode::Allocator&, Genode::Allocator&,
Genode::Xml_node config, Genode::Xml_node config,
Io_response_handler &) Io_response_handler &,
File_system &)
: :
Single_file_system(NODE_TYPE_FILE, name(), config), Single_file_system(NODE_TYPE_FILE, name(), config),
_label(config), _label(config),

View File

@ -89,7 +89,8 @@ class Vfs::Rtc_file_system : public Single_file_system
Rtc_file_system(Genode::Env &env, Rtc_file_system(Genode::Env &env,
Genode::Allocator&, Genode::Allocator&,
Genode::Xml_node config, Genode::Xml_node config,
Io_response_handler &) Io_response_handler &,
File_system &)
: :
Single_file_system(NODE_TYPE_CHAR_DEVICE, name(), config), Single_file_system(NODE_TYPE_CHAR_DEVICE, name(), config),
_rtc(env) _rtc(env)

View File

@ -31,10 +31,9 @@ class Vfs::Symlink_file_system : public Single_file_system
public: public:
Symlink_file_system(Genode::Env&, Symlink_file_system(Genode::Env &, Genode::Allocator &,
Genode::Allocator&,
Genode::Xml_node config, Genode::Xml_node config,
Io_response_handler&) Io_response_handler &, File_system &)
: :
Single_file_system(NODE_TYPE_SYMLINK, "symlink", config), Single_file_system(NODE_TYPE_SYMLINK, "symlink", config),
_target(config.attribute_value("target", Target())) _target(config.attribute_value("target", Target()))

View File

@ -515,7 +515,8 @@ class Vfs::Tar_file_system : public File_system
Tar_file_system(Genode::Env &env, Tar_file_system(Genode::Env &env,
Genode::Allocator &alloc, Genode::Allocator &alloc,
Genode::Xml_node config, Genode::Xml_node config,
Io_response_handler &) Io_response_handler &,
File_system &)
: :
_env(env), _alloc(alloc), _env(env), _alloc(alloc),
_rom_name(config.attribute_value("name", Rom_name())), _rom_name(config.attribute_value("name", Rom_name())),

View File

@ -106,9 +106,10 @@ class Vfs::Terminal_file_system : public Single_file_system
public: public:
Terminal_file_system(Genode::Env &env, Terminal_file_system(Genode::Env &env,
Genode::Allocator&, Genode::Allocator &,
Genode::Xml_node config, Genode::Xml_node config,
Io_response_handler &io_handler) Io_response_handler &io_handler,
File_system &)
: :
Single_file_system(NODE_TYPE_CHAR_DEVICE, name(), config), Single_file_system(NODE_TYPE_CHAR_DEVICE, name(), config),
_label(config.attribute_value("label", Label())), _label(config.attribute_value("label", Label())),

View File

@ -22,10 +22,9 @@ namespace Vfs { class Zero_file_system; }
struct Vfs::Zero_file_system : Single_file_system struct Vfs::Zero_file_system : Single_file_system
{ {
Zero_file_system(Genode::Env&, Zero_file_system(Genode::Env &, Genode::Allocator &,
Genode::Allocator&,
Genode::Xml_node config, Genode::Xml_node config,
Io_response_handler &) Io_response_handler &, File_system &)
: :
Single_file_system(NODE_TYPE_CHAR_DEVICE, name(), config) Single_file_system(NODE_TYPE_CHAR_DEVICE, name(), config)
{ } { }

View File

@ -208,8 +208,7 @@ class Fs_report::Root : public Genode::Root_component<Session_component>
Vfs::Dir_file_system _vfs { Vfs::Dir_file_system _vfs {
_env, _heap, vfs_config(), _env, _heap, vfs_config(),
_io_response_handler, _io_response_handler,
_global_file_system_factory, _global_file_system_factory };
Vfs::Dir_file_system::Root() };
Genode::Signal_handler<Root> _config_dispatcher { Genode::Signal_handler<Root> _config_dispatcher {
_env.ep(), *this, &Root::_config_update }; _env.ep(), *this, &Root::_config_update };

View File

@ -682,7 +682,7 @@ class Vfs_server::Root : public Genode::Root_component<Session_component>
Vfs::Dir_file_system _vfs { Vfs::Dir_file_system _vfs {
_env, _vfs_heap, vfs_config(), _io_response_handler, _env, _vfs_heap, vfs_config(), _io_response_handler,
_global_file_system_factory, Vfs::Dir_file_system::Root() }; _global_file_system_factory };
Genode::Signal_handler<Root> _config_handler { Genode::Signal_handler<Root> _config_handler {
_env.ep(), *this, &Root::_config_update }; _env.ep(), *this, &Root::_config_update };

View File

@ -531,10 +531,9 @@ void Component::construct(Genode::Env &env)
Vfs::Global_file_system_factory global_file_system_factory(heap); Vfs::Global_file_system_factory global_file_system_factory(heap);
Vfs::Dir_file_system vfs_root(env, heap, config_xml.sub_node("vfs"), Vfs::Dir_file_system vfs_root { env, heap, config_xml.sub_node("vfs"),
io_response_handler, io_response_handler,
global_file_system_factory, global_file_system_factory };
Vfs::Dir_file_system::Root());
Vfs::Vfs_handle *vfs_root_handle; Vfs::Vfs_handle *vfs_root_handle;
vfs_root.opendir("/", false, &vfs_root_handle, heap); vfs_root.opendir("/", false, &vfs_root_handle, heap);

View File

@ -235,9 +235,7 @@ struct Noux::Main
} _io_response_handler; } _io_response_handler;
Vfs::Dir_file_system _root_dir { _env, _heap, _config.xml().sub_node("fstab"), Vfs::Dir_file_system _root_dir { _env, _heap, _config.xml().sub_node("fstab"),
_io_response_handler, _io_response_handler, _global_file_system_factory };
_global_file_system_factory,
Vfs::Dir_file_system::Root() };
Vfs_handle_context _vfs_handle_context; Vfs_handle_context _vfs_handle_context;