diff --git a/repos/libports/lib/mk/libc_fuse_exfat.mk b/repos/libports/lib/mk/libc_fuse_exfat.mk
index 41cab03699..b5d5a1bd4d 100644
--- a/repos/libports/lib/mk/libc_fuse_exfat.mk
+++ b/repos/libports/lib/mk/libc_fuse_exfat.mk
@@ -1,3 +1,5 @@
+REQUIRES = conversion_to_vfs_plugin
+
EXFAT_DIR := $(call select_from_ports,exfat)/src/lib/exfat
SRC_C = $(notdir $(EXFAT_DIR)/fuse/main.c)
diff --git a/repos/libports/lib/mk/libc_fuse_ext2.mk b/repos/libports/lib/mk/libc_fuse_ext2.mk
index 39eda17542..3e93f99b5f 100644
--- a/repos/libports/lib/mk/libc_fuse_ext2.mk
+++ b/repos/libports/lib/mk/libc_fuse_ext2.mk
@@ -1,3 +1,5 @@
+REQUIRES = conversion_to_vfs_plugin
+
FUSE_EXT2_PORT_DIR := $(call select_from_ports,fuse-ext2)
FUSE_EXT2_DIR := $(FUSE_EXT2_PORT_DIR)/src/lib/fuse-ext2/fuse-ext2
diff --git a/repos/libports/lib/mk/libc_fuse_ntfs-3g.mk b/repos/libports/lib/mk/libc_fuse_ntfs-3g.mk
index 67de1a5506..ed05e70de6 100644
--- a/repos/libports/lib/mk/libc_fuse_ntfs-3g.mk
+++ b/repos/libports/lib/mk/libc_fuse_ntfs-3g.mk
@@ -1,3 +1,5 @@
+REQUIRES = conversion_to_vfs_plugin
+
NTFS_3G_DIR := $(call select_from_ports,ntfs-3g)/src/lib/ntfs-3g
SRC_C = ntfs-3g.c ntfs-3g_common.c
diff --git a/repos/libports/src/lib/libc/issetugid.cc b/repos/libports/src/lib/libc/issetugid.cc
index 8de995092f..d7c2e991e0 100644
--- a/repos/libports/src/lib/libc/issetugid.cc
+++ b/repos/libports/src/lib/libc/issetugid.cc
@@ -16,6 +16,6 @@
extern "C" int issetugid(void)
{
- Genode::raw("issetugid called, not yet implemented, returning 1");
+ Genode::warning("issetugid called, not yet implemented, returning 1");
return 1;
}
diff --git a/repos/libports/src/lib/libc/rlimit.cc b/repos/libports/src/lib/libc/rlimit.cc
index 43fa5e7afc..a82be63a0c 100644
--- a/repos/libports/src/lib/libc/rlimit.cc
+++ b/repos/libports/src/lib/libc/rlimit.cc
@@ -32,7 +32,7 @@ extern "C" int __attribute__((weak)) getrlimit(int resource, struct rlimit *rlim
return 0;
}
- Genode::raw("getrlimit called, return 0");
+ Genode::warning("getrlimit called, return 0");
return 0;
}
diff --git a/repos/libports/src/lib/libc/task.cc b/repos/libports/src/lib/libc/task.cc
index 53fd5928d9..62e5860c6b 100644
--- a/repos/libports/src/lib/libc/task.cc
+++ b/repos/libports/src/lib/libc/task.cc
@@ -17,10 +17,12 @@
#include
#include
#include
+#include
/* libc-internal includes */
#include
#include
+#include "vfs_plugin.h"
/* escape sequences for highlighting debug message prefixes */
@@ -72,6 +74,11 @@ class Libc::Task : public Genode::Rpc_object
Genode::Env &_env;
+ /* XXX: this heap is only used by the Vfs_plugin */
+ Genode::Heap _heap { &_env.ram(), &_env.rm() };
+
+ Vfs_plugin _vfs { _env, _heap };
+
/**
* Application context and execution state
*/
diff --git a/repos/libports/src/lib/libc/vfs_plugin.cc b/repos/libports/src/lib/libc/vfs_plugin.cc
index 7f20ddb1f9..42224c1a1d 100644
--- a/repos/libports/src/lib/libc/vfs_plugin.cc
+++ b/repos/libports/src/lib/libc/vfs_plugin.cc
@@ -33,7 +33,7 @@
/* libc plugin interface */
#include
-#include
+#include
/* libc-internal includes */
#include
@@ -150,112 +150,6 @@ namespace Libc {
}
}
-
-namespace Libc { class Vfs_plugin; }
-
-
-class Libc::Vfs_plugin : public Libc::Plugin
-{
- private:
-
- Vfs::Dir_file_system _root_dir;
-
- Genode::Xml_node _vfs_config()
- {
- try {
- return vfs_config();
- } catch (...) {
- Genode::warning("no VFS configured");
- return Genode::Xml_node("");
- }
- }
-
- void _open_stdio(int libc_fd, char const *path, unsigned flags)
- {
- struct stat out_stat;
- if (::strlen(path) == 0 || stat(path, &out_stat) != 0)
- return;
-
- Libc::File_descriptor *fd = open(path, flags, libc_fd);
- if (fd->libc_fd != libc_fd) {
- Genode::error("could not allocate fd ", libc_fd, " "
- "for ", path, ", got fd ", fd->libc_fd);
- close(fd);
- return;
- }
-
- /*
- * We need to manually register the path. Normally this is done
- * by '_open'. But we call the local 'open' function directly
- * because we want to explicitly specify the libc fd ID.
- *
- * We have to allocate the path from the libc (done via 'strdup')
- * such that the path can be freed when an stdio fd is closed.
- */
- fd->fd_path = strdup(path);
- }
-
- public:
-
- /**
- * Constructor
- */
- Vfs_plugin() : _root_dir(_vfs_config(), Vfs::global_file_system_factory())
- {
- if (_root_dir.num_dirent("/")) {
- chdir(initial_cwd());
-
- _open_stdio(0, config_stdin(), O_RDONLY);
- _open_stdio(1, config_stdout(), O_WRONLY);
- _open_stdio(2, config_stderr(), O_WRONLY);
- }
- }
-
- ~Vfs_plugin() { }
-
- bool supports_access(const char *, int) override { return true; }
- bool supports_mkdir(const char *, mode_t) override { return true; }
- bool supports_open(const char *, int) override { return true; }
- bool supports_readlink(const char *, char *, ::size_t) override { return true; }
- bool supports_rename(const char *, const char *) override { return true; }
- bool supports_rmdir(const char *) override { return true; }
- bool supports_stat(const char *) override { return true; }
- bool supports_symlink(const char *, const char *) override { return true; }
- bool supports_unlink(const char *) override { return true; }
- bool supports_mmap() override { return true; }
-
- Libc::File_descriptor *open(const char *, int, int libc_fd);
-
- Libc::File_descriptor *open(const char *path, int flags) override
- {
- return open(path, flags, Libc::ANY_FD);
- }
-
- int access(char const *, int) override;
- int close(Libc::File_descriptor *) override;
- int dup2(Libc::File_descriptor *, Libc::File_descriptor *) override;
- int fcntl(Libc::File_descriptor *, int, long) override;
- int fstat(Libc::File_descriptor *, struct stat *) override;
- int fstatfs(Libc::File_descriptor *, struct statfs *) override;
- int fsync(Libc::File_descriptor *fd) override;
- int ftruncate(Libc::File_descriptor *, ::off_t) override;
- ssize_t getdirentries(Libc::File_descriptor *, char *, ::size_t , ::off_t *) override;
- int ioctl(Libc::File_descriptor *, int , char *) override;
- ::off_t lseek(Libc::File_descriptor *fd, ::off_t offset, int whence) override;
- int mkdir(const char *, mode_t) override;
- ssize_t read(Libc::File_descriptor *, void *, ::size_t) override;
- ssize_t readlink(const char *, char *, ::size_t) override;
- int rename(const char *, const char *) override;
- int rmdir(const char *) override;
- int stat(const char *, struct stat *) override;
- int symlink(const char *, const char *) override;
- int unlink(const char *) override;
- ssize_t write(Libc::File_descriptor *, const void *, ::size_t ) override;
- void *mmap(void *, ::size_t, int, int, Libc::File_descriptor *, ::off_t) override;
- int munmap(void *, ::size_t) override;
-};
-
-
int Libc::Vfs_plugin::access(const char *path, int amode)
{
if (_root_dir.leaf_path(path))
@@ -275,7 +169,7 @@ Libc::File_descriptor *Libc::Vfs_plugin::open(char const *path, int flags,
while (handle == 0) {
- switch (_root_dir.open(path, flags, &handle)) {
+ switch (_root_dir.open(path, flags, &handle, _alloc)) {
case Result::OPEN_OK:
break;
@@ -288,7 +182,7 @@ Libc::File_descriptor *Libc::Vfs_plugin::open(char const *path, int flags,
}
/* O_CREAT is set, so try to create the file */
- switch (_root_dir.open(path, flags | O_EXCL, &handle)) {
+ switch (_root_dir.open(path, flags | O_EXCL, &handle, _alloc)) {
case Result::OPEN_OK:
break;
@@ -857,9 +751,3 @@ int Libc::Vfs_plugin::munmap(void *addr, ::size_t)
Libc::mem_alloc()->free(addr);
return 0;
}
-
-
-void __attribute__((constructor)) init_libc_vfs(void)
-{
- static Libc::Vfs_plugin plugin;
-}
diff --git a/repos/libports/src/lib/libc/vfs_plugin.h b/repos/libports/src/lib/libc/vfs_plugin.h
new file mode 100644
index 0000000000..67aed05c17
--- /dev/null
+++ b/repos/libports/src/lib/libc/vfs_plugin.h
@@ -0,0 +1,154 @@
+/*
+ * \brief Libc plugin for using a process-local virtual file system
+ * \author Norman Feske
+ * \date 2014-04-09
+ */
+
+/*
+ * Copyright (C) 2014-2016 Genode Labs GmbH
+ *
+ * This file is part of the Genode OS framework, which is distributed
+ * under the terms of the GNU General Public License version 2.
+ */
+
+#ifndef _LIBC_VFS__PLUGIN_H_
+#define _LIBC_VFS__PLUGIN_H_
+
+/* Genode includes */
+#include
+#include
+#include
+#include
+
+/* libc includes */
+#include
+#include
+
+/* libc plugin interface */
+#include
+#include
+
+namespace Libc {
+
+ Genode::Xml_node config();
+ Genode::Xml_node vfs_config();
+
+ char const *initial_cwd();
+ char const *config_stdin();
+ char const *config_stdout();
+ char const *config_stderr();
+
+}
+
+
+namespace Libc { class Vfs_plugin; }
+
+
+class Libc::Vfs_plugin : public Libc::Plugin
+{
+ private:
+
+ Genode::Allocator &_alloc;
+
+ Vfs::Dir_file_system _root_dir;
+
+ Genode::Xml_node _vfs_config()
+ {
+ try {
+ return vfs_config();
+ } catch (...) {
+ PINF("no VFS configured");
+ return Genode::Xml_node("");
+ }
+ }
+
+ void _open_stdio(int libc_fd, char const *path, unsigned flags)
+ {
+ struct stat out_stat;
+ if (::strlen(path) == 0 || stat(path, &out_stat) != 0)
+ return;
+
+ Libc::File_descriptor *fd = open(path, flags, libc_fd);
+ if (fd->libc_fd != libc_fd) {
+ PERR("could not allocate fd %d for %s, got fd %d",
+ libc_fd, path, fd->libc_fd);
+ close(fd);
+ return;
+ }
+
+ /*
+ * We need to manually register the path. Normally this is done
+ * by '_open'. But we call the local 'open' function directly
+ * because we want to explicitly specify the libc fd ID.
+ *
+ * We have to allocate the path from the libc (done via 'strdup')
+ * such that the path can be freed when an stdio fd is closed.
+ */
+ fd->fd_path = strdup(path);
+ }
+
+ public:
+
+ /**
+ * Constructor
+ */
+ Vfs_plugin(Genode::Env &env, Genode::Allocator &alloc)
+ :
+ _alloc(alloc),
+ _root_dir(env, _alloc, _vfs_config(),
+ Vfs::global_file_system_factory())
+ {
+ if (_root_dir.num_dirent("/")) {
+ chdir(initial_cwd());
+
+ _open_stdio(0, config_stdin(), O_RDONLY);
+ _open_stdio(1, config_stdout(), O_WRONLY);
+ _open_stdio(2, config_stderr(), O_WRONLY);
+ }
+ }
+
+ ~Vfs_plugin() { }
+
+ bool supports_access(const char *, int) override { return true; }
+ bool supports_mkdir(const char *, mode_t) override { return true; }
+ bool supports_open(const char *, int) override { return true; }
+ bool supports_readlink(const char *, char *, ::size_t) override { return true; }
+ bool supports_rename(const char *, const char *) override { return true; }
+ bool supports_rmdir(const char *) override { return true; }
+ bool supports_stat(const char *) override { return true; }
+ bool supports_symlink(const char *, const char *) override { return true; }
+ bool supports_unlink(const char *) override { return true; }
+ bool supports_mmap() override { return true; }
+
+ Libc::File_descriptor *open(const char *, int, int libc_fd);
+
+ Libc::File_descriptor *open(const char *path, int flags) override
+ {
+ return open(path, flags, Libc::ANY_FD);
+ }
+
+ int access(char const *, int) override;
+ int close(Libc::File_descriptor *) override;
+ int dup2(Libc::File_descriptor *, Libc::File_descriptor *) override;
+ int fcntl(Libc::File_descriptor *, int, long) override;
+ int fstat(Libc::File_descriptor *, struct stat *) override;
+ int fstatfs(Libc::File_descriptor *, struct statfs *) override;
+ int fsync(Libc::File_descriptor *fd) override;
+ int ftruncate(Libc::File_descriptor *, ::off_t) override;
+ ssize_t getdirentries(Libc::File_descriptor *, char *, ::size_t , ::off_t *) override;
+ int ioctl(Libc::File_descriptor *, int , char *) override;
+ ::off_t lseek(Libc::File_descriptor *fd, ::off_t offset, int whence) override;
+ int mkdir(const char *, mode_t) override;
+ ssize_t read(Libc::File_descriptor *, void *, ::size_t) override;
+ ssize_t readlink(const char *, char *, ::size_t) override;
+ int rename(const char *, const char *) override;
+ int rmdir(const char *) override;
+ int stat(const char *, struct stat *) override;
+ int symlink(const char *, const char *) override;
+ int unlink(const char *) override;
+ ssize_t write(Libc::File_descriptor *, const void *, ::size_t ) override;
+ void *mmap(void *, ::size_t, int, int, Libc::File_descriptor *, ::off_t) override;
+ int munmap(void *, ::size_t) override;
+};
+
+#endif
diff --git a/repos/libports/src/lib/vfs/jitterentropy/vfs.cc b/repos/libports/src/lib/vfs/jitterentropy/vfs.cc
index 31a9cd7357..4abf4bbf5a 100644
--- a/repos/libports/src/lib/vfs/jitterentropy/vfs.cc
+++ b/repos/libports/src/lib/vfs/jitterentropy/vfs.cc
@@ -20,9 +20,10 @@
struct Jitterentropy_factory : Vfs::File_system_factory
{
- Vfs::File_system *create(Genode::Xml_node node) override
+ Vfs::File_system *create(Genode::Env&, Genode::Allocator &alloc,
+ Genode::Xml_node node) override
{
- return new (Genode::env()->heap()) Jitterentropy_file_system(node);
+ return new (alloc) Jitterentropy_file_system(node);
}
};
diff --git a/repos/os/include/vfs/dir_file_system.h b/repos/os/include/vfs/dir_file_system.h
index 12796c2742..988a24a37e 100644
--- a/repos/os/include/vfs/dir_file_system.h
+++ b/repos/os/include/vfs/dir_file_system.h
@@ -206,7 +206,10 @@ class Vfs::Dir_file_system : public File_system
public:
- Dir_file_system(Xml_node node, File_system_factory &fs_factory)
+ Dir_file_system(Genode::Env &env,
+ Genode::Allocator &alloc,
+ Genode::Xml_node node,
+ File_system_factory &fs_factory)
:
_first_file_system(0)
{
@@ -224,12 +227,12 @@ class Vfs::Dir_file_system : public File_system
/* traverse into nodes */
if (sub_node.has_type("dir")) {
- _append_file_system(new (env()->heap())
- Dir_file_system(sub_node, fs_factory));
+ _append_file_system(new (alloc)
+ Dir_file_system(env, alloc, sub_node, fs_factory));
continue;
}
- File_system *fs = fs_factory.create(sub_node);
+ File_system *fs = fs_factory.create(env, alloc, sub_node);
if (fs) {
_append_file_system(fs);
continue;
@@ -420,7 +423,7 @@ class Vfs::Dir_file_system : public File_system
Open_result open(char const *path,
unsigned mode,
Vfs_handle **out_handle,
- Allocator &alloc = *Genode::env()->heap()) override
+ Allocator &alloc) override
{
/*
* If 'path' is a directory, we create a 'Vfs_handle'
diff --git a/repos/os/include/vfs/directory_service.h b/repos/os/include/vfs/directory_service.h
index 252f3e3083..82aea8b00c 100644
--- a/repos/os/include/vfs/directory_service.h
+++ b/repos/os/include/vfs/directory_service.h
@@ -61,7 +61,7 @@ struct Vfs::Directory_service
virtual Open_result open(char const *path,
unsigned mode,
Vfs_handle **handle,
- Allocator &alloc = *Genode::env()->heap()) = 0;
+ Allocator &alloc) = 0;
/**
* Close handle resources and deallocate handle
diff --git a/repos/os/include/vfs/file_system_factory.h b/repos/os/include/vfs/file_system_factory.h
index 60fa640ac5..d0360e14ff 100644
--- a/repos/os/include/vfs/file_system_factory.h
+++ b/repos/os/include/vfs/file_system_factory.h
@@ -5,7 +5,7 @@
*/
/*
- * Copyright (C) 2014 Genode Labs GmbH
+ * Copyright (C) 2014-2016 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2.
@@ -30,7 +30,16 @@ namespace Vfs {
struct Vfs::File_system_factory
{
- virtual File_system *create(Xml_node node) = 0;
+ /**
+ * Create and return a new file-system
+ *
+ * \param env Env for service connections
+ * \param alloc internal file-system allocator
+ * \param config file-system configuration
+ */
+ virtual File_system *create(Genode::Env &env,
+ Genode::Allocator &alloc,
+ Xml_node config) = 0;
};
diff --git a/repos/os/src/app/cli_monitor/main.cc b/repos/os/src/app/cli_monitor/main.cc
index f971030782..d7df1cfc7d 100644
--- a/repos/os/src/app/cli_monitor/main.cc
+++ b/repos/os/src/app/cli_monitor/main.cc
@@ -16,6 +16,7 @@
#include
#include
#include
+#include
/* public CLI-monitor includes */
#include
@@ -71,31 +72,17 @@ static size_t ram_preservation_from_config()
}
-/**
- * Return singleton instance of the subsystem config registry
- */
-static Subsystem_config_registry &subsystem_config_registry()
+static Genode::Xml_node vfs_config()
{
- try {
-
- /* initialize virtual file system */
- static Vfs::Dir_file_system
- root_dir(Genode::config()->xml_node().sub_node("vfs"),
- Vfs::global_file_system_factory());
-
- static Subsystem_config_registry inst(root_dir);
-
- return inst;
-
- } catch (Genode::Xml_node::Nonexistent_sub_node) {
-
+ try { return Genode::config()->xml_node().sub_node("vfs"); }
+ catch (Genode::Xml_node::Nonexistent_sub_node) {
Genode::error("missing '' configuration");
throw;
}
}
-int main(int argc, char **argv)
+void Component::construct(Genode::Env &env)
{
/* look for dynamic linker */
Genode::Dataspace_capability ldso_ds;
@@ -109,7 +96,7 @@ int main(int argc, char **argv)
using Genode::Signal_receiver;
static Genode::Cap_connection cap;
- static Terminal::Connection terminal;
+ static Terminal::Connection terminal(env);
static Command_registry commands;
static Child_registry children;
@@ -135,12 +122,18 @@ int main(int argc, char **argv)
sig_rec.manage(&yield_broadcast_sig_ctx),
sig_rec.manage(&resource_avail_sig_ctx));
+ /* initialize virtual file system */
+ static Vfs::Dir_file_system root_dir(env, *Genode::env()->heap(), vfs_config(),
+ Vfs::global_file_system_factory());
+
+ static Subsystem_config_registry subsystem_config_registry(root_dir);
+
/* initialize generic commands */
commands.insert(new Help_command);
Kill_command kill_command(children);
commands.insert(&kill_command);
commands.insert(new Start_command(ram, cap, children,
- subsystem_config_registry(),
+ subsystem_config_registry,
yield_response_sig_cap,
exited_child_sig_cap,
ldso_ds));
@@ -240,5 +233,5 @@ int main(int argc, char **argv)
line_editor.reset();
}
- return 0;
+ env.parent().exit(0);
}
diff --git a/repos/os/src/app/cli_monitor/subsystem_config_registry.h b/repos/os/src/app/cli_monitor/subsystem_config_registry.h
index e250eb038c..9f00e84e4f 100644
--- a/repos/os/src/app/cli_monitor/subsystem_config_registry.h
+++ b/repos/os/src/app/cli_monitor/subsystem_config_registry.h
@@ -89,7 +89,7 @@ class Subsystem_config_registry
Vfs::Directory_service::Open_result const open_result =
_fs.open(path.base(),
Vfs::Directory_service::OPEN_MODE_RDONLY,
- &handle);
+ &handle, *Genode::env()->heap());
Vfs::Vfs_handle::Guard handle_guard(handle);
diff --git a/repos/os/src/lib/vfs/block_file_system.h b/repos/os/src/lib/vfs/block_file_system.h
index 339ca4e606..3bd73cb0a4 100644
--- a/repos/os/src/lib/vfs/block_file_system.h
+++ b/repos/os/src/lib/vfs/block_file_system.h
@@ -6,7 +6,7 @@
*/
/*
- * Copyright (C) 2013-2014 Genode Labs GmbH
+ * Copyright (C) 2013-2016 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2.
@@ -26,18 +26,10 @@ class Vfs::Block_file_system : public Single_file_system
{
private:
- struct Label
- {
- enum { LABEL_MAX_LEN = 64 };
- char string[LABEL_MAX_LEN];
+ Genode::Allocator &_alloc;
- Label(Xml_node config)
- {
- string[0] = 0;
- try { config.attribute("label").value(string, sizeof(string)); }
- catch (...) { }
- }
- } _label;
+ typedef Genode::String<64> Label;
+ Label _label;
/*
* Serialize access to packet stream of the block session
@@ -47,7 +39,7 @@ class Vfs::Block_file_system : public Single_file_system
char *_block_buffer;
unsigned _block_buffer_count;
- Genode::Allocator_avl _tx_block_alloc;
+ Genode::Allocator_avl _tx_block_alloc { &_alloc };
Block::Connection _block;
Genode::size_t _block_size;
Block::sector_t _block_count;
@@ -98,14 +90,16 @@ class Vfs::Block_file_system : public Single_file_system
public:
- Block_file_system(Xml_node config)
+ Block_file_system(Genode::Env &env,
+ Genode::Allocator &alloc,
+ Genode::Xml_node config)
:
Single_file_system(NODE_TYPE_BLOCK_DEVICE, name(), config),
- _label(config),
+ _alloc(alloc),
+ _label(config.attribute_value("label", Label())),
_block_buffer(0),
_block_buffer_count(1),
- _tx_block_alloc(env()->heap()),
- _block(&_tx_block_alloc, 128*1024, _label.string),
+ _block(env, &_tx_block_alloc, 128*1024, _label.string()),
_tx_source(_block.tx()),
_readable(false),
_writeable(false)
@@ -118,12 +112,12 @@ 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 (env()->heap()) char[_block_buffer_count * _block_size];
+ _block_buffer = new (_alloc) char[_block_buffer_count * _block_size];
}
~Block_file_system()
{
- destroy(env()->heap(), _block_buffer);
+ destroy(_alloc, _block_buffer);
}
static char const *name() { return "block"; }
diff --git a/repos/os/src/lib/vfs/file_system_factory.cc b/repos/os/src/lib/vfs/file_system_factory.cc
index 42319a8274..0d09376c6d 100644
--- a/repos/os/src/lib/vfs/file_system_factory.cc
+++ b/repos/os/src/lib/vfs/file_system_factory.cc
@@ -55,9 +55,11 @@ class Default_file_system_factory : public Vfs::Global_file_system_factory
{
Builtin_entry() : Entry_base(FILE_SYSTEM::name()) { }
- Vfs::File_system *create(Genode::Xml_node node) override
+ Vfs::File_system *create(Genode::Env &env,
+ Genode::Allocator &alloc,
+ Genode::Xml_node node) override
{
- return new (Genode::env()->heap()) FILE_SYSTEM(node);
+ return new (alloc) FILE_SYSTEM(env, alloc, node);
}
};
@@ -70,8 +72,10 @@ class Default_file_system_factory : public Vfs::Global_file_system_factory
:
Entry_base(name), _fs_factory(fs_factory) { }
- Vfs::File_system *create(Genode::Xml_node node) override {
- return _fs_factory.create(node); }
+ Vfs::File_system *create(Genode::Env &env,
+ Genode::Allocator &alloc,
+ Genode::Xml_node node) override {
+ return _fs_factory.create(env, alloc, node); }
};
Genode::List _list;
@@ -82,11 +86,13 @@ class Default_file_system_factory : public Vfs::Global_file_system_factory
_list.insert(new (Genode::env()->heap()) Builtin_entry());
}
- Vfs::File_system *_try_create(Genode::Xml_node node)
+ Vfs::File_system *_try_create(Genode::Env &env,
+ Genode::Allocator &alloc,
+ Genode::Xml_node node)
{
for (Entry_base *e = _list.first(); e; e = e->next())
if (e->matches(node))
- return e->create(node);
+ return e->create(env, alloc, node);
return 0;
}
@@ -126,12 +132,13 @@ class Default_file_system_factory : public Vfs::Global_file_system_factory
/**
* \throw Factory_not_available
*/
- Vfs::File_system_factory &_load_factory(Library_name const &lib_name)
+ Vfs::File_system_factory &_load_factory(Genode::Allocator &alloc,
+ Library_name const &lib_name)
{
Genode::Shared_object *shared_object = nullptr;
try {
- shared_object = new (Genode::env()->heap())
+ shared_object = new (alloc)
Genode::Shared_object(lib_name.string());
typedef Vfs::File_system_factory *(*Query_fn)();
@@ -148,18 +155,18 @@ class Default_file_system_factory : public Vfs::Global_file_system_factory
PWRN("could not find symbol '%s' in '%s'",
_factory_symbol(), lib_name.string());
- Genode::destroy(Genode::env()->heap(), shared_object);
+ Genode::destroy(alloc, shared_object);
throw Factory_not_available();
}
}
- bool _probe_external_factory(Genode::Xml_node node)
+ bool _probe_external_factory(Genode::Allocator &alloc, Genode::Xml_node node)
{
Library_name const lib_name = _library_name(_node_name(node));
try {
- _list.insert(new (Genode::env()->heap())
- External_entry(_node_name(node).string(), _load_factory(lib_name)));
+ _list.insert(new (alloc)
+ External_entry(_node_name(node).string(), _load_factory(alloc, lib_name)));
return true;
} catch (Factory_not_available) { return false; }
@@ -167,20 +174,22 @@ class Default_file_system_factory : public Vfs::Global_file_system_factory
public:
- Vfs::File_system *create(Genode::Xml_node node) override
+ Vfs::File_system *create(Genode::Env &env,
+ Genode::Allocator &alloc,
+ Genode::Xml_node node) override
{
try {
/* try if type is handled by the currently registered fs types */
- if (Vfs::File_system *fs = _try_create(node))
+ if (Vfs::File_system *fs = _try_create(env, alloc, node))
return fs;
/* if the builtin fails, do not try loading an external */
} catch (...) { return 0; }
try {
/* probe for file system implementation available as shared lib */
- if (_probe_external_factory(node)) {
+ if (_probe_external_factory(alloc, node)) {
/* try again with the new file system type loaded */
- if (Vfs::File_system *fs = _try_create(node))
+ if (Vfs::File_system *fs = _try_create(env, alloc, node))
return fs;
}
} catch (...) { }
diff --git a/repos/os/src/lib/vfs/fs_file_system.h b/repos/os/src/lib/vfs/fs_file_system.h
index 938c641fdb..5964f71781 100644
--- a/repos/os/src/lib/vfs/fs_file_system.h
+++ b/repos/os/src/lib/vfs/fs_file_system.h
@@ -25,6 +25,7 @@ class Vfs::Fs_file_system : public File_system
{
private:
+
/*
* Lock used to serialize the interaction with the packet stream of the
* file-system session.
@@ -34,7 +35,8 @@ class Vfs::Fs_file_system : public File_system
*/
Lock _lock;
- Genode::Allocator_avl _fs_packet_alloc;
+ Genode::Env &_env;
+ Genode::Allocator_avl _fs_packet_alloc;
typedef Genode::String<64> Label_string;
Label_string _label;
@@ -149,9 +151,12 @@ class Vfs::Fs_file_system : public File_system
public:
- Fs_file_system(Xml_node config)
+ Fs_file_system(Genode::Env &env,
+ Genode::Allocator &alloc,
+ Genode::Xml_node config)
:
- _fs_packet_alloc(env()->heap()),
+ _env(env),
+ _fs_packet_alloc(&alloc),
_label(config.attribute_value("label", Label_string())),
_root( config.attribute_value("root", Root_string())),
_fs(_fs_packet_alloc,
@@ -191,9 +196,9 @@ class Vfs::Fs_file_system : public File_system
::File_system::Status status = _fs.status(file);
Ram_dataspace_capability ds_cap =
- env()->ram_session()->alloc(status.size);
+ _env.ram().alloc(status.size);
- local_addr = env()->rm_session()->attach(ds_cap);
+ local_addr = _env.rm().attach(ds_cap);
::File_system::Session::Tx::Source &source = *_fs.tx();
file_size const max_packet_size = source.bulk_buffer_size() / 2;
@@ -225,12 +230,12 @@ class Vfs::Fs_file_system : public File_system
source.release_packet(packet);
}
- env()->rm_session()->detach(local_addr);
+ _env.rm().detach(local_addr);
return ds_cap;
} catch(...) {
- env()->rm_session()->detach(local_addr);
- env()->ram_session()->free(ds_cap);
+ _env.rm().detach(local_addr);
+ _env.ram().free(ds_cap);
return Dataspace_capability();
}
}
@@ -238,7 +243,7 @@ class Vfs::Fs_file_system : public File_system
void release(char const *path, Dataspace_capability ds_cap) override
{
if (ds_cap.valid())
- env()->ram_session()->free(static_cap_cast(ds_cap));
+ _env.ram().free(static_cap_cast(ds_cap));
}
Stat_result stat(char const *path, Stat &out) override
diff --git a/repos/os/src/lib/vfs/inline_file_system.h b/repos/os/src/lib/vfs/inline_file_system.h
index 074fc83f8c..0480090821 100644
--- a/repos/os/src/lib/vfs/inline_file_system.h
+++ b/repos/os/src/lib/vfs/inline_file_system.h
@@ -8,7 +8,7 @@
*/
/*
- * Copyright (C) 2014 Genode Labs GmbH
+ * Copyright (C) 2014-2016 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2.
@@ -31,7 +31,9 @@ class Vfs::Inline_file_system : public Single_file_system
public:
- Inline_file_system(Xml_node config)
+ Inline_file_system(Genode::Env&,
+ Genode::Allocator&,
+ Genode::Xml_node config)
:
Single_file_system(NODE_TYPE_FILE, name(), config),
_base(config.content_base()),
@@ -42,7 +44,7 @@ class Vfs::Inline_file_system : public Single_file_system
/********************************
- ** File I/O service interface **
+ ** Directory service interface **
********************************/
Stat_result stat(char const *path, Stat &out) override
diff --git a/repos/os/src/lib/vfs/log_file_system.h b/repos/os/src/lib/vfs/log_file_system.h
index 656c389137..7c1aeaedca 100644
--- a/repos/os/src/lib/vfs/log_file_system.h
+++ b/repos/os/src/lib/vfs/log_file_system.h
@@ -5,7 +5,7 @@
*/
/*
- * Copyright (C) 2014 Genode Labs GmbH
+ * Copyright (C) 2014-2016 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2.
@@ -28,7 +28,9 @@ class Vfs::Log_file_system : public Single_file_system
public:
- Log_file_system(Xml_node config)
+ Log_file_system(Genode::Env&,
+ Genode::Allocator&,
+ Genode::Xml_node config)
:
Single_file_system(NODE_TYPE_CHAR_DEVICE, name(), config)
{ }
diff --git a/repos/os/src/lib/vfs/null_file_system.h b/repos/os/src/lib/vfs/null_file_system.h
index 3c7957aaca..1a732c250d 100644
--- a/repos/os/src/lib/vfs/null_file_system.h
+++ b/repos/os/src/lib/vfs/null_file_system.h
@@ -6,7 +6,7 @@
*/
/*
- * Copyright (C) 2012-2014 Genode Labs GmbH
+ * Copyright (C) 2012-2016 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2.
@@ -22,7 +22,9 @@ namespace Vfs { class Null_file_system; }
struct Vfs::Null_file_system : Single_file_system
{
- Null_file_system(Xml_node config)
+ Null_file_system(Genode::Env&,
+ Genode::Allocator&,
+ Genode::Xml_node config)
:
Single_file_system(NODE_TYPE_CHAR_DEVICE, name(), config)
{ }
diff --git a/repos/os/src/lib/vfs/ram_file_system.h b/repos/os/src/lib/vfs/ram_file_system.h
index 366792a217..b50ccd44b1 100644
--- a/repos/os/src/lib/vfs/ram_file_system.h
+++ b/repos/os/src/lib/vfs/ram_file_system.h
@@ -356,6 +356,7 @@ class Vfs::Ram_file_system : public Vfs::File_system
}
};
+ Genode::Env &_env;
Genode::Allocator &_alloc;
Vfs_ram::Directory _root = { "" };
@@ -419,8 +420,10 @@ class Vfs::Ram_file_system : public Vfs::File_system
public:
- Ram_file_system(Xml_node config)
- : _alloc(*env()->heap()) { }
+ Ram_file_system(Genode::Env &env,
+ Genode::Allocator &alloc,
+ Genode::Xml_node)
+ : _env(env), _alloc(alloc) { }
~Ram_file_system() { _root.empty(_alloc); }
@@ -705,22 +708,22 @@ class Vfs::Ram_file_system : public Vfs::File_system
char *local_addr = nullptr;
try {
- ds_cap = env()->ram_session()->alloc(len);
+ ds_cap = _env.ram().alloc(len);
- local_addr = env()->rm_session()->attach(ds_cap);
+ local_addr = _env.rm().attach(ds_cap);
file->read(local_addr, file->length(), 0);
- env()->rm_session()->detach(local_addr);
+ _env.rm().detach(local_addr);
} catch(...) {
- env()->rm_session()->detach(local_addr);
- env()->ram_session()->free(ds_cap);
+ _env.rm().detach(local_addr);
+ _env.ram().free(ds_cap);
return Dataspace_capability();
}
return ds_cap;
}
void release(char const *path, Dataspace_capability ds_cap) override {
- env()->ram_session()->free(
+ _env.ram().free(
static_cap_cast(ds_cap)); }
diff --git a/repos/os/src/lib/vfs/rom_file_system.h b/repos/os/src/lib/vfs/rom_file_system.h
index 0af32548be..c503a4db2e 100644
--- a/repos/os/src/lib/vfs/rom_file_system.h
+++ b/repos/os/src/lib/vfs/rom_file_system.h
@@ -14,7 +14,7 @@
#ifndef _INCLUDE__VFS__ROM_FILE_SYSTEM_H_
#define _INCLUDE__VFS__ROM_FILE_SYSTEM_H_
-#include
+#include
#include
namespace Vfs { class Rom_file_system; }
@@ -48,11 +48,13 @@ class Vfs::Rom_file_system : public Single_file_system
public:
- Rom_file_system(Xml_node config)
+ Rom_file_system(Genode::Env &env,
+ Genode::Allocator&,
+ Genode::Xml_node config)
:
Single_file_system(NODE_TYPE_FILE, name(), config),
_label(config),
- _rom(_label.string)
+ _rom(env, _label.string)
{ }
static char const *name() { return "rom"; }
diff --git a/repos/os/src/lib/vfs/rtc_file_system.h b/repos/os/src/lib/vfs/rtc_file_system.h
index 777f867cfe..e56f889959 100644
--- a/repos/os/src/lib/vfs/rtc_file_system.h
+++ b/repos/os/src/lib/vfs/rtc_file_system.h
@@ -5,7 +5,7 @@
*/
/*
- * Copyright (C) 2014 Genode Labs GmbH
+ * Copyright (C) 2014-2016 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2.
@@ -30,9 +30,12 @@ class Vfs::Rtc_file_system : public Single_file_system
public:
- Rtc_file_system(Xml_node config)
+ Rtc_file_system(Genode::Env &env,
+ Genode::Allocator&,
+ Genode::Xml_node config)
:
- Single_file_system(NODE_TYPE_CHAR_DEVICE, name(), config)
+ Single_file_system(NODE_TYPE_CHAR_DEVICE, name(), config),
+ _rtc(env)
{ }
static char const *name() { return "rtc"; }
diff --git a/repos/os/src/lib/vfs/symlink_file_system.h b/repos/os/src/lib/vfs/symlink_file_system.h
index e8409f6483..47843a506e 100644
--- a/repos/os/src/lib/vfs/symlink_file_system.h
+++ b/repos/os/src/lib/vfs/symlink_file_system.h
@@ -42,13 +42,14 @@ class Vfs::Symlink_file_system : public File_system
public:
- Symlink_file_system(Xml_node config)
+ Symlink_file_system(Genode::Env&,
+ Genode::Allocator&,
+ Genode::Xml_node config)
{
try {
config.attribute("name").value(_filename, sizeof(_filename));
config.attribute("target").value(_target, sizeof(_target));
} catch (...) { }
-
}
static char const *name() { return "symlink"; }
diff --git a/repos/os/src/lib/vfs/tar_file_system.h b/repos/os/src/lib/vfs/tar_file_system.h
index 271b6fc7b4..8ba62e1719 100644
--- a/repos/os/src/lib/vfs/tar_file_system.h
+++ b/repos/os/src/lib/vfs/tar_file_system.h
@@ -17,27 +17,22 @@
#include
#include
#include
+#include
namespace Vfs { class Tar_file_system; }
class Vfs::Tar_file_system : public File_system
{
- struct Rom_name
- {
- enum { ROM_NAME_MAX_LEN = 64 };
- char name[ROM_NAME_MAX_LEN];
+ Genode::Env &_env;
+ Genode::Allocator &_alloc;
- Rom_name(Xml_node config) {
- config.attribute("name").value(name, sizeof(name));
- }
- } _rom_name;
+ typedef Genode::String<64> Rom_name;
+ Rom_name _rom_name;
- Genode::Rom_connection _rom;
-
- Genode::Dataspace_capability _tar_ds;
- char *_tar_base;
- file_size _tar_size;
+ Genode::Attached_rom_dataspace _tar_ds { _env, _rom_name.string() };
+ char *_tar_base = _tar_ds.local_addr();
+ file_size const _tar_size = _tar_ds.size();
class Record
{
@@ -192,11 +187,15 @@ class Vfs::Tar_file_system : public File_system
{
private:
+ Genode::Allocator &_alloc;
+
Node &_root_node;
public:
- Add_node_action(Node &root_node) : _root_node(root_node) { }
+ Add_node_action(Genode::Allocator &alloc,
+ Node &root_node)
+ : _alloc(alloc), _root_node(root_node) { }
void operator()(Record const *record)
{
@@ -242,16 +241,16 @@ class Vfs::Tar_file_system : public File_system
* pointer to save some memory
*/
Genode::size_t name_size = strlen(path_element) + 1;
- char *name = (char*)env()->heap()->alloc(name_size);
+ char *name = (char*)_alloc.alloc(name_size);
strncpy(name, path_element, name_size);
- child_node = new (env()->heap()) Node(name, record);
+ child_node = new (_alloc) Node(name, record);
} else {
/* create a directory node without record */
Genode::size_t name_size = strlen(path_element) + 1;
- char *name = (char*)env()->heap()->alloc(name_size);
+ char *name = (char*)_alloc.alloc(name_size);
strncpy(name, path_element, name_size);
- child_node = new (env()->heap()) Node(name, 0);
+ child_node = new (_alloc) Node(name, 0);
}
parent_node->insert(child_node);
}
@@ -343,19 +342,19 @@ class Vfs::Tar_file_system : public File_system
public:
- Tar_file_system(Xml_node config)
+ Tar_file_system(Genode::Env &env,
+ Genode::Allocator &alloc,
+ Genode::Xml_node config)
:
- _rom_name(config), _rom(_rom_name.name),
- _tar_ds(_rom.dataspace()),
- _tar_base(env()->rm_session()->attach(_tar_ds)),
- _tar_size(Dataspace_client(_tar_ds).size()),
+ _env(env), _alloc(alloc),
+ _rom_name(config.attribute_value("name", Rom_name())),
_root_node("", 0),
_cached_num_dirent(_root_node)
{
- Genode::log("tar archive '", Genode::Cstring(_rom_name.name), "' "
+ Genode::log("tar archive '", _rom_name, "' "
"local at ", (void *)_tar_base, ", size is ", _tar_size);
- _for_each_tar_record_do(Add_node_action(_root_node));
+ _for_each_tar_record_do(Add_node_action(_alloc, _root_node));
}
@@ -378,11 +377,11 @@ class Vfs::Tar_file_system : public File_system
try {
Ram_dataspace_capability ds_cap =
- env()->ram_session()->alloc(record->size());
+ _env.ram().alloc(record->size());
- void *local_addr = env()->rm_session()->attach(ds_cap);
+ void *local_addr = _env.rm().attach(ds_cap);
memcpy(local_addr, record->data(), record->size());
- env()->rm_session()->detach(local_addr);
+ _env.rm().detach(local_addr);
return ds_cap;
}
@@ -393,7 +392,7 @@ class Vfs::Tar_file_system : public File_system
void release(char const *, Dataspace_capability ds_cap) override
{
- env()->ram_session()->free(static_cap_cast(ds_cap));
+ _env.ram().free(static_cap_cast(ds_cap));
}
Stat_result stat(char const *path, Stat &out) override
diff --git a/repos/os/src/lib/vfs/terminal_file_system.h b/repos/os/src/lib/vfs/terminal_file_system.h
index 7a511b25a3..d15c2bc8a1 100644
--- a/repos/os/src/lib/vfs/terminal_file_system.h
+++ b/repos/os/src/lib/vfs/terminal_file_system.h
@@ -6,7 +6,7 @@
*/
/*
- * Copyright (C) 2012-2014 Genode Labs GmbH
+ * Copyright (C) 2012-2016 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2.
@@ -25,28 +25,20 @@ class Vfs::Terminal_file_system : public Single_file_system
{
private:
- struct Label
- {
- enum { LABEL_MAX_LEN = 64 };
- char string[LABEL_MAX_LEN];
-
- Label(Xml_node config)
- {
- string[0] = 0;
- try { config.attribute("label").value(string, sizeof(string)); }
- catch (...) { }
- }
- } _label;
+ typedef Genode::String<64> Label;
+ Label _label;
Terminal::Connection _terminal;
public:
- Terminal_file_system(Xml_node config)
+ Terminal_file_system(Genode::Env &env,
+ Genode::Allocator&,
+ Genode::Xml_node config)
:
Single_file_system(NODE_TYPE_CHAR_DEVICE, name(), config),
- _label(config),
- _terminal(_label.string)
+ _label(config.attribute_value("label", Label())),
+ _terminal(env, _label.string())
{
/*
* Wait for connection-established signal
diff --git a/repos/os/src/lib/vfs/zero_file_system.h b/repos/os/src/lib/vfs/zero_file_system.h
index 975282696e..20faf851e3 100644
--- a/repos/os/src/lib/vfs/zero_file_system.h
+++ b/repos/os/src/lib/vfs/zero_file_system.h
@@ -6,7 +6,7 @@
*/
/*
- * Copyright (C) 2012-2014 Genode Labs GmbH
+ * Copyright (C) 2012-2016 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2.
@@ -22,7 +22,9 @@ namespace Vfs { class Zero_file_system; }
struct Vfs::Zero_file_system : Single_file_system
{
- Zero_file_system(Xml_node config)
+ Zero_file_system(Genode::Env&,
+ Genode::Allocator&,
+ Genode::Xml_node config)
:
Single_file_system(NODE_TYPE_CHAR_DEVICE, name(), config)
{ }
diff --git a/repos/os/src/server/vfs/main.cc b/repos/os/src/server/vfs/main.cc
index 546d180270..4aa8353a98 100644
--- a/repos/os/src/server/vfs/main.cc
+++ b/repos/os/src/server/vfs/main.cc
@@ -17,11 +17,11 @@
#include
#include
#include
-#include
#include
#include
#include
#include
+#include
/* Local includes */
#include "assert.h"
@@ -34,7 +34,6 @@ namespace Vfs_server {
class Session_component;
class Root;
- struct Main;
static Genode::Xml_node vfs_config()
{
@@ -70,7 +69,7 @@ class Vfs_server::Session_component :
Genode::Heap _alloc =
{ &_ram, Genode::env()->rm_session() };
- Genode::Signal_rpc_member
+ Genode::Signal_handler
_process_packet_dispatcher;
Vfs::Dir_file_system &_vfs;
Directory _root;
@@ -141,8 +140,10 @@ class Vfs_server::Session_component :
size_t const length = packet.length();
seek_off_t const seek = packet.position();
+ /* assume failure by default */
+ packet.succeeded(false);
+
if ((!(content && length)) || (packet.length() > packet.size())) {
- packet.succeeded(false);
return;
}
@@ -178,9 +179,6 @@ class Vfs_server::Session_component :
{
Packet_descriptor packet = tx_sink()->get_packet();
- /* assume failure by default */
- packet.succeeded(false);
-
_process_packet_op(packet);
/*
@@ -194,7 +192,7 @@ class Vfs_server::Session_component :
* Called by signal dispatcher, executed in the context of the main
* thread (not serialized with the RPC functions)
*/
- void _process_packets(unsigned)
+ void _process_packets()
{
while (tx_sink()->packet_avail()) {
@@ -221,7 +219,7 @@ class Vfs_server::Session_component :
* Check if string represents a valid path (must start with '/')
*/
static void _assert_valid_path(char const *path) {
- if (path[0] != '/') throw Lookup_failed(); }
+ if (!path || path[0] != '/') throw Lookup_failed(); }
/**
* Check if string represents a valid name (must not contain '/')
@@ -244,7 +242,8 @@ class Vfs_server::Session_component :
* \param root_path path root of the session
* \param writable whether the session can modify files
*/
- Session_component(Server::Entrypoint &ep,
+
+ Session_component(Genode::Env &env,
char const *label,
size_t ram_quota,
size_t tx_buf_size,
@@ -252,9 +251,9 @@ class Vfs_server::Session_component :
char const *root_path,
bool writable)
:
- Session_rpc_object(env()->ram_session()->alloc(tx_buf_size), ep.rpc_ep()),
+ Session_rpc_object(env.ram().alloc(tx_buf_size), env.ep().rpc_ep()),
_label(label),
- _process_packet_dispatcher(ep, *this, &Session_component::_process_packets),
+ _process_packet_dispatcher(env.ep(), *this, &Session_component::_process_packets),
_vfs(vfs),
_root(vfs, root_path, false),
_writable(writable)
@@ -554,10 +553,11 @@ class Vfs_server::Root :
{
private:
- Vfs::Dir_file_system _vfs =
- { vfs_config(), Vfs::global_file_system_factory() };
+ Genode::Env &_env;
+ Genode::Heap _heap { &_env.ram(), &_env.rm() };
- Server::Entrypoint &_ep;
+ Vfs::Dir_file_system _vfs
+ { _env, _heap, vfs_config(), Vfs::global_file_system_factory() };
protected:
@@ -632,7 +632,7 @@ class Vfs_server::Root :
}
Session_component *session = new(md_alloc())
- Session_component(_ep,
+ Session_component(_env,
label.string(),
ram_quota,
tx_buf_size,
@@ -652,48 +652,25 @@ class Vfs_server::Root :
public:
- /**
- * Constructor
- *
- * \param ep entrypoint
- * \param md_alloc meta-data allocator
- */
- Root(Server::Entrypoint &ep, Genode::Allocator &md_alloc)
+ Root(Genode::Env &env, Genode::Allocator &md_alloc)
:
- Root_component(&ep.rpc_ep(), &md_alloc),
- _ep(ep)
- { }
+ Root_component(&env.ep().rpc_ep(), &md_alloc),
+ _env(env)
+ {
+ env.parent().announce(env.ep().manage(*this));
+ }
};
-struct Vfs_server::Main
+/***************
+ ** Component **
+ ***************/
+
+Genode::size_t Component::stack_size() { return 2*1024*sizeof(long); }
+
+void Component::construct(Genode::Env &env)
{
- Server::Entrypoint &ep;
+ static Genode::Sliced_heap sliced_heap { &env.ram(), &env.rm() };
- /*
- * Initialize root interface
- */
- Genode::Sliced_heap sliced_heap =
- { Genode::env()->ram_session(), Genode::env()->rm_session() };
-
- Vfs_server::Root fs_root = { ep, sliced_heap };
-
- Main(Server::Entrypoint &ep) : ep(ep)
- {
- env()->parent()->announce(ep.manage(fs_root));
- }
-};
-
-
-/**********************
- ** Server framework **
- **********************/
-
-char const * Server::name() { return "vfs_ep"; }
-
-Genode::size_t Server::stack_size() { return 2*1024*sizeof(long); }
-
-void Server::construct(Server::Entrypoint &ep)
-{
- static Vfs_server::Main inst(ep);
+ static Vfs_server::Root root { env, sliced_heap };
}
diff --git a/repos/os/src/server/vfs/target.mk b/repos/os/src/server/vfs/target.mk
index d5095585bd..4d41be738d 100644
--- a/repos/os/src/server/vfs/target.mk
+++ b/repos/os/src/server/vfs/target.mk
@@ -1,4 +1,4 @@
TARGET = vfs
SRC_CC = main.cc
-LIBS = base config server vfs
+LIBS = base config vfs
INC_DIR += $(PRG_DIR)
diff --git a/repos/os/src/test/vfs_stress/main.cc b/repos/os/src/test/vfs_stress/main.cc
index afb2697202..bf5f98aaa6 100644
--- a/repos/os/src/test/vfs_stress/main.cc
+++ b/repos/os/src/test/vfs_stress/main.cc
@@ -36,6 +36,7 @@
#include
#include
#include
+#include
#include
#include
#include
@@ -143,12 +144,13 @@ typedef Genode::Path Path;
struct Stress_test
{
- ::Path path;
- Vfs::file_size count;
- Vfs::File_system &vfs;
+ ::Path path;
+ Vfs::file_size count;
+ Vfs::File_system &vfs;
+ Genode::Allocator &alloc;
- Stress_test(Vfs::File_system &vfs, char const *parent)
- : path(parent), count(0), vfs(vfs) { }
+ Stress_test(Vfs::File_system &vfs, Genode::Allocator &alloc, char const *parent)
+ : path(parent), count(0), vfs(vfs), alloc(alloc) { }
};
@@ -183,8 +185,8 @@ struct Mkdir_test : public Stress_test
mkdir_a(depth);
}
- Mkdir_test(Vfs::File_system &vfs, char const *parent)
- : Stress_test(vfs, parent)
+ Mkdir_test(Vfs::File_system &vfs, Genode::Allocator &alloc, char const *parent)
+ : Stress_test(vfs, alloc, parent)
{
try { mkdir_a(1); } catch (...) {
error("failed at '", path, "' after ", count, " directories");
@@ -213,7 +215,7 @@ struct Populate_test : public Stress_test
{
Vfs_handle *handle = nullptr;
assert_open(vfs.open(
- path.base(), Directory_service::OPEN_MODE_CREATE, &handle));
+ path.base(), Directory_service::OPEN_MODE_CREATE, &handle, alloc));
Vfs_handle::Guard guard(handle);
++count;
}
@@ -237,8 +239,8 @@ struct Populate_test : public Stress_test
}
}
- Populate_test(Vfs::File_system &vfs, char const *parent)
- : Stress_test(vfs, parent)
+ Populate_test(Vfs::File_system &vfs, Genode::Allocator &alloc, char const *parent)
+ : Stress_test(vfs, alloc, parent)
{
::Path start_path(path.base());
try {
@@ -275,7 +277,7 @@ struct Write_test : public Stress_test
{
Vfs_handle *handle = nullptr;
assert_open(vfs.open(
- path.base(), Directory_service::OPEN_MODE_WRONLY, &handle));
+ path.base(), Directory_service::OPEN_MODE_WRONLY, &handle, alloc));
Vfs_handle::Guard guard(handle);
file_size n;
@@ -303,8 +305,8 @@ struct Write_test : public Stress_test
}
}
- Write_test(Vfs::File_system &vfs, char const *parent)
- : Stress_test(vfs, parent)
+ Write_test(Vfs::File_system &vfs, Genode::Allocator &alloc, char const *parent)
+ : Stress_test(vfs, alloc, parent)
{
size_t path_len = strlen(path.base());
try {
@@ -341,7 +343,7 @@ struct Read_test : public Stress_test
{
Vfs_handle *handle = nullptr;
assert_open(vfs.open(
- path.base(), Directory_service::OPEN_MODE_RDONLY, &handle));
+ path.base(), Directory_service::OPEN_MODE_RDONLY, &handle, alloc));
Vfs_handle::Guard guard(handle);
char tmp[MAX_PATH_LEN];
@@ -371,8 +373,8 @@ struct Read_test : public Stress_test
}
}
- Read_test(Vfs::File_system &vfs, char const *parent)
- : Stress_test(vfs, parent)
+ Read_test(Vfs::File_system &vfs, Genode::Allocator &alloc, char const *parent)
+ : Stress_test(vfs, alloc, parent)
{
size_t path_len = strlen(path.base());
try {
@@ -426,8 +428,8 @@ struct Unlink_test : public Stress_test
}
}
- Unlink_test(Vfs::File_system &vfs, char const *parent)
- : Stress_test(vfs, parent)
+ Unlink_test(Vfs::File_system &vfs, Genode::Allocator &alloc, char const *parent)
+ : Stress_test(vfs, alloc, parent)
{
typedef Vfs::Directory_service::Unlink_result Result;
try {
@@ -463,11 +465,13 @@ void Component::construct(Genode::Env &env)
{
enum { ROOT_TREE_COUNT = 6 };
+ Genode::Heap heap(env.ram(), env.rm());
+
Attached_rom_dataspace config_rom(env, "config");
Xml_node const config_xml = config_rom.xml();
- Vfs::Dir_file_system vfs_root(config_xml.sub_node("vfs"),
- Vfs::global_file_system_factory());
+ Vfs::Dir_file_system vfs_root(env, heap, config_xml.sub_node("vfs"),
+ Vfs::global_file_system_factory());
char path[Vfs::MAX_PATH_LEN];
MAX_DEPTH = config_xml.attribute_value("depth", 16U);
@@ -491,7 +495,7 @@ void Component::construct(Genode::Env &env)
for (int i = 0; i < ROOT_TREE_COUNT; ++i) {
snprintf(path, 3, "/%d", i);
vfs_root.mkdir(path, 0);
- Mkdir_test test(vfs_root, path);
+ Mkdir_test test(vfs_root, heap, path);
count += test.wait();
}
elapsed_ms = timer.elapsed_ms() - elapsed_ms;
@@ -514,7 +518,7 @@ void Component::construct(Genode::Env &env)
for (int i = 0; i < ROOT_TREE_COUNT; ++i) {
snprintf(path, 3, "/%d", i);
- Populate_test test(vfs_root, path);
+ Populate_test test(vfs_root, heap, path);
count += test.wait();
}
@@ -544,7 +548,7 @@ void Component::construct(Genode::Env &env)
for (int i = 0; i < ROOT_TREE_COUNT; ++i) {
snprintf(path, 3, "/%d", i);
- Write_test test(vfs_root, path);
+ Write_test test(vfs_root, heap, path);
count += test.wait();
}
@@ -576,7 +580,7 @@ void Component::construct(Genode::Env &env)
for (int i = 0; i < ROOT_TREE_COUNT; ++i) {
snprintf(path, 3, "/%d", i);
- Read_test test(vfs_root, path);
+ Read_test test(vfs_root, heap, path);
count += test.wait();
}
@@ -608,7 +612,7 @@ void Component::construct(Genode::Env &env)
for (int i = 0; i < ROOT_TREE_COUNT; ++i) {
snprintf(path, 3, "/%d", i);
- Unlink_test test(vfs_root, path);
+ Unlink_test test(vfs_root, heap, path);
count += test.wait();
}
diff --git a/repos/ports/run/vbox_win.inc b/repos/ports/run/vbox_win.inc
index 288b757acb..0a92d8a1ca 100644
--- a/repos/ports/run/vbox_win.inc
+++ b/repos/ports/run/vbox_win.inc
@@ -122,7 +122,7 @@ append config_of_app {
-
+
diff --git a/repos/ports/src/noux/main.cc b/repos/ports/src/noux/main.cc
index e66319639e..114ac24a12 100644
--- a/repos/ports/src/noux/main.cc
+++ b/repos/ports/src/noux/main.cc
@@ -30,6 +30,7 @@
#include
#include
#include
+#include
/* supported file systems */
#include
@@ -287,7 +288,8 @@ bool Noux::Child::syscall(Noux::Session::Syscall sc)
Vfs::Vfs_handle *vfs_handle = 0;
_sysio->error.open = root_dir()->open(_sysio->open_in.path,
_sysio->open_in.mode,
- &vfs_handle);
+ &vfs_handle,
+ *Genode::env()->heap());
if (!vfs_handle)
break;
@@ -1049,7 +1051,9 @@ static Noux::Io_channel *connect_stdio(Vfs::Dir_file_system &root,
config()->xml_node().attribute(stdio_name).value(
path, sizeof(path));
- if (root.open(path, mode, &vfs_handle) != Directory_service::OPEN_OK) {
+ if (root.open(path, mode, &vfs_handle, *Genode::env()->heap())
+ != Directory_service::OPEN_OK)
+ {
error("failed to connect ", stdio_name, " to '", Cstring(path), "'");
Genode::env()->parent()->exit(1);
}
@@ -1117,14 +1121,18 @@ void operator delete (void * ptr)
template
struct File_system_factory : Vfs::File_system_factory
{
- Vfs::File_system *create(Genode::Xml_node node)
+ Vfs::File_system *create(Genode::Env &env, Genode::Allocator &alloc,
+ Genode::Xml_node node)
{
- return new FILE_SYSTEM(node);
+ return new FILE_SYSTEM(env, alloc, node);
}
};
-int main(int argc, char **argv)
+/**
+ * XXX: only a partial conversion from `int main(...)` to `void construct(...)`
+ */
+void Component::construct(Genode::Env &env)
{
using namespace Noux;
log("--- noux started ---");
@@ -1151,8 +1159,9 @@ int main(int argc, char **argv)
fs_factory.extend("random", random_file_system_factory);
/* initialize virtual file system */
- static Vfs::Dir_file_system
- root_dir(config()->xml_node().sub_node("fstab"), fs_factory);
+ static Vfs::Dir_file_system root_dir(env, *Genode::env()->heap(),
+ config()->xml_node().sub_node("fstab"),
+ fs_factory);
/* set user information */
try {
@@ -1199,7 +1208,7 @@ int main(int argc, char **argv)
parent_services,
resources_ep,
false,
- env()->heap(),
+ Genode::env()->heap(),
destruct_queue,
verbose);
@@ -1241,10 +1250,10 @@ int main(int argc, char **argv)
destruct_queue.flush();
if (verbose_quota)
- log("quota: avail=", env()->ram_session()->avail(), " "
- "used=", env()->ram_session()->used());
+ log("quota: avail=", env.ram().avail(), " "
+ "used=", env.ram().used());
}
log("--- exiting noux ---");
- return exit_value;
+ env.parent().exit(exit_value);
}
diff --git a/repos/ports/src/noux/random_file_system.h b/repos/ports/src/noux/random_file_system.h
index 85e6dfade7..14443166b8 100644
--- a/repos/ports/src/noux/random_file_system.h
+++ b/repos/ports/src/noux/random_file_system.h
@@ -237,7 +237,8 @@ namespace Noux {
public:
- Random_file_system(Xml_node config)
+ Random_file_system(Genode::Env&, Genode::Allocator&,
+ Genode::Xml_node config)
:
Single_file_system(NODE_TYPE_CHAR_DEVICE, name(), config),
_arc4random(0, 0)
diff --git a/repos/ports/src/noux/stdio_file_system.h b/repos/ports/src/noux/stdio_file_system.h
index 051917757e..31c5bff8ea 100644
--- a/repos/ports/src/noux/stdio_file_system.h
+++ b/repos/ports/src/noux/stdio_file_system.h
@@ -35,7 +35,8 @@ namespace Noux {
public:
- Stdio_file_system(Xml_node config)
+ Stdio_file_system(Genode::Env&, Genode::Allocator&,
+ Genode::Xml_node config)
:
Single_file_system(NODE_TYPE_CHAR_DEVICE, name(), config),
_terminal(terminal()),
diff --git a/repos/ports/src/virtualbox/frontend/main.cc b/repos/ports/src/virtualbox/frontend/main.cc
index bbf3ef0a93..f3c05d7a41 100644
--- a/repos/ports/src/virtualbox/frontend/main.cc
+++ b/repos/ports/src/virtualbox/frontend/main.cc
@@ -39,6 +39,8 @@
static char c_vbox_file[128];
static char c_vbox_vmname[128];
+extern "C" void init_libc_vbox_logger(void);
+
/**
* xpcom style memory allocation
@@ -207,6 +209,9 @@ int main(int argc, char **argv)
throw;
}
+ /* enable stdout/stderr for VBox Log infrastructure */
+ init_libc_vbox_logger();
+
int rc = RTR3InitExe(argc, &argv, 0);
if (RT_FAILURE(rc))
return -1;
diff --git a/repos/ports/src/virtualbox/logger.cc b/repos/ports/src/virtualbox/logger.cc
index 524e5a2f15..63cc429806 100644
--- a/repos/ports/src/virtualbox/logger.cc
+++ b/repos/ports/src/virtualbox/logger.cc
@@ -144,7 +144,7 @@ namespace {
} /* unnamed namespace */
-void __attribute__((constructor)) init_libc_vbox_logger(void)
+extern "C" void init_libc_vbox_logger(void)
{
static Plugin plugin;
}
diff --git a/repos/ports/src/virtualbox5/frontend/main.cc b/repos/ports/src/virtualbox5/frontend/main.cc
index 60d40ac693..c6b2ef8537 100644
--- a/repos/ports/src/virtualbox5/frontend/main.cc
+++ b/repos/ports/src/virtualbox5/frontend/main.cc
@@ -38,6 +38,7 @@
static char c_vbox_file[128];
static char c_vbox_vmname[128];
+extern "C" void init_libc_vbox_logger(void);
/**
* xpcom style memory allocation
@@ -239,6 +240,9 @@ int main(int argc, char **argv)
throw;
}
+ /* enable stdout/stderr for VBox Log infrastructure */
+ init_libc_vbox_logger();
+
int rc = RTR3InitExe(argc, &argv, 0);
if (RT_FAILURE(rc))
return -1;