VFS: construct file-systems using Vfs::Env object

Reduce the size and forward compatibility of VFS file-system
constructors by passing an object holding accessors for 'Genode::Env',
'Genode::Allocator', response handlers, and the root file-system.

Fix #2742
This commit is contained in:
Ehmry - 2018-04-03 15:59:35 +02:00 committed by Christian Helmuth
parent 810f59b555
commit 82a683eccc
36 changed files with 482 additions and 435 deletions

View File

@ -7,7 +7,7 @@
*/
/*
* Copyright (C) 2015-2017 Genode Labs GmbH
* Copyright (C) 2015-2018 Genode Labs GmbH
*
* This file is distributed under the terms of the GNU General Public License
* version 2.
@ -1382,12 +1382,11 @@ class Vfs::Lxip_file_system : public Vfs::File_system,
public:
Lxip_file_system(Genode::Env &env, Genode::Allocator &alloc,
Genode::Xml_node config,
Vfs::Io_response_handler &io_response_handler)
Lxip_file_system(Vfs::Env &env, Genode::Xml_node config)
:
Directory(""),
_ep(env.ep()), _alloc(alloc), _io_response_handler(io_response_handler)
_ep(env.env().ep()), _alloc(env.alloc()),
_io_response_handler(env.io_handler())
{
apply_config(config);
}
@ -1715,14 +1714,10 @@ struct Lxip_factory : Vfs::File_system_factory
}
};
Vfs::File_system *create(Genode::Env &env,
Genode::Allocator &alloc,
Genode::Xml_node config,
Vfs::Io_response_handler &io_handler,
Vfs::File_system &) override
Vfs::File_system *create(Vfs::Env &env, Genode::Xml_node config) override
{
static Init inst(env, alloc);
return new (alloc) Vfs::Lxip_file_system(env, alloc, config, io_handler);
static Init inst(env.env(), env.alloc());
return new (env.alloc()) Vfs::Lxip_file_system(env, config);
}
};

View File

@ -61,8 +61,7 @@ class Vfs::Rump_file_system : public File_system
typedef Genode::Path<MAX_PATH_LEN> Path;
Genode::Env &_env;
Io_response_handler &_io_handler;
Vfs::Env &_env;
struct Rump_vfs_dir_handle;
struct Rump_watch_handle;
@ -379,15 +378,14 @@ class Vfs::Rump_file_system : public File_system
{
for (Rump_watch_handle *h = _watchers.first(); h; h = h->next()) {
if (h->kqueue_check())
_io_handler.handle_watch_response(h->context());
_env.watch_handler().handle_watch_response(h->context());
}
}
public:
Rump_file_system(Genode::Env &env, Xml_node const &config,
Io_response_handler &io_handler)
: _env(env), _io_handler(io_handler)
Rump_file_system(Vfs::Env &env, Xml_node const &config)
: _env(env)
{
typedef Genode::String<16> Fs_type;
@ -427,6 +425,8 @@ class Vfs::Rump_file_system : public File_system
Genode::Dataspace_capability dataspace(char const *path) override
{
Genode::Env &env = _env.env();
int fd = rump_sys_open(path, O_RDONLY);
if (fd == -1) return Genode::Dataspace_capability();
@ -437,9 +437,9 @@ class Vfs::Rump_file_system : public File_system
char *local_addr = nullptr;
Ram_dataspace_capability ds_cap;
try {
ds_cap = _env.ram().alloc(ds_size);
ds_cap = env.ram().alloc(ds_size);
local_addr = _env.rm().attach(ds_cap);
local_addr = env.rm().attach(ds_cap);
enum { CHUNK_SIZE = 16U << 10 };
@ -450,11 +450,11 @@ class Vfs::Rump_file_system : public File_system
i += n;
}
_env.rm().detach(local_addr);
env.rm().detach(local_addr);
} catch(...) {
if (local_addr)
_env.rm().detach(local_addr);
_env.ram().free(ds_cap);
env.rm().detach(local_addr);
env.ram().free(ds_cap);
}
rump_sys_close(fd);
return ds_cap;
@ -464,7 +464,7 @@ class Vfs::Rump_file_system : public File_system
Genode::Dataspace_capability ds_cap) override
{
if (ds_cap.valid())
_env.ram().free(
_env.env().ram().free(
static_cap_cast<Genode::Ram_dataspace>(ds_cap));
}
@ -826,13 +826,9 @@ class Rump_factory : public Vfs::File_system_factory
}
Vfs::File_system *create(Genode::Env &env,
Genode::Allocator &alloc,
Genode::Xml_node config,
Vfs::Io_response_handler &io_handler,
Vfs::File_system &) override
Vfs::File_system *create(Vfs::Env &env, Genode::Xml_node config) override
{
return new (alloc) Vfs::Rump_file_system(env, config, io_handler);
return new (env.alloc()) Vfs::Rump_file_system(env, config);
}
};
@ -841,14 +837,10 @@ extern "C" Vfs::File_system_factory *vfs_file_system_factory(void)
{
struct Extern_factory : Vfs::File_system_factory
{
Vfs::File_system *create(Genode::Env &env,
Genode::Allocator &alloc,
Genode::Xml_node node,
Vfs::Io_response_handler &io_handler,
Vfs::File_system &root_dir) override
Vfs::File_system *create(Vfs::Env &env, Genode::Xml_node node) override
{
static Rump_factory factory(env, alloc);
return factory.create(env, alloc, node, io_handler, root_dir);
static Rump_factory factory(env.env(), env.alloc());
return factory.create(env, node);
}
};

View File

@ -17,6 +17,7 @@
/* Genode includes */
#include <base/env.h>
#include <base/allocator.h>
#include <vfs/simple_env.h>
#include <vfs/dir_file_system.h>
#include <vfs/file_system_factory.h>
@ -70,6 +71,13 @@ struct Genode::Directory : Noncopyable, Interface
typedef String<256> Path;
static Path join(Path const &x, Path const &y)
{
char const *p = y.string();
while (*p == '/') ++p;
return Path(x, "/", p);
}
private:
/*
@ -110,7 +118,7 @@ struct Genode::Directory : Noncopyable, Interface
* Ignore return value as the validity of the result is can be
* checked by the caller via 'stat.mode != 0'.
*/
_nonconst_fs().stat(Path(_path, "/", rel_path).string(), stat);
_nonconst_fs().stat(join(_path, rel_path).string(), stat);
return stat;
}
@ -124,9 +132,14 @@ struct Genode::Directory : Noncopyable, Interface
*
* \throw Open_failed
*/
Directory(Vfs::File_system &fs, Entrypoint &ep, Allocator &alloc)
: _path(""), _fs(fs), _ep(ep), _alloc(alloc)
{ }
Directory(Vfs::Env &vfs_env)
: _path(""), _fs(vfs_env.root_dir()),
_ep(vfs_env.env().ep()), _alloc(vfs_env.alloc())
{
if (_fs.opendir("/", false, &_handle, _alloc) !=
Vfs::Directory_service::OPENDIR_OK)
throw Nonexistent_directory();
}
/**
* Open sub directory
@ -134,7 +147,7 @@ struct Genode::Directory : Noncopyable, Interface
* \throw Nonexistent_directory
*/
Directory(Directory const &other, Path const &rel_path)
: _path(other._path, "/", rel_path), _fs(other._fs), _ep(other._ep),
: _path(join(other._path, rel_path)), _fs(other._fs), _ep(other._ep),
_alloc(other._alloc)
{
if (_fs.opendir(_path.string(), false, &_handle, _alloc) !=
@ -212,29 +225,23 @@ struct Genode::Directory : Noncopyable, Interface
Vfs::file_size file_size(Path const &rel_path) const
{
Vfs::Directory_service::Stat stat = _stat(rel_path);
if (!(stat.mode & Vfs::Directory_service::STAT_MODE_FILE))
throw Nonexistent_file();
return stat.size;
}
};
struct Genode::Root_directory : public Vfs::Io_response_handler,
private Vfs::Global_file_system_factory,
private Vfs::Dir_file_system,
public Directory
struct Genode::Root_directory : public Vfs::Simple_env,
public Directory
{
void handle_io_response(Vfs::Vfs_handle::Context*) override { }
Root_directory(Env &env, Allocator &alloc, Xml_node config)
Root_directory(Genode::Env &env, Allocator &alloc, Xml_node config)
:
Vfs::Global_file_system_factory(alloc),
Vfs::Dir_file_system(env, alloc, config, *this, *this),
Directory(*this, env.ep(), alloc)
Vfs::Simple_env(env, alloc, config), Directory((Vfs::Simple_env&)*this)
{ }
void apply_config(Xml_node config) { Vfs::Dir_file_system::apply_config(config); }
void apply_config(Xml_node config) { root_dir().apply_config(config); }
};
@ -306,7 +313,7 @@ class Genode::Readonly_file : public File
: _ep(_mutable(dir)._ep)
{
_open(_mutable(dir)._fs, _mutable(dir)._alloc,
Path(dir._path, "/", rel_path));
Directory::join(dir._path, rel_path));
}
~Readonly_file() { _handle->ds().close(_handle); }

View File

@ -99,21 +99,13 @@ class Vfs_audit::File_system : public Vfs::File_system
public:
File_system(Genode::Env &env,
Genode::Allocator &alloc,
Genode::Xml_node config,
Vfs::Io_response_handler &io_handler,
Vfs::File_system &root_dir)
File_system(Vfs::Env &env, Genode::Xml_node config)
:
_audit_log(env, config.attribute_value("label", Genode::String<64>("audit")).string()),
_root_dir(root_dir),
_audit_log(env.env(), config.attribute_value("label", Genode::String<64>("audit")).string()),
_root_dir(env.root_dir()),
_audit_path(config.attribute_value(
"path", Genode::String<Absolute_path::capacity()>()).string())
{
(void)env;
(void)alloc;
(void)io_handler;
}
{ }
const char* type() override { return "audit"; }
@ -295,14 +287,10 @@ extern "C" Vfs::File_system_factory *vfs_file_system_factory(void)
{
struct Factory : Vfs::File_system_factory
{
Vfs::File_system *create(Genode::Env &env,
Genode::Allocator &alloc,
Genode::Xml_node config,
Vfs::Io_response_handler &io_handler,
Vfs::File_system &root_dir) override
Vfs::File_system *create(Vfs::Env &env, Genode::Xml_node config) override
{
return new (alloc)
Vfs_audit::File_system(env, alloc, config, io_handler, root_dir);
return new (env.alloc())
Vfs_audit::File_system(env, config);
}
};

View File

@ -56,14 +56,13 @@ struct Vfs_ttf::Font_from_file
*/
static constexpr float MAX_SIZE_PX = 100.0;
Font_from_file(Vfs::File_system &root, Entrypoint &ep, Allocator &alloc,
Path const &file_path, float px)
Font_from_file(Vfs::Env &vfs_env, Path const &file_path, float px)
:
_dir(root, ep, alloc),
_content(alloc, _dir, file_path, File_content::Limit{10*1024*1024})
_dir(vfs_env),
_content(vfs_env.alloc(), _dir, file_path, File_content::Limit{10*1024*1024})
{
_content.bytes([&] (char const *ptr, size_t) {
_font.construct(alloc, ptr, min(px, MAX_SIZE_PX)); });
_font.construct(vfs_env.alloc(), ptr, min(px, MAX_SIZE_PX)); });
}
Font const &font() const { return *_font; }
@ -80,22 +79,20 @@ struct Vfs_ttf::Local_factory : File_system_factory
Readonly_value_file_system<unsigned> _max_width_fs;
Readonly_value_file_system<unsigned> _max_height_fs;
Local_factory(Env &env, Allocator &alloc, Xml_node node,
Vfs::File_system &root_dir)
Local_factory(Vfs::Env &vfs_env, Xml_node node)
:
_font(root_dir, env.ep(), alloc,
_font(vfs_env,
node.attribute_value("path", Directory::Path()),
node.attribute_value("size_px", 16.0)),
_cache_limit({node.attribute_value("cache", Number_of_bytes())}),
_cached_font(alloc, _font.font(), _cache_limit),
_cached_font(vfs_env.alloc(), _font.font(), _cache_limit),
_glyphs_fs (_cached_font),
_baseline_fs ("baseline", _font.font().baseline()),
_max_width_fs ("max_width", _font.font().bounding_box().w()),
_max_height_fs("max_height", _font.font().bounding_box().h())
{ }
Vfs::File_system *create(Env &, Allocator &, Xml_node node,
Io_response_handler &, Vfs::File_system &) override
Vfs::File_system *create(Vfs::Env&, Genode::Xml_node node) override
{
if (node.has_type(Glyphs_file_system::type_name()))
return &_glyphs_fs;
@ -135,13 +132,12 @@ class Vfs_ttf::File_system : private Local_factory,
public:
File_system(Env &env, Allocator &alloc, Xml_node node,
Vfs::File_system &root_dir)
File_system(Vfs::Env &vfs_env, Genode::Xml_node node)
:
Local_factory(env, alloc, node, root_dir),
Vfs::Dir_file_system(env, alloc,
Local_factory(vfs_env, node),
Vfs::Dir_file_system(vfs_env,
Xml_node(_config(node).string()),
*this, *this, root_dir)
*this)
{ }
char const *type() override { return "ttf"; }
@ -156,13 +152,11 @@ extern "C" Vfs::File_system_factory *vfs_file_system_factory(void)
{
struct Factory : Vfs::File_system_factory
{
Vfs::File_system *create(Genode::Env &env, Genode::Allocator &alloc,
Genode::Xml_node node,
Vfs::Io_response_handler &,
Vfs::File_system &root_dir) override
Vfs::File_system *create(Vfs::Env &vfs_env,
Genode::Xml_node node) override
{
try {
return new (alloc) Vfs_ttf::File_system(env, alloc, node, root_dir); }
try { return new (vfs_env.alloc())
Vfs_ttf::File_system(vfs_env, node); }
catch (...) { }
return nullptr;
}

View File

@ -40,6 +40,7 @@ extern char **environ;
namespace Libc {
class Env_implementation;
class Vfs_env;
class Kernel;
class Pthreads;
class Timer;
@ -52,6 +53,47 @@ namespace Libc {
}
class Libc::Vfs_env : public Vfs::Env
{
private:
Genode::Env &_env;
Genode::Allocator &_alloc;
Vfs::Io_response_handler &_io_handler;
struct Watch_response_stub : Vfs::Watch_response_handler {
void handle_watch_response(Vfs::Vfs_watch_handle::Context*) override { };
} _watch_stub { };
Vfs::Global_file_system_factory _global_file_system_factory { _alloc };
Vfs::Dir_file_system _root_dir;
public:
Vfs_env(Genode::Env &env,
Genode::Allocator &alloc,
Genode::Xml_node config,
Vfs::Io_response_handler &io_handler)
: _env(env), _alloc(alloc), _io_handler(io_handler),
_root_dir(*this, config, _global_file_system_factory)
{ }
Genode::Env &env() override { return _env; }
Genode::Allocator &alloc() override { return _alloc; }
Vfs::File_system &root_dir() override { return _root_dir; }
Vfs::Io_response_handler &io_handler() override {
return _io_handler; }
Vfs::Watch_response_handler &watch_handler() override {
return _watch_stub; }
};
class Libc::Env_implementation : public Libc::Env
{
private:
@ -85,7 +127,7 @@ class Libc::Env_implementation : public Libc::Env
}
Vfs::Global_file_system_factory _file_system_factory;
Vfs::Dir_file_system _vfs;
Vfs_env _vfs_env;
Genode::Xml_node _config_xml() const override {
return _config.xml(); };
@ -96,8 +138,7 @@ class Libc::Env_implementation : public Libc::Env
Vfs::Io_response_handler &io_response_handler)
:
_env(env), _file_system_factory(alloc),
_vfs(_env, alloc, _vfs_config(), io_response_handler,
_file_system_factory)
_vfs_env(_env, alloc, _vfs_config(), io_response_handler)
{ }
@ -106,7 +147,7 @@ class Libc::Env_implementation : public Libc::Env
*************************/
Vfs::File_system &vfs() override {
return _vfs; }
return _vfs_env.root_dir(); }
Genode::Xml_node libc_config() override {
return _libc_config(); }

View File

@ -210,9 +210,7 @@ class Fatfs::File_system : public Vfs::File_system
}
};
Genode::Env &_env;
Genode::Allocator &_alloc;
Vfs::Io_response_handler &_io_handler;
Vfs::Env &_vfs_env;
FATFS _fatfs;
@ -240,7 +238,7 @@ class Fatfs::File_system : public Vfs::File_system
void _notify(File &file)
{
for (Fatfs_file_watch_handle *h = file.watchers.first(); h; h = h->next())
_io_handler.handle_watch_response(h->context());
_vfs_env.watch_handler().handle_watch_response(h->context());
}
/**
@ -254,7 +252,7 @@ class Fatfs::File_system : public Vfs::File_system
for (Fatfs_dir_watch_handle *h = _dir_watchers.first(); h; h = h->next()) {
if (h->path == parent)
_io_handler.handle_watch_response(h->context());
_vfs_env.watch_handler().handle_watch_response(h->context());
}
}
@ -272,7 +270,7 @@ class Fatfs::File_system : public Vfs::File_system
file.path.import("");
_next_file = &file;
} else {
destroy(_alloc, &file);
destroy(_vfs_env.alloc(), &file);
}
}
@ -296,18 +294,15 @@ class Fatfs::File_system : public Vfs::File_system
handle->file = nullptr;
file.watchers.remove(handle);
if (auto *ctx = handle->context())
_io_handler.handle_watch_response(ctx);
_vfs_env.watch_handler().handle_watch_response(ctx);
}
_close(file);
}
public:
File_system(Genode::Env &env,
Genode::Allocator &alloc,
Genode::Xml_node config,
Vfs::Io_response_handler &io_handler)
: _env(env), _alloc(alloc), _io_handler(io_handler)
File_system(Vfs::Env &env, Genode::Xml_node config)
: _vfs_env(env)
{
{
static unsigned codepage = 0;
@ -394,7 +389,7 @@ class Fatfs::File_system : public Vfs::File_system
/* attempt allocation before modifying blocks */
if (!_next_file)
_next_file = new (_alloc) File();
_next_file = new (_vfs_env.alloc()) File();
handle = new (alloc) Fatfs_file_handle(*this, alloc, vfs_mode);
if (!file) {
@ -516,7 +511,7 @@ class Fatfs::File_system : public Vfs::File_system
} else {
if (!file) {
if (!_next_file)
_next_file = new (_alloc) File();
_next_file = new (_vfs_env.alloc()) File();
file = _next_file;
FRESULT fres = f_open(
@ -827,25 +822,17 @@ struct Fatfs_factory : Vfs::File_system_factory
Inner(Genode::Env &env, Genode::Allocator &alloc) {
Fatfs::block_init(env, alloc); }
Vfs::File_system *create(Genode::Env &env,
Genode::Allocator &alloc,
Genode::Xml_node node,
Vfs::Io_response_handler &handler,
Vfs::File_system &) override
Vfs::File_system *create(Vfs::Env &env, Genode::Xml_node node) override
{
return new (alloc)
Fatfs::File_system(env, alloc, node, handler);
return new (env.alloc())
Fatfs::File_system(env, node);
}
};
Vfs::File_system *create(Genode::Env &env,
Genode::Allocator &alloc,
Genode::Xml_node node,
Vfs::Io_response_handler &io_handler,
Vfs::File_system &root_dir) override
Vfs::File_system *create(Vfs::Env &vfs_env, Genode::Xml_node node) override
{
static Inner factory(env, alloc);
return factory.create(env, alloc, node, io_handler, root_dir);
static Inner factory(vfs_env.env(), vfs_env.alloc());
return factory.create(vfs_env, node);
}
};

View File

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

View File

@ -38,14 +38,14 @@ class Vfs::Dir_file_system : public File_system
Dir_file_system(Dir_file_system const &);
Dir_file_system &operator = (Dir_file_system const &);
Vfs::Env &_env;
/**
* This instance is the root of VFS
*
* Additionally, the root has an empty _name.
*/
bool _vfs_root = false;
File_system &_root_dir;
bool const _vfs_root { &_env.root_dir() == this };
struct Dir_vfs_handle : Vfs_handle
{
@ -363,14 +363,11 @@ class Vfs::Dir_file_system : public File_system
public:
Dir_file_system(Genode::Env &env,
Genode::Allocator &alloc,
Dir_file_system(Vfs::Env &env,
Genode::Xml_node node,
Io_response_handler &io_handler,
File_system_factory &fs_factory,
File_system &root_dir)
File_system_factory &fs_factory)
:
_root_dir(root_dir)
_env(env)
{
using namespace Genode;
@ -386,14 +383,13 @@ class Vfs::Dir_file_system : public File_system
/* traverse into <dir> nodes */
if (sub_node.has_type("dir")) {
_append_file_system(new (alloc)
Dir_file_system(env, alloc, sub_node, io_handler,
fs_factory, _root_dir));
_append_file_system(new (_env.alloc())
Dir_file_system(_env, sub_node, fs_factory));
continue;
}
File_system * const fs =
fs_factory.create(env, alloc, sub_node, io_handler, _root_dir);
fs_factory.create(_env, sub_node);
if (fs) {
_append_file_system(fs);
@ -413,20 +409,6 @@ class Vfs::Dir_file_system : public File_system
}
}
/**
* Constructor used for creating the root directory
*/
Dir_file_system(Genode::Env &env,
Genode::Allocator &alloc,
Genode::Xml_node node,
Io_response_handler &io_handler,
File_system_factory &fs_factory)
:
Dir_file_system(env, alloc, node, io_handler, fs_factory, *this)
{
_vfs_root = true;
}
/*********************************
** Directory-service interface **
*********************************/

View File

@ -0,0 +1,43 @@
/*
* \brief Cross-plugin VFS environment
* \author Emery Hemingway
* \date 2018-04-02
*/
/*
* Copyright (C) 2018 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU Affero General Public License version 3.
*/
#ifndef _INCLUDE__VFS__ENV_H_
#define _INCLUDE__VFS__ENV_H_
#include <vfs/file_system.h>
#include <base/allocator.h>
#include <base/env.h>
namespace Vfs { struct Env; }
struct Vfs::Env : Interface
{
virtual Genode::Env &env() = 0;
/**
* Allocator for creating stuctures shared
* across open VFS handles.
*/
virtual Genode::Allocator &alloc() = 0;
/**
* VFS root file-system
*/
virtual File_system &root_dir() = 0;
virtual Io_response_handler &io_handler() = 0;
virtual Watch_response_handler &watch_handler() = 0;
};
#endif /* _INCLUDE__VFS__ENV_H_ */

View File

@ -21,6 +21,7 @@
namespace Vfs {
class Vfs_handle;
struct Io_response_handler;
struct Watch_response_handler;
struct File_io_service;
}
@ -28,11 +29,14 @@ namespace Vfs {
struct Vfs::Io_response_handler : Interface
{
virtual void handle_io_response(Vfs_handle::Context *context) = 0;
virtual void handle_watch_response(Vfs_watch_handle::Context*) {
Genode::warning(__func__, " discarding event"); };
};
struct Vfs::Watch_response_handler : Interface
{
virtual void handle_watch_response(Vfs_watch_handle::Context*) = 0;
};
struct Vfs::File_io_service : Interface
{
enum General_error { ERR_FD_INVALID, NUM_GENERAL_ERRORS };

View File

@ -5,7 +5,7 @@
*/
/*
* Copyright (C) 2014-2017 Genode Labs GmbH
* Copyright (C) 2014-2018 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU Affero General Public License version 3.
@ -14,6 +14,7 @@
#ifndef _INCLUDE__VFS__FILE_SYSTEM_FACTORY_H_
#define _INCLUDE__VFS__FILE_SYSTEM_FACTORY_H_
#include <vfs/env.h>
#include <vfs/file_system.h>
namespace Vfs {
@ -28,17 +29,10 @@ struct Vfs::File_system_factory : Interface
/**
* Create and return a new file-system
*
* \param env Env for service connections
* \param alloc internal file-system allocator
* \param env Env of VFS root
* \param config file-system configuration
* \param io_handler callback handler
* \param root_dir VFS root directory
*/
virtual File_system *create(Genode::Env &env,
Genode::Allocator &alloc,
Xml_node config,
Io_response_handler &io_handler,
File_system &root_dir) = 0;
virtual File_system *create(Vfs::Env &env, Xml_node config) = 0;
};
@ -66,11 +60,8 @@ class Vfs::Global_file_system_factory : public Vfs::File_system_factory
template <typename FILE_SYSTEM>
void _add_builtin_fs();
Vfs::File_system *_try_create(Genode::Env &env,
Genode::Allocator &alloc,
Genode::Xml_node node,
Io_response_handler &io_handler,
Vfs::File_system &root_dir);
Vfs::File_system *_try_create(Vfs::Env &env,
Genode::Xml_node config);
/**
* Return name of factory provided by the shared library
@ -95,14 +86,13 @@ class Vfs::Global_file_system_factory : public Vfs::File_system_factory
/**
* \throw Factory_not_available
*/
Vfs::File_system_factory &_load_factory(Genode::Env &env,
Genode::Allocator &alloc,
Vfs::File_system_factory &_load_factory(Vfs::Env &env,
Library_name const &lib_name);
/**
* Try to load external File_system_factory provider
*/
bool _probe_external_factory(Genode::Env &env, Genode::Allocator &alloc,
bool _probe_external_factory(Vfs::Env &env,
Genode::Xml_node node);
public:
@ -112,14 +102,12 @@ class Vfs::Global_file_system_factory : public Vfs::File_system_factory
*
* \param alloc internal factory allocator
*/
Global_file_system_factory(Genode::Allocator &md_alloc);
Global_file_system_factory(Genode::Allocator &alloc);
/**
* File_system_factory interface
*/
File_system *create(Genode::Env &, Genode::Allocator &,
Genode::Xml_node, Io_response_handler &,
File_system &) override;
File_system *create(Vfs::Env&, Genode::Xml_node) override;
/**
* Register an additional factory for new file-system type

View File

@ -0,0 +1,59 @@
/*
* \brief Cross-plugin VFS environment
* \author Emery Hemingway
* \date 2018-04-04
*/
/*
* Copyright (C) 2018 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU Affero General Public License version 3.
*/
#ifndef _INCLUDE__VFS__SIMPLE_ENV_H_
#define _INCLUDE__VFS__SIMPLE_ENV_H_
#include <vfs/file_system_factory.h>
#include <vfs/dir_file_system.h>
#include <vfs/env.h>
namespace Vfs { struct Simple_env; }
class Vfs::Simple_env : public Vfs::Env
{
private:
Genode::Env &_env;
Genode::Allocator &_alloc;
struct Io_response_dummy : Vfs::Io_response_handler {
void handle_io_response(Vfs::Vfs_handle::Context*) override { }
} _io_dummy { };
struct Watch_response_dummy : Vfs::Watch_response_handler {
void handle_watch_response(Vfs::Vfs_watch_handle::Context*) override { }
} _watch_dummy { };
Vfs::Global_file_system_factory _fs_factory { _alloc };
Vfs::Dir_file_system _root_dir;
public:
Simple_env(Genode::Env &env,
Genode::Allocator &alloc,
Genode::Xml_node config)
:
_env(env), _alloc(alloc), _root_dir(*this, config, _fs_factory)
{ }
Genode::Env &env() override { return _env; }
Genode::Allocator &alloc() override { return _alloc; }
Vfs::File_system &root_dir() override { return _root_dir; }
Vfs::Io_response_handler &io_handler() override { return _io_dummy; }
Vfs::Watch_response_handler &watch_handler() override { return _watch_dummy; }
};
#endif /* _INCLUDE__VFS__SIMPLE_ENV_H_ */

View File

@ -13,8 +13,7 @@
/* Genode includes */
#include <base/attached_rom_dataspace.h>
#include <vfs/file_system_factory.h>
#include <vfs/dir_file_system.h>
#include <vfs/simple_env.h>
#include <base/component.h>
/* public CLI-monitor includes */
@ -148,18 +147,9 @@ struct Cli_monitor::Main
Heap _heap { _env.ram(), _env.rm() };
struct Io_response_handler : Vfs::Io_response_handler
{
void handle_io_response(Vfs::Vfs_handle::Context *) override { }
} io_response_handler { };
Vfs::Simple_env _vfs_env { _env, _heap, _vfs_config() };
Vfs::Global_file_system_factory _global_file_system_factory { _heap };
/* initialize virtual file system */
Vfs::Dir_file_system _root_dir { _env, _heap, _vfs_config(), io_response_handler,
_global_file_system_factory };
Subsystem_config_registry _subsystem_config_registry { _root_dir, _heap, _env.ep() };
Subsystem_config_registry _subsystem_config_registry { _vfs_env.root_dir(), _heap, _env.ep() };
template <typename T>
struct Registered : T

View File

@ -26,7 +26,7 @@ class Vfs::Block_file_system : public Single_file_system
{
private:
Genode::Allocator &_alloc;
Vfs::Env &_env;
typedef Genode::String<64> Label;
Label _label;
@ -39,8 +39,9 @@ class Vfs::Block_file_system : public Single_file_system
char *_block_buffer;
unsigned _block_buffer_count;
Genode::Allocator_avl _tx_block_alloc { &_alloc };
Block::Connection _block;
Genode::Allocator_avl _tx_block_alloc { &_env.alloc() };
Block::Connection _block {
_env.env(), &_tx_block_alloc, 128*1024, _label.string() };
Genode::size_t _block_size = 0;
Block::sector_t _block_count = 0;
Block::Session::Operations _block_ops { };
@ -334,18 +335,13 @@ class Vfs::Block_file_system : public Single_file_system
public:
Block_file_system(Genode::Env &env,
Genode::Allocator &alloc,
Genode::Xml_node config,
Io_response_handler &,
File_system &)
Block_file_system(Vfs::Env &env, Genode::Xml_node config)
:
Single_file_system(NODE_TYPE_BLOCK_DEVICE, name(), config),
_alloc(alloc),
_env(env),
_label(config.attribute_value("label", Label())),
_block_buffer(0),
_block_buffer_count(1),
_block(env, &_tx_block_alloc, 128*1024, _label.string()),
_tx_source(_block.tx()),
_readable(false),
_writeable(false),
@ -359,7 +355,7 @@ class Vfs::Block_file_system : public Single_file_system
_readable = _block_ops.supported(Block::Packet_descriptor::READ);
_writeable = _block_ops.supported(Block::Packet_descriptor::WRITE);
_block_buffer = new (_alloc) char[_block_buffer_count * _block_size];
_block_buffer = new (_env.alloc()) char[_block_buffer_count * _block_size];
_block.tx_channel()->sigh_ready_to_submit(_source_submit_cap);
}
@ -368,7 +364,7 @@ class Vfs::Block_file_system : public Single_file_system
{
_signal_receiver.dissolve(&_signal_context);
destroy(_alloc, _block_buffer);
destroy(_env.alloc(), _block_buffer);
}
static char const *name() { return "block"; }

View File

@ -5,7 +5,7 @@
*/
/*
* Copyright (C) 2014-2017 Genode Labs GmbH
* Copyright (C) 2014-2018 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU Affero General Public License version 3.
@ -66,14 +66,8 @@ struct Vfs::Builtin_entry : Vfs::Global_file_system_factory::Entry_base
{
Builtin_entry() : Entry_base(FILE_SYSTEM::name()) { }
Vfs::File_system *create(Genode::Env &env,
Genode::Allocator &alloc,
Genode::Xml_node node,
Io_response_handler &io_handler,
File_system &root_dir) override
{
return new (alloc) FILE_SYSTEM(env, alloc, node, io_handler, root_dir);
}
Vfs::File_system *create(Vfs::Env &env, Genode::Xml_node node) override {
return new (env.alloc()) FILE_SYSTEM(env, node); }
};
@ -86,13 +80,10 @@ struct Vfs::External_entry : Vfs::Global_file_system_factory::Entry_base
:
Entry_base(name), _fs_factory(fs_factory) { }
File_system *create(Genode::Env &env,
Genode::Allocator &alloc,
Genode::Xml_node node,
Io_response_handler &io_handler,
File_system &root_dir) override
File_system *create(Vfs::Env &env,
Genode::Xml_node config) override
{
return _fs_factory.create(env, alloc, node, io_handler, root_dir);
return _fs_factory.create(env, config);
}
};
@ -110,19 +101,13 @@ void Vfs::Global_file_system_factory::_add_builtin_fs()
/**
* Lookup and create File_system instance
*/
Vfs::File_system *Vfs::Global_file_system_factory::_try_create(Genode::Env &env,
Genode::Allocator &alloc,
Genode::Xml_node node,
Io_response_handler &io_handler,
File_system &root_dir)
Vfs::File_system*
Vfs::Global_file_system_factory::_try_create(Vfs::Env &env,
Genode::Xml_node config)
{
for (Entry_base *e = _list.first(); e; e = e->next()) {
if (e->matches(node)) {
return e->create(env, alloc, node, io_handler, root_dir);
}
}
return 0;
for (Entry_base *e = _list.first(); e; e = e->next())
if (e->matches(config)) return e->create(env, config);
return nullptr;
}
@ -153,15 +138,14 @@ Library_name Vfs::Global_file_system_factory::_library_name(Node_name const &nod
/**
* \throw Factory_not_available
*/
Vfs::File_system_factory &Vfs::Global_file_system_factory::_load_factory(Genode::Env &env,
Genode::Allocator &alloc,
Vfs::File_system_factory &Vfs::Global_file_system_factory::_load_factory(Vfs::Env &env,
Library_name const &lib_name)
{
Genode::Shared_object *shared_object = nullptr;
try {
shared_object = new (alloc)
Genode::Shared_object(env, alloc, lib_name.string(),
shared_object = new (env.alloc())
Genode::Shared_object(env.env(), env.alloc(), lib_name.string(),
Genode::Shared_object::BIND_LAZY,
Genode::Shared_object::DONT_KEEP);
@ -180,7 +164,7 @@ Vfs::File_system_factory &Vfs::Global_file_system_factory::_load_factory(Genode:
Genode::Cstring(_factory_symbol()),
"' in '", lib_name, "'");
Genode::destroy(alloc, shared_object);
Genode::destroy(env.alloc(), shared_object);
throw Factory_not_available();
}
}
@ -189,16 +173,15 @@ Vfs::File_system_factory &Vfs::Global_file_system_factory::_load_factory(Genode:
/**
* Try to load external File_system_factory provider
*/
bool Vfs::Global_file_system_factory::_probe_external_factory(Genode::Env &env,
Genode::Allocator &alloc,
bool Vfs::Global_file_system_factory::_probe_external_factory(Vfs::Env &env,
Genode::Xml_node node)
{
Library_name const lib_name = _library_name(_node_name(node));
try {
_list.insert(new (alloc)
_list.insert(new (env.alloc())
External_entry(_node_name(node).string(),
_load_factory(env, alloc, lib_name)));
_load_factory(env, lib_name)));
return true;
} catch (Factory_not_available) { return false; }
@ -208,29 +191,26 @@ bool Vfs::Global_file_system_factory::_probe_external_factory(Genode::Env
/**
* Create and return a new file-system
*/
Vfs::File_system *Vfs::Global_file_system_factory::create(Genode::Env &env,
Genode::Allocator &alloc,
Genode::Xml_node node,
Io_response_handler &io_handler,
File_system &root_dir)
Vfs::File_system *Vfs::Global_file_system_factory::create(Vfs::Env &env,
Genode::Xml_node node)
{
try {
/* try if type is handled by the currently registered fs types */
if (Vfs::File_system *fs = _try_create(env, alloc, node, io_handler, root_dir))
if (Vfs::File_system *fs = _try_create(env, node))
return fs;
/* if the builtin fails, do not try loading an external */
} catch (...) { return 0; }
} catch (...) { return nullptr; }
try {
/* probe for file system implementation available as shared lib */
if (_probe_external_factory(env, alloc, node)) {
if (_probe_external_factory(env, node)) {
/* try again with the new file system type loaded */
if (Vfs::File_system *fs = _try_create(env, alloc, node, io_handler, root_dir))
if (Vfs::File_system *fs = _try_create(env, node))
return fs;
}
} catch (...) { }
return 0;
return nullptr;
}

View File

@ -38,9 +38,8 @@ class Vfs::Fs_file_system : public File_system
*/
Lock _lock { };
Genode::Env &_env;
Genode::Allocator_avl _fs_packet_alloc;
Io_response_handler &_event_handler;
Vfs::Env &_env;
Genode::Allocator_avl _fs_packet_alloc { &_env.alloc() };
typedef Genode::String<64> Label_string;
Label_string _label;
@ -82,7 +81,7 @@ class Vfs::Fs_file_system : public File_system
friend class Genode::Id_space<::File_system::Node>;
::File_system::Connection &_fs;
Io_response_handler &_event_handler;
Io_response_handler &_io_handler;
bool _queue_read(file_size count, file_size const seek_offset)
{
@ -145,7 +144,7 @@ class Vfs::Fs_file_system : public File_system
* Notify anyone who might have failed on
* 'alloc_packet()' or 'submit_packet()'
*/
_event_handler.handle_io_response(nullptr);
_io_handler.handle_io_response(nullptr);
return READ_OK;
}
@ -158,7 +157,7 @@ class Vfs::Fs_file_system : public File_system
:
Vfs_handle(fs, fs, alloc, status_flags),
Handle_space::Element(*this, space, node_handle),
_fs(fs_connection), _event_handler(io_handler)
_fs(fs_connection), _io_handler(io_handler)
{ }
::File_system::File_handle file_handle() const
@ -227,7 +226,7 @@ class Vfs::Fs_file_system : public File_system
* Notify anyone who might have failed on
* 'alloc_packet()' or 'submit_packet()'
*/
_event_handler.handle_io_response(nullptr);
_io_handler.handle_io_response(nullptr);
return SYNC_OK;
}
@ -377,16 +376,20 @@ class Vfs::Fs_file_system : public File_system
struct Post_signal_hook : Genode::Entrypoint::Post_signal_hook
{
Genode::Entrypoint &_ep;
Io_response_handler &_event_handler;
Io_response_handler &_io_handler;
Watch_response_handler &_watch_handler;
List<Vfs_handle::Context> _context_list { };
List<Vfs_watch_handle::Context>
_watch_context_list { };
Lock _list_lock { };
bool _notify_all { false };
Post_signal_hook(Genode::Entrypoint &ep,
Io_response_handler &io_handler)
: _ep(ep), _event_handler(io_handler) { }
Post_signal_hook(Vfs::Env &env)
:
_ep(env.env().ep()),
_io_handler(env.io_handler()),
_watch_handler(env.watch_handler())
{ }
void arm_io_event(Vfs_handle::Context *context)
{
@ -453,7 +456,7 @@ class Vfs::Fs_file_system : public File_system
}
if (context || notify_all)
_event_handler.handle_io_response(context);
_io_handler.handle_io_response(context);
/* done if no contexts and all notified */
} while (context);
@ -466,13 +469,13 @@ class Vfs::Fs_file_system : public File_system
context = _watch_context_list.first();
if (!context) break;
_watch_context_list.remove(context);
_event_handler.handle_watch_response(context);
_watch_handler.handle_watch_response(context);
}
}
}
};
Post_signal_hook _post_signal_hook { _env.ep(), _event_handler };
Post_signal_hook _post_signal_hook { _env };
file_size _read(Fs_vfs_handle &handle, void *buf,
file_size const count, file_size const seek_offset)
@ -498,7 +501,7 @@ class Vfs::Fs_file_system : public File_system
source.submit_packet(packet_in);
while (handle.queued_read_state != Handle_state::Queued_state::ACK) {
_env.ep().wait_and_dispatch_one_io_signal();
_env.env().ep().wait_and_dispatch_one_io_signal();
}
/* obtain result packet descriptor with updated status info */
@ -627,25 +630,19 @@ class Vfs::Fs_file_system : public File_system
}
Genode::Io_signal_handler<Fs_file_system> _ack_handler {
_env.ep(), *this, &Fs_file_system::_handle_ack };
_env.env().ep(), *this, &Fs_file_system::_handle_ack };
Genode::Io_signal_handler<Fs_file_system> _ready_handler {
_env.ep(), *this, &Fs_file_system::_ready_to_submit };
_env.env().ep(), *this, &Fs_file_system::_ready_to_submit };
public:
Fs_file_system(Genode::Env &env,
Genode::Allocator &alloc,
Genode::Xml_node config,
Io_response_handler &event_handler,
File_system &)
Fs_file_system(Vfs::Env &env, Genode::Xml_node config)
:
_env(env),
_fs_packet_alloc(&alloc),
_event_handler(event_handler),
_label(config.attribute_value("label", Label_string())),
_root( config.attribute_value("root", Root_string())),
_fs(env, _fs_packet_alloc,
_fs(_env.env(), _fs_packet_alloc,
_label.string(), _root.string(),
config.attribute_value("writeable", true),
::File_system::DEFAULT_TX_BUF_SIZE)
@ -673,7 +670,7 @@ class Vfs::Fs_file_system : public File_system
try {
::File_system::Node_handle node = _fs.node(path);
Fs_handle_guard node_guard(*this, _fs, node, _handle_space,
_fs, _event_handler);
_fs, _env.io_handler());
status = _fs.status(node);
}
catch (::File_system::Lookup_failed) { return STAT_ERR_NO_ENTRY; }
@ -709,7 +706,7 @@ class Vfs::Fs_file_system : public File_system
try {
::File_system::Dir_handle dir = _fs.dir(dir_path.base(), false);
Fs_handle_guard dir_guard(*this, _fs, dir, _handle_space, _fs,
_event_handler);
_env.io_handler());
_fs.unlink(dir, file_name.base() + 1);
}
@ -745,12 +742,12 @@ class Vfs::Fs_file_system : public File_system
_fs.dir(from_dir_path.base(), false);
Fs_handle_guard from_dir_guard(*this, _fs, from_dir,
_handle_space, _fs, _event_handler);
_handle_space, _fs, _env.io_handler());
::File_system::Dir_handle to_dir = _fs.dir(to_dir_path.base(),
false);
Fs_handle_guard to_dir_guard(*this, _fs, to_dir, _handle_space,
_fs, _event_handler);
_fs, _env.io_handler());
_fs.move(from_dir, from_file_name.base() + 1,
to_dir, to_file_name.base() + 1);
@ -769,7 +766,7 @@ class Vfs::Fs_file_system : public File_system
::File_system::Node_handle node;
try { node = _fs.node(path); } catch (...) { return 0; }
Fs_handle_guard node_guard(*this, _fs, node, _handle_space, _fs,
_event_handler);
_env.io_handler());
::File_system::Status status = _fs.status(node);
@ -781,7 +778,7 @@ class Vfs::Fs_file_system : public File_system
try {
::File_system::Node_handle node = _fs.node(path);
Fs_handle_guard node_guard(*this, _fs, node, _handle_space,
_fs, _event_handler);
_fs, _env.io_handler());
::File_system::Status status = _fs.status(node);
@ -827,7 +824,7 @@ class Vfs::Fs_file_system : public File_system
try {
::File_system::Dir_handle dir = _fs.dir(dir_path.base(), false);
Fs_handle_guard dir_guard(*this, _fs, dir, _handle_space, _fs,
_event_handler);
_env.io_handler());
::File_system::File_handle file = _fs.file(dir,
file_name.base() + 1,
@ -835,7 +832,7 @@ class Vfs::Fs_file_system : public File_system
*out_handle = new (alloc)
Fs_vfs_file_handle(*this, alloc, vfs_mode, _handle_space,
file, _fs, _event_handler);
file, _fs, _env.io_handler());
}
catch (::File_system::Lookup_failed) { return OPEN_ERR_UNACCESSIBLE; }
catch (::File_system::Permission_denied) { return OPEN_ERR_NO_PERM; }
@ -863,7 +860,7 @@ class Vfs::Fs_file_system : public File_system
*out_handle = new (alloc)
Fs_vfs_dir_handle(*this, alloc, ::File_system::READ_ONLY,
_handle_space, dir, _fs, _event_handler);
_handle_space, dir, _fs, _env.io_handler());
}
catch (::File_system::Lookup_failed) { return OPENDIR_ERR_LOOKUP_FAILED; }
catch (::File_system::Name_too_long) { return OPENDIR_ERR_NAME_TOO_LONG; }
@ -895,7 +892,7 @@ class Vfs::Fs_file_system : public File_system
false);
Fs_handle_guard from_dir_guard(*this, _fs, dir_handle,
_handle_space, _fs, _event_handler);
_handle_space, _fs, _env.io_handler());
::File_system::Symlink_handle symlink_handle =
_fs.symlink(dir_handle, symlink_name.base() + 1, create);
@ -904,7 +901,7 @@ class Vfs::Fs_file_system : public File_system
Fs_vfs_symlink_handle(*this, alloc,
::File_system::READ_ONLY,
_handle_space, symlink_handle, _fs,
_event_handler);
_env.io_handler());
return OPENLINK_OK;
}

View File

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

View File

@ -91,15 +91,12 @@ class Vfs::Log_file_system : public Single_file_system
public:
Log_file_system(Genode::Env &env,
Genode::Allocator&,
Genode::Xml_node config,
Io_response_handler &,
File_system &)
Log_file_system(Vfs::Env &env,
Genode::Xml_node config)
:
Single_file_system(NODE_TYPE_CHAR_DEVICE, name(), config),
_label(config.attribute_value("label", Label())),
_log(_log_session(env))
_log(_log_session(env.env()))
{ }
static const char *name() { return "log"; }

View File

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

View File

@ -143,7 +143,7 @@ class Vfs_ram::Node : private Genode::Avl_node<Node>, private Genode::Lock
void close(Io_handle &handle) { _io_handles.remove(&handle); }
void close(Watch_handle &handle) { _watch_handles.remove(&handle); }
void notify(Io_response_handler &handler)
void notify(Watch_response_handler &handler)
{
for (Watch_handle *h = _watch_handles.first(); h; h = h->next()) {
if (auto *ctx = h->context()) {
@ -479,10 +479,8 @@ class Vfs::Ram_file_system : public Vfs::File_system
friend class Genode::List<Vfs_ram::Watch_handle>;
Genode::Env &_env;
Genode::Allocator &_alloc;
Io_response_handler &_io_handler;
Vfs_ram::Directory _root = { "" };
Vfs::Env &_env;
Vfs_ram::Directory _root = { "" };
Vfs_ram::Node *lookup(char const *path, bool return_parent = false)
{
@ -538,22 +536,17 @@ class Vfs::Ram_file_system : public Vfs::File_system
return;
}
} else if (Directory *dir = dynamic_cast<Directory*>(node)) {
dir->empty(_alloc);
dir->empty(_env.alloc());
}
destroy(_alloc, node);
destroy(_env.alloc(), node);
}
public:
Ram_file_system(Genode::Env &env,
Genode::Allocator &alloc,
Genode::Xml_node,
Io_response_handler &io_handler,
File_system &)
: _env(env), _alloc(alloc), _io_handler(io_handler) { }
Ram_file_system(Vfs::Env &env, Genode::Xml_node) : _env(env) { }
~Ram_file_system() { _root.empty(_alloc); }
~Ram_file_system() { _root.empty(_env.alloc()); }
/*********************************
@ -606,10 +599,10 @@ class Vfs::Ram_file_system : public Vfs::File_system
if (strlen(name) >= MAX_NAME_LEN)
return OPEN_ERR_NAME_TOO_LONG;
try { file = new (_alloc) File(name, _alloc); }
try { file = new (_env.alloc()) File(name, _env.alloc()); }
catch (Out_of_memory) { return OPEN_ERR_NO_SPACE; }
parent->adopt(file);
parent->notify(_io_handler);
parent->notify(_env.watch_handler());
} else {
Node *node = lookup(path);
if (!node) return OPEN_ERR_UNACCESSIBLE;
@ -660,11 +653,11 @@ class Vfs::Ram_file_system : public Vfs::File_system
if (parent->child(name))
return OPENDIR_ERR_NODE_ALREADY_EXISTS;
try { dir = new (_alloc) Directory(name); }
try { dir = new (_env.alloc()) Directory(name); }
catch (Out_of_memory) { return OPENDIR_ERR_NO_SPACE; }
parent->adopt(dir);
parent->notify(_io_handler);
parent->notify(_env.watch_handler());
} else {
Node *node = lookup(path);
@ -716,13 +709,13 @@ class Vfs::Ram_file_system : public Vfs::File_system
if (strlen(name) >= MAX_NAME_LEN)
return OPENLINK_ERR_NAME_TOO_LONG;
try { link = new (_alloc) Symlink(name); }
try { link = new (_env.alloc()) Symlink(name); }
catch (Out_of_memory) { return OPENLINK_ERR_NO_SPACE; }
link->lock();
parent->adopt(link);
link->unlock();
parent->notify(_io_handler);
parent->notify(_env.watch_handler());
} else {
if (!node) return OPENLINK_ERR_LOOKUP_FAILED;
@ -763,9 +756,9 @@ class Vfs::Ram_file_system : public Vfs::File_system
destroy(vfs_handle->alloc(), ram_handle);
if (ram_handle->node.unlinked() && !ram_handle->node.opened()) {
destroy(_alloc, &ram_handle->node);
destroy(_env.alloc(), &ram_handle->node);
} else if (node_modified) {
node.notify(_io_handler);
node.notify(_env.watch_handler());
}
}
@ -847,8 +840,8 @@ class Vfs::Ram_file_system : public Vfs::File_system
from_node->name(new_name);
to_dir->adopt(from_node);
from_dir->notify(_io_handler);
to_dir->notify(_io_handler);
from_dir->notify(_env.watch_handler());
to_dir->notify(_env.watch_handler());
return RENAME_OK;
}
@ -866,7 +859,7 @@ class Vfs::Ram_file_system : public Vfs::File_system
node->lock();
parent->release(node);
parent->notify(_io_handler);
parent->notify(_env.watch_handler());
remove(node);
return UNLINK_OK;
}
@ -888,22 +881,22 @@ class Vfs::Ram_file_system : public Vfs::File_system
char *local_addr = nullptr;
try {
ds_cap = _env.ram().alloc(len);
ds_cap = _env.env().ram().alloc(len);
local_addr = _env.rm().attach(ds_cap);
local_addr = _env.env().rm().attach(ds_cap);
file->read(local_addr, file->length(), 0);
_env.rm().detach(local_addr);
_env.env().rm().detach(local_addr);
} catch(...) {
_env.rm().detach(local_addr);
_env.ram().free(ds_cap);
_env.env().rm().detach(local_addr);
_env.env().ram().free(ds_cap);
return Dataspace_capability();
}
return ds_cap;
}
void release(char const *, Dataspace_capability ds_cap) override {
_env.ram().free(
_env.env().ram().free(
static_cap_cast<Genode::Ram_dataspace>(ds_cap)); }
@ -997,7 +990,7 @@ class Vfs::Ram_file_system : public Vfs::File_system
if (handle->modifying) {
handle->modifying = false;
handle->node.close(*handle);
handle->node.notify(_io_handler);
handle->node.notify(_env.watch_handler());
handle->node.open(*handle);
}
return SYNC_OK;

View File

@ -102,15 +102,12 @@ class Vfs::Rom_file_system : public Single_file_system
public:
Rom_file_system(Genode::Env &env,
Genode::Allocator&,
Genode::Xml_node config,
Io_response_handler &,
File_system &)
Rom_file_system(Vfs::Env &env,
Genode::Xml_node config)
:
Single_file_system(NODE_TYPE_FILE, name(), config),
_label(config),
_rom(env, _label.string)
_rom(env.env(), _label.string)
{ }
static char const *name() { return "rom"; }

View File

@ -86,14 +86,10 @@ class Vfs::Rtc_file_system : public Single_file_system
public:
Rtc_file_system(Genode::Env &env,
Genode::Allocator&,
Genode::Xml_node config,
Io_response_handler &,
File_system &)
Rtc_file_system(Vfs::Env &env, Genode::Xml_node config)
:
Single_file_system(NODE_TYPE_CHAR_DEVICE, name(), config),
_rtc(env)
_rtc(env.env())
{ }
static char const *name() { return "rtc"; }

View File

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

View File

@ -512,13 +512,9 @@ class Vfs::Tar_file_system : public File_system
public:
Tar_file_system(Genode::Env &env,
Genode::Allocator &alloc,
Genode::Xml_node config,
Io_response_handler &,
File_system &)
Tar_file_system(Vfs::Env &env, Genode::Xml_node config)
:
_env(env), _alloc(alloc),
_env(env.env()), _alloc(env.alloc()),
_rom_name(config.attribute_value("name", Rom_name())),
_root_node("", 0),
_cached_num_dirent(_root_node)

View File

@ -105,15 +105,11 @@ class Vfs::Terminal_file_system : public Single_file_system
public:
Terminal_file_system(Genode::Env &env,
Genode::Allocator &,
Genode::Xml_node config,
Io_response_handler &io_handler,
File_system &)
Terminal_file_system(Vfs::Env &env, Genode::Xml_node config)
:
Single_file_system(NODE_TYPE_CHAR_DEVICE, name(), config),
_label(config.attribute_value("label", Label())),
_env(env), _io_handler(io_handler)
_env(env.env()), _io_handler(env.io_handler())
{
/* register for read-avail notification */
_terminal.read_avail_sigh(_read_avail_handler);

View File

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

View File

@ -11,8 +11,7 @@
* under the terms of the GNU Affero General Public License version 3.
*/
#include <vfs/dir_file_system.h>
#include <vfs/file_system_factory.h>
#include <vfs/simple_env.h>
#include <os/path.h>
#include <report_session/report_session.h>
#include <root/component.h>
@ -199,16 +198,7 @@ class Fs_report::Root : public Genode::Root_component<Session_component>
}
}
struct Io_dummy : Io_response_handler {
void handle_io_response(Vfs::Vfs_handle::Context*) override { }
} _io_response_handler { };
Vfs::Global_file_system_factory _global_file_system_factory { _heap };
Vfs::Dir_file_system _vfs {
_env, _heap, vfs_config(),
_io_response_handler,
_global_file_system_factory };
Vfs::Simple_env _vfs_env { _env, _heap, vfs_config() };
Genode::Signal_handler<Root> _config_dispatcher {
_env.ep(), *this, &Root::_config_update };
@ -216,7 +206,7 @@ class Fs_report::Root : public Genode::Root_component<Session_component>
void _config_update()
{
_config_rom.update();
_vfs.apply_config(vfs_config());
_vfs_env.root_dir().apply_config(vfs_config());
}
protected:
@ -246,7 +236,7 @@ class Fs_report::Root : public Genode::Root_component<Session_component>
}
return new (md_alloc())
Session_component(_env, _heap, _vfs, label, buffer_size);
Session_component(_env, _heap, _vfs_env.root_dir(), label, buffer_size);
}
public:
@ -261,13 +251,13 @@ class Fs_report::Root : public Genode::Root_component<Session_component>
struct Fs_report::Main
{
Env &env;
Genode::Env &env;
Sliced_heap sliced_heap { env.ram(), env.rm() };
Root root { env, sliced_heap };
Main(Env &env) : env(env)
Main(Genode::Env &env) : env(env)
{
env.parent().announce(env.ep().manage(root));
}

View File

@ -34,8 +34,10 @@ namespace Vfs_server {
using namespace Vfs;
class Session_component;
class Io_response_handler;
class Watch_response_handler;
class Vfs_env;
class Root;
class Event_response_handler;
typedef Genode::Registered<Session_component> Registered_session;
typedef Genode::Registry<Registered_session> Session_registry;
@ -66,7 +68,7 @@ class Vfs_server::Session_component : public File_system::Session_rpc_object,
Genode::Signal_handler<Session_component> _process_packet_handler;
Vfs::Dir_file_system &_vfs;
Vfs::File_system &_vfs;
/*
* The root node needs be allocated with the session struct
@ -375,12 +377,12 @@ class Vfs_server::Session_component : public File_system::Session_rpc_object,
* \param writable whether the session can modify files
*/
Session_component(Genode::Env &env,
char const *label,
Genode::Ram_quota ram_quota,
Genode::Cap_quota cap_quota,
size_t tx_buf_size,
Vfs::Dir_file_system &vfs,
Session_component(Genode::Env &env,
char const *label,
Genode::Ram_quota ram_quota,
Genode::Cap_quota cap_quota,
size_t tx_buf_size,
Vfs::File_system &vfs,
char const *root_path,
bool writable)
:
@ -675,16 +677,16 @@ class Vfs_server::Session_component : public File_system::Session_rpc_object,
};
/**
* Global vfs event handler
* Global I/O event handler
*/
struct Vfs_server::Event_response_handler : Vfs::Io_response_handler
struct Vfs_server::Io_response_handler : Vfs::Io_response_handler
{
Session_registry &_session_registry;
bool _in_progress { false };
bool _handle_general_io { false };
Event_response_handler(Session_registry &session_registry)
Io_response_handler(Session_registry &session_registry)
: _session_registry(session_registry) { }
void handle_io_response(Vfs::Vfs_handle::Context *context) override
@ -711,7 +713,13 @@ struct Vfs_server::Event_response_handler : Vfs::Io_response_handler
_in_progress = false;
}
};
/**
* Global VFS watch handler
*/
struct Vfs_server::Watch_response_handler : Vfs::Watch_response_handler
{
void handle_watch_response(Vfs::Vfs_watch_handle::Context *context) override
{
if (context)
@ -720,14 +728,47 @@ struct Vfs_server::Event_response_handler : Vfs::Io_response_handler
};
class Vfs_server::Root : public Genode::Root_component<Session_component>
class Vfs_server::Vfs_env final : Vfs::Env
{
private:
Genode::Env &_env;
Genode::Heap _heap { &_env.ram(), &_env.rm() };
/* heap for internal VFS allocation */
Genode::Heap _vfs_heap { &_env.ram(), &_env.rm() };
Io_response_handler _io_handler;
Watch_response_handler _watch_handler { };
Vfs::Global_file_system_factory _global_file_system_factory { _heap };
Vfs::Dir_file_system _root_dir;
public:
Vfs_env(Genode::Env &env, Genode::Xml_node config,
Session_registry &sessions)
: _env(env), _io_handler(sessions),
_root_dir(*this, config, _global_file_system_factory)
{ }
Genode::Env &env() override { return _env; }
Genode::Allocator &alloc() override { return _heap; }
Vfs::File_system &root_dir() override { return _root_dir; }
Io_response_handler &io_handler() override {
return _io_handler; }
Watch_response_handler &watch_handler() override {
return _watch_handler; }
};
class Vfs_server::Root : public Genode::Root_component<Session_component>
{
private:
Genode::Env &_env;
Genode::Attached_rom_dataspace _config_rom { _env, "config" };
@ -743,13 +784,7 @@ class Vfs_server::Root : public Genode::Root_component<Session_component>
Session_registry _session_registry { };
Event_response_handler _response_handler { _session_registry };
Vfs::Global_file_system_factory _global_file_system_factory { _vfs_heap };
Vfs::Dir_file_system _vfs {
_env, _vfs_heap, vfs_config(), _response_handler,
_global_file_system_factory };
Vfs_env _vfs_env { _env, vfs_config(), _session_registry };
Genode::Signal_handler<Root> _config_handler {
_env.ep(), *this, &Root::_config_update };
@ -757,7 +792,7 @@ class Vfs_server::Root : public Genode::Root_component<Session_component>
void _config_update()
{
_config_rom.update();
_vfs.apply_config(vfs_config());
_vfs_env.root_dir().apply_config(vfs_config());
}
protected:
@ -835,7 +870,8 @@ class Vfs_server::Root : public Genode::Root_component<Session_component>
}
/* check if the session root exists */
if (!((session_root == "/") || _vfs.directory(session_root.base()))) {
if (!((session_root == "/")
|| _vfs_env.root_dir().directory(session_root.base()))) {
error("session root '", session_root, "' not found for '", label, "'");
throw Service_denied();
}
@ -844,7 +880,7 @@ class Vfs_server::Root : public Genode::Root_component<Session_component>
Registered_session(_session_registry, _env, label.string(),
Genode::Ram_quota{ram_quota},
Genode::Cap_quota{cap_quota},
tx_buf_size, _vfs,
tx_buf_size, _vfs_env.root_dir(),
session_root.base(), writeable);
auto ram_used = _env.pd().used_ram().value - initial_ram_usage;

View File

@ -33,8 +33,7 @@
*/
/* Genode includes */
#include <vfs/file_system_factory.h>
#include <vfs/dir_file_system.h>
#include <vfs/simple_env.h>
#include <timer_session/connection.h>
#include <base/heap.h>
#include <base/attached_rom_dataspace.h>
@ -521,19 +520,9 @@ void Component::construct(Genode::Env &env)
Attached_rom_dataspace config_rom(env, "config");
Xml_node const config_xml = config_rom.xml();
struct Io_response_handler : Vfs::Io_response_handler
{
void handle_io_response(Vfs::Vfs_handle::Context *) override
{
Genode::log(__func__, " called");
}
} io_response_handler;
Vfs::Simple_env vfs_env { env, heap, config_xml.sub_node("vfs") };
Vfs::Global_file_system_factory global_file_system_factory(heap);
Vfs::Dir_file_system vfs_root { env, heap, config_xml.sub_node("vfs"),
io_response_handler,
global_file_system_factory };
Vfs::File_system &vfs_root = vfs_env.root_dir();
Vfs::Vfs_handle *vfs_root_handle;
vfs_root.opendir("/", false, &vfs_root_handle, heap);

View File

@ -124,7 +124,7 @@ class Noux::Child : public Rpc_object<Session>,
Env &_env;
Vfs::Dir_file_system &_root_dir;
Vfs::File_system &_root_dir;
Vfs_io_waiter_registry &_vfs_io_waiter_registry;
Vfs_handle_context _vfs_handle_context;
@ -323,7 +323,7 @@ class Noux::Child : public Rpc_object<Session>,
Pid_allocator &pid_allocator,
int pid,
Env &env,
Vfs::Dir_file_system &root_dir,
Vfs::File_system &root_dir,
Vfs_io_waiter_registry &vfs_io_waiter_registry,
Args const &args,
Sysio::Env const &sysio_env,

View File

@ -51,7 +51,7 @@ class Noux::Child_env
/**
* Verify that the file exists and return its size
*/
Vfs::file_size _file_size(Vfs::Dir_file_system &root_dir,
Vfs::file_size _file_size(Vfs::File_system &root_dir,
char const *binary_name)
{
Vfs::Directory_service::Stat stat_out;
@ -88,7 +88,7 @@ class Noux::Child_env
*/
void _process_binary_name_and_args(char const *binary_name,
char const *args,
Vfs::Dir_file_system &root_dir,
Vfs::File_system &root_dir,
Vfs_io_waiter_registry &vfs_io_waiter_registry,
Ram_session &ram,
Region_map &rm,
@ -210,7 +210,7 @@ class Noux::Child_env
Child_env(char const *binary_name,
char const *args, Sysio::Env env,
Vfs::Dir_file_system &root_dir,
Vfs::File_system &root_dir,
Vfs_io_waiter_registry &vfs_io_waiter_registry,
Ram_session &ram,
Region_map &rm,

View File

@ -39,14 +39,14 @@ class Noux::Local_rom_factory : public Local_rom_service::Factory
Allocator &_alloc;
Env &_env;
Rpc_entrypoint &_ep;
Vfs::Dir_file_system &_root_dir;
Vfs::File_system &_root_dir;
Vfs_io_waiter_registry &_vfs_io_waiter_registry;
Dataspace_registry &_registry;
public:
Local_rom_factory(Allocator &alloc, Env &env, Rpc_entrypoint &ep,
Vfs::Dir_file_system &root_dir,
Vfs::File_system &root_dir,
Vfs_io_waiter_registry &vfs_io_waiter_registry,
Dataspace_registry &registry)
:

View File

@ -27,6 +27,7 @@
#include <destruct_queue.h>
#include <kill_broadcaster.h>
#include <vfs/dir_file_system.h>
#include <vfs/simple_env.h>
namespace Noux {
@ -96,7 +97,7 @@ static Noux::Io_channel &
connect_stdio(Genode::Env &env,
Genode::Constructible<Terminal::Connection> &terminal,
Genode::Xml_node config,
Vfs::Dir_file_system &root,
Vfs::File_system &root,
Noux::Vfs_handle_context &vfs_handle_context,
Noux::Vfs_io_waiter_registry &vfs_io_waiter_registry,
Noux::Terminal_io_channel::Type type,
@ -234,8 +235,33 @@ struct Noux::Main
} _io_response_handler;
Vfs::Dir_file_system _root_dir { _env, _heap, _config.xml().sub_node("fstab"),
_io_response_handler, _global_file_system_factory };
struct Vfs_env : Vfs::Env, Vfs::Watch_response_handler
{
Main &_main;
Vfs::Global_file_system_factory _fs_factory { _main._heap };
Vfs::Dir_file_system _root_dir;
Vfs_env(Main &main, Xml_node config)
: _main(main), _root_dir(*this, config, _fs_factory) { }
/**
* Vfs::Watch_response_handler interface
*/
void handle_watch_response(Vfs::Vfs_watch_handle::Context*) override { }
/**
* Vfs::Env interface
*/
Genode::Env &env() override { return _main._env; }
Allocator &alloc() override { return _main._heap; }
Vfs::File_system &root_dir() override { return _root_dir; }
Vfs::Io_response_handler &io_handler() override { return _main._io_response_handler; }
Vfs::Watch_response_handler &watch_handler() override { return *this; }
} _vfs_env { *this, _config.xml().sub_node("fstab") };
Vfs::File_system &_root_dir = _vfs_env.root_dir();
Vfs_handle_context _vfs_handle_context;

View File

@ -36,7 +36,7 @@ struct Noux::Vfs_dataspace
{
typedef Child_policy::Name Name;
Vfs::Dir_file_system &root_dir;
Vfs::File_system &root_dir;
Vfs_io_waiter_registry &vfs_io_waiter_registry;
Name const name;
@ -47,7 +47,7 @@ struct Noux::Vfs_dataspace
Dataspace_capability ds;
bool got_ds_from_vfs { true };
Vfs_dataspace(Vfs::Dir_file_system &root_dir,
Vfs_dataspace(Vfs::File_system &root_dir,
Vfs_io_waiter_registry &vfs_io_waiter_registry,
Name const &name,
Genode::Ram_session &ram, Genode::Region_map &rm,
@ -174,7 +174,7 @@ class Noux::Rom_session_component : public Rpc_object<Rom_session>
Allocator &_alloc;
Rpc_entrypoint &_ep;
Vfs::Dir_file_system &_root_dir;
Vfs::File_system &_root_dir;
Vfs_io_waiter_registry &_vfs_io_waiter_registry;
Dataspace_registry &_ds_registry;
@ -203,7 +203,7 @@ class Noux::Rom_session_component : public Rpc_object<Rom_session>
public:
Rom_session_component(Allocator &alloc, Env &env, Rpc_entrypoint &ep,
Vfs::Dir_file_system &root_dir,
Vfs::File_system &root_dir,
Vfs_io_waiter_registry &vfs_io_waiter_registry,
Dataspace_registry &ds_registry, Name const &name)
:

View File

@ -82,7 +82,7 @@ struct Noux::Vfs_io_channel : Io_channel
}
Vfs_io_channel(char const *path, char const *leaf_path,
Vfs::Dir_file_system *root_dir, Vfs::Vfs_handle *vfs_handle,
Vfs::File_system *root_dir, Vfs::Vfs_handle *vfs_handle,
Vfs_io_waiter_registry &vfs_io_waiter_registry,
Entrypoint &ep)
: