vfs: pass Env and allocator when creating file-systems

Fix #1891
This commit is contained in:
Emery Hemingway 2016-05-25 15:47:22 +02:00 committed by Christian Helmuth
parent beebd394fc
commit ddf3716cff
37 changed files with 436 additions and 358 deletions

View File

@ -1,3 +1,5 @@
REQUIRES = conversion_to_vfs_plugin
EXFAT_DIR := $(call select_from_ports,exfat)/src/lib/exfat EXFAT_DIR := $(call select_from_ports,exfat)/src/lib/exfat
SRC_C = $(notdir $(EXFAT_DIR)/fuse/main.c) SRC_C = $(notdir $(EXFAT_DIR)/fuse/main.c)

View File

@ -1,3 +1,5 @@
REQUIRES = conversion_to_vfs_plugin
FUSE_EXT2_PORT_DIR := $(call select_from_ports,fuse-ext2) FUSE_EXT2_PORT_DIR := $(call select_from_ports,fuse-ext2)
FUSE_EXT2_DIR := $(FUSE_EXT2_PORT_DIR)/src/lib/fuse-ext2/fuse-ext2 FUSE_EXT2_DIR := $(FUSE_EXT2_PORT_DIR)/src/lib/fuse-ext2/fuse-ext2

View File

@ -1,3 +1,5 @@
REQUIRES = conversion_to_vfs_plugin
NTFS_3G_DIR := $(call select_from_ports,ntfs-3g)/src/lib/ntfs-3g NTFS_3G_DIR := $(call select_from_ports,ntfs-3g)/src/lib/ntfs-3g
SRC_C = ntfs-3g.c ntfs-3g_common.c SRC_C = ntfs-3g.c ntfs-3g_common.c

View File

@ -16,6 +16,6 @@
extern "C" int issetugid(void) 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; return 1;
} }

View File

@ -32,7 +32,7 @@ extern "C" int __attribute__((weak)) getrlimit(int resource, struct rlimit *rlim
return 0; return 0;
} }
Genode::raw("getrlimit called, return 0"); Genode::warning("getrlimit called, return 0");
return 0; return 0;
} }

View File

@ -17,10 +17,12 @@
#include <base/thread.h> #include <base/thread.h>
#include <base/rpc_server.h> #include <base/rpc_server.h>
#include <base/rpc_client.h> #include <base/rpc_client.h>
#include <base/heap.h>
/* libc-internal includes */ /* libc-internal includes */
#include <internal/call_func.h> #include <internal/call_func.h>
#include <base/internal/unmanaged_singleton.h> #include <base/internal/unmanaged_singleton.h>
#include "vfs_plugin.h"
/* escape sequences for highlighting debug message prefixes */ /* escape sequences for highlighting debug message prefixes */
@ -72,6 +74,11 @@ class Libc::Task : public Genode::Rpc_object<Task_resume, Libc::Task>
Genode::Env &_env; 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 * Application context and execution state
*/ */

View File

@ -33,7 +33,7 @@
/* libc plugin interface */ /* libc plugin interface */
#include <libc-plugin/plugin.h> #include <libc-plugin/plugin.h>
#include <libc-plugin/fd_alloc.h> #include <vfs_plugin.h>
/* libc-internal includes */ /* libc-internal includes */
#include <libc_mem_alloc.h> #include <libc_mem_alloc.h>
@ -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("<vfs/>");
}
}
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) int Libc::Vfs_plugin::access(const char *path, int amode)
{ {
if (_root_dir.leaf_path(path)) 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) { while (handle == 0) {
switch (_root_dir.open(path, flags, &handle)) { switch (_root_dir.open(path, flags, &handle, _alloc)) {
case Result::OPEN_OK: case Result::OPEN_OK:
break; 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 */ /* 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: case Result::OPEN_OK:
break; break;
@ -857,9 +751,3 @@ int Libc::Vfs_plugin::munmap(void *addr, ::size_t)
Libc::mem_alloc()->free(addr); Libc::mem_alloc()->free(addr);
return 0; return 0;
} }
void __attribute__((constructor)) init_libc_vfs(void)
{
static Libc::Vfs_plugin plugin;
}

View File

@ -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 <base/env.h>
#include <base/printf.h>
#include <vfs/dir_file_system.h>
#include <os/config.h>
/* libc includes */
#include <fcntl.h>
#include <unistd.h>
/* libc plugin interface */
#include <libc-plugin/plugin.h>
#include <libc-plugin/fd_alloc.h>
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("<vfs/>");
}
}
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

View File

@ -20,9 +20,10 @@
struct Jitterentropy_factory : Vfs::File_system_factory 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);
} }
}; };

View File

@ -206,7 +206,10 @@ class Vfs::Dir_file_system : public File_system
public: 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) _first_file_system(0)
{ {
@ -224,12 +227,12 @@ class Vfs::Dir_file_system : public File_system
/* traverse into <dir> nodes */ /* traverse into <dir> nodes */
if (sub_node.has_type("dir")) { if (sub_node.has_type("dir")) {
_append_file_system(new (env()->heap()) _append_file_system(new (alloc)
Dir_file_system(sub_node, fs_factory)); Dir_file_system(env, alloc, sub_node, fs_factory));
continue; continue;
} }
File_system *fs = fs_factory.create(sub_node); File_system *fs = fs_factory.create(env, alloc, sub_node);
if (fs) { if (fs) {
_append_file_system(fs); _append_file_system(fs);
continue; continue;
@ -420,7 +423,7 @@ class Vfs::Dir_file_system : public File_system
Open_result open(char const *path, Open_result open(char const *path,
unsigned mode, unsigned mode,
Vfs_handle **out_handle, Vfs_handle **out_handle,
Allocator &alloc = *Genode::env()->heap()) override Allocator &alloc) override
{ {
/* /*
* If 'path' is a directory, we create a 'Vfs_handle' * If 'path' is a directory, we create a 'Vfs_handle'

View File

@ -61,7 +61,7 @@ struct Vfs::Directory_service
virtual Open_result open(char const *path, virtual Open_result open(char const *path,
unsigned mode, unsigned mode,
Vfs_handle **handle, Vfs_handle **handle,
Allocator &alloc = *Genode::env()->heap()) = 0; Allocator &alloc) = 0;
/** /**
* Close handle resources and deallocate handle * Close handle resources and deallocate handle

View File

@ -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 * This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2. * under the terms of the GNU General Public License version 2.
@ -30,7 +30,16 @@ namespace Vfs {
struct Vfs::File_system_factory 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;
}; };

View File

@ -16,6 +16,7 @@
#include <cap_session/connection.h> #include <cap_session/connection.h>
#include <vfs/file_system_factory.h> #include <vfs/file_system_factory.h>
#include <vfs/dir_file_system.h> #include <vfs/dir_file_system.h>
#include <base/component.h>
/* public CLI-monitor includes */ /* public CLI-monitor includes */
#include <cli_monitor/ram.h> #include <cli_monitor/ram.h>
@ -71,31 +72,17 @@ static size_t ram_preservation_from_config()
} }
/** static Genode::Xml_node vfs_config()
* Return singleton instance of the subsystem config registry
*/
static Subsystem_config_registry &subsystem_config_registry()
{ {
try { try { return Genode::config()->xml_node().sub_node("vfs"); }
catch (Genode::Xml_node::Nonexistent_sub_node) {
/* 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) {
Genode::error("missing '<vfs>' configuration"); Genode::error("missing '<vfs>' configuration");
throw; throw;
} }
} }
int main(int argc, char **argv) void Component::construct(Genode::Env &env)
{ {
/* look for dynamic linker */ /* look for dynamic linker */
Genode::Dataspace_capability ldso_ds; Genode::Dataspace_capability ldso_ds;
@ -109,7 +96,7 @@ int main(int argc, char **argv)
using Genode::Signal_receiver; using Genode::Signal_receiver;
static Genode::Cap_connection cap; static Genode::Cap_connection cap;
static Terminal::Connection terminal; static Terminal::Connection terminal(env);
static Command_registry commands; static Command_registry commands;
static Child_registry children; static Child_registry children;
@ -135,12 +122,18 @@ int main(int argc, char **argv)
sig_rec.manage(&yield_broadcast_sig_ctx), sig_rec.manage(&yield_broadcast_sig_ctx),
sig_rec.manage(&resource_avail_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 */ /* initialize generic commands */
commands.insert(new Help_command); commands.insert(new Help_command);
Kill_command kill_command(children); Kill_command kill_command(children);
commands.insert(&kill_command); commands.insert(&kill_command);
commands.insert(new Start_command(ram, cap, children, commands.insert(new Start_command(ram, cap, children,
subsystem_config_registry(), subsystem_config_registry,
yield_response_sig_cap, yield_response_sig_cap,
exited_child_sig_cap, exited_child_sig_cap,
ldso_ds)); ldso_ds));
@ -240,5 +233,5 @@ int main(int argc, char **argv)
line_editor.reset(); line_editor.reset();
} }
return 0; env.parent().exit(0);
} }

View File

@ -89,7 +89,7 @@ class Subsystem_config_registry
Vfs::Directory_service::Open_result const open_result = Vfs::Directory_service::Open_result const open_result =
_fs.open(path.base(), _fs.open(path.base(),
Vfs::Directory_service::OPEN_MODE_RDONLY, Vfs::Directory_service::OPEN_MODE_RDONLY,
&handle); &handle, *Genode::env()->heap());
Vfs::Vfs_handle::Guard handle_guard(handle); Vfs::Vfs_handle::Guard handle_guard(handle);

View File

@ -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 * This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2. * 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: private:
struct Label Genode::Allocator &_alloc;
{
enum { LABEL_MAX_LEN = 64 };
char string[LABEL_MAX_LEN];
Label(Xml_node config) typedef Genode::String<64> Label;
{ Label _label;
string[0] = 0;
try { config.attribute("label").value(string, sizeof(string)); }
catch (...) { }
}
} _label;
/* /*
* Serialize access to packet stream of the block session * 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; char *_block_buffer;
unsigned _block_buffer_count; unsigned _block_buffer_count;
Genode::Allocator_avl _tx_block_alloc; Genode::Allocator_avl _tx_block_alloc { &_alloc };
Block::Connection _block; Block::Connection _block;
Genode::size_t _block_size; Genode::size_t _block_size;
Block::sector_t _block_count; Block::sector_t _block_count;
@ -98,14 +90,16 @@ class Vfs::Block_file_system : public Single_file_system
public: 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), Single_file_system(NODE_TYPE_BLOCK_DEVICE, name(), config),
_label(config), _alloc(alloc),
_label(config.attribute_value("label", Label())),
_block_buffer(0), _block_buffer(0),
_block_buffer_count(1), _block_buffer_count(1),
_tx_block_alloc(env()->heap()), _block(env, &_tx_block_alloc, 128*1024, _label.string()),
_block(&_tx_block_alloc, 128*1024, _label.string),
_tx_source(_block.tx()), _tx_source(_block.tx()),
_readable(false), _readable(false),
_writeable(false) _writeable(false)
@ -118,12 +112,12 @@ class Vfs::Block_file_system : public Single_file_system
_readable = _block_ops.supported(Block::Packet_descriptor::READ); _readable = _block_ops.supported(Block::Packet_descriptor::READ);
_writeable = _block_ops.supported(Block::Packet_descriptor::WRITE); _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() ~Block_file_system()
{ {
destroy(env()->heap(), _block_buffer); destroy(_alloc, _block_buffer);
} }
static char const *name() { return "block"; } static char const *name() { return "block"; }

View File

@ -55,9 +55,11 @@ class Default_file_system_factory : public Vfs::Global_file_system_factory
{ {
Builtin_entry() : Entry_base(FILE_SYSTEM::name()) { } 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) { } Entry_base(name), _fs_factory(fs_factory) { }
Vfs::File_system *create(Genode::Xml_node node) override { Vfs::File_system *create(Genode::Env &env,
return _fs_factory.create(node); } Genode::Allocator &alloc,
Genode::Xml_node node) override {
return _fs_factory.create(env, alloc, node); }
}; };
Genode::List<Entry_base> _list; Genode::List<Entry_base> _list;
@ -82,11 +86,13 @@ class Default_file_system_factory : public Vfs::Global_file_system_factory
_list.insert(new (Genode::env()->heap()) Builtin_entry<FILE_SYSTEM>()); _list.insert(new (Genode::env()->heap()) Builtin_entry<FILE_SYSTEM>());
} }
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()) for (Entry_base *e = _list.first(); e; e = e->next())
if (e->matches(node)) if (e->matches(node))
return e->create(node); return e->create(env, alloc, node);
return 0; return 0;
} }
@ -126,12 +132,13 @@ class Default_file_system_factory : public Vfs::Global_file_system_factory
/** /**
* \throw Factory_not_available * \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; Genode::Shared_object *shared_object = nullptr;
try { try {
shared_object = new (Genode::env()->heap()) shared_object = new (alloc)
Genode::Shared_object(lib_name.string()); Genode::Shared_object(lib_name.string());
typedef Vfs::File_system_factory *(*Query_fn)(); 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'", PWRN("could not find symbol '%s' in '%s'",
_factory_symbol(), lib_name.string()); _factory_symbol(), lib_name.string());
Genode::destroy(Genode::env()->heap(), shared_object); Genode::destroy(alloc, shared_object);
throw Factory_not_available(); 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)); Library_name const lib_name = _library_name(_node_name(node));
try { try {
_list.insert(new (Genode::env()->heap()) _list.insert(new (alloc)
External_entry(_node_name(node).string(), _load_factory(lib_name))); External_entry(_node_name(node).string(), _load_factory(alloc, lib_name)));
return true; return true;
} catch (Factory_not_available) { return false; } } catch (Factory_not_available) { return false; }
@ -167,20 +174,22 @@ class Default_file_system_factory : public Vfs::Global_file_system_factory
public: 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 {
/* try if type is handled by the currently registered fs types */ /* try if type is handled by the currently registered fs types */
if (Vfs::File_system *fs = _try_create(node)) if (Vfs::File_system *fs = _try_create(env, alloc, node))
return fs; return fs;
/* if the builtin fails, do not try loading an external */ /* if the builtin fails, do not try loading an external */
} catch (...) { return 0; } } catch (...) { return 0; }
try { try {
/* probe for file system implementation available as shared lib */ /* 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 */ /* 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; return fs;
} }
} catch (...) { } } catch (...) { }

View File

@ -25,6 +25,7 @@ class Vfs::Fs_file_system : public File_system
{ {
private: private:
/* /*
* Lock used to serialize the interaction with the packet stream of the * Lock used to serialize the interaction with the packet stream of the
* file-system session. * file-system session.
@ -34,7 +35,8 @@ class Vfs::Fs_file_system : public File_system
*/ */
Lock _lock; Lock _lock;
Genode::Allocator_avl _fs_packet_alloc; Genode::Env &_env;
Genode::Allocator_avl _fs_packet_alloc;
typedef Genode::String<64> Label_string; typedef Genode::String<64> Label_string;
Label_string _label; Label_string _label;
@ -149,9 +151,12 @@ class Vfs::Fs_file_system : public File_system
public: 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())), _label(config.attribute_value("label", Label_string())),
_root( config.attribute_value("root", Root_string())), _root( config.attribute_value("root", Root_string())),
_fs(_fs_packet_alloc, _fs(_fs_packet_alloc,
@ -191,9 +196,9 @@ class Vfs::Fs_file_system : public File_system
::File_system::Status status = _fs.status(file); ::File_system::Status status = _fs.status(file);
Ram_dataspace_capability ds_cap = 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_system::Session::Tx::Source &source = *_fs.tx();
file_size const max_packet_size = source.bulk_buffer_size() / 2; 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); source.release_packet(packet);
} }
env()->rm_session()->detach(local_addr); _env.rm().detach(local_addr);
return ds_cap; return ds_cap;
} catch(...) { } catch(...) {
env()->rm_session()->detach(local_addr); _env.rm().detach(local_addr);
env()->ram_session()->free(ds_cap); _env.ram().free(ds_cap);
return Dataspace_capability(); 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 void release(char const *path, Dataspace_capability ds_cap) override
{ {
if (ds_cap.valid()) if (ds_cap.valid())
env()->ram_session()->free(static_cap_cast<Genode::Ram_dataspace>(ds_cap)); _env.ram().free(static_cap_cast<Genode::Ram_dataspace>(ds_cap));
} }
Stat_result stat(char const *path, Stat &out) override Stat_result stat(char const *path, Stat &out) override

View File

@ -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 * This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2. * 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: 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), Single_file_system(NODE_TYPE_FILE, name(), config),
_base(config.content_base()), _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 Stat_result stat(char const *path, Stat &out) override

View File

@ -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 * This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2. * 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: 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) Single_file_system(NODE_TYPE_CHAR_DEVICE, name(), config)
{ } { }

View File

@ -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 * This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2. * 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 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) Single_file_system(NODE_TYPE_CHAR_DEVICE, name(), config)
{ } { }

View File

@ -356,6 +356,7 @@ class Vfs::Ram_file_system : public Vfs::File_system
} }
}; };
Genode::Env &_env;
Genode::Allocator &_alloc; Genode::Allocator &_alloc;
Vfs_ram::Directory _root = { "" }; Vfs_ram::Directory _root = { "" };
@ -419,8 +420,10 @@ class Vfs::Ram_file_system : public Vfs::File_system
public: public:
Ram_file_system(Xml_node config) Ram_file_system(Genode::Env &env,
: _alloc(*env()->heap()) { } Genode::Allocator &alloc,
Genode::Xml_node)
: _env(env), _alloc(alloc) { }
~Ram_file_system() { _root.empty(_alloc); } ~Ram_file_system() { _root.empty(_alloc); }
@ -705,22 +708,22 @@ class Vfs::Ram_file_system : public Vfs::File_system
char *local_addr = nullptr; char *local_addr = nullptr;
try { 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); file->read(local_addr, file->length(), 0);
env()->rm_session()->detach(local_addr); _env.rm().detach(local_addr);
} catch(...) { } catch(...) {
env()->rm_session()->detach(local_addr); _env.rm().detach(local_addr);
env()->ram_session()->free(ds_cap); _env.ram().free(ds_cap);
return Dataspace_capability(); return Dataspace_capability();
} }
return ds_cap; return ds_cap;
} }
void release(char const *path, Dataspace_capability ds_cap) override { void release(char const *path, Dataspace_capability ds_cap) override {
env()->ram_session()->free( _env.ram().free(
static_cap_cast<Genode::Ram_dataspace>(ds_cap)); } static_cap_cast<Genode::Ram_dataspace>(ds_cap)); }

View File

@ -14,7 +14,7 @@
#ifndef _INCLUDE__VFS__ROM_FILE_SYSTEM_H_ #ifndef _INCLUDE__VFS__ROM_FILE_SYSTEM_H_
#define _INCLUDE__VFS__ROM_FILE_SYSTEM_H_ #define _INCLUDE__VFS__ROM_FILE_SYSTEM_H_
#include <os/attached_rom_dataspace.h> #include <base/attached_rom_dataspace.h>
#include <vfs/file_system.h> #include <vfs/file_system.h>
namespace Vfs { class Rom_file_system; } namespace Vfs { class Rom_file_system; }
@ -48,11 +48,13 @@ class Vfs::Rom_file_system : public Single_file_system
public: 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), Single_file_system(NODE_TYPE_FILE, name(), config),
_label(config), _label(config),
_rom(_label.string) _rom(env, _label.string)
{ } { }
static char const *name() { return "rom"; } static char const *name() { return "rom"; }

View File

@ -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 * This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2. * 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: 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"; } static char const *name() { return "rtc"; }

View File

@ -42,13 +42,14 @@ class Vfs::Symlink_file_system : public File_system
public: public:
Symlink_file_system(Xml_node config) Symlink_file_system(Genode::Env&,
Genode::Allocator&,
Genode::Xml_node config)
{ {
try { try {
config.attribute("name").value(_filename, sizeof(_filename)); config.attribute("name").value(_filename, sizeof(_filename));
config.attribute("target").value(_target, sizeof(_target)); config.attribute("target").value(_target, sizeof(_target));
} catch (...) { } } catch (...) { }
} }
static char const *name() { return "symlink"; } static char const *name() { return "symlink"; }

View File

@ -17,27 +17,22 @@
#include <rom_session/connection.h> #include <rom_session/connection.h>
#include <vfs/file_system.h> #include <vfs/file_system.h>
#include <vfs/vfs_handle.h> #include <vfs/vfs_handle.h>
#include <base/attached_rom_dataspace.h>
namespace Vfs { class Tar_file_system; } namespace Vfs { class Tar_file_system; }
class Vfs::Tar_file_system : public File_system class Vfs::Tar_file_system : public File_system
{ {
struct Rom_name Genode::Env &_env;
{ Genode::Allocator &_alloc;
enum { ROM_NAME_MAX_LEN = 64 };
char name[ROM_NAME_MAX_LEN];
Rom_name(Xml_node config) { typedef Genode::String<64> Rom_name;
config.attribute("name").value(name, sizeof(name)); Rom_name _rom_name;
}
} _rom_name;
Genode::Rom_connection _rom; Genode::Attached_rom_dataspace _tar_ds { _env, _rom_name.string() };
char *_tar_base = _tar_ds.local_addr<char>();
Genode::Dataspace_capability _tar_ds; file_size const _tar_size = _tar_ds.size();
char *_tar_base;
file_size _tar_size;
class Record class Record
{ {
@ -192,11 +187,15 @@ class Vfs::Tar_file_system : public File_system
{ {
private: private:
Genode::Allocator &_alloc;
Node &_root_node; Node &_root_node;
public: 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) void operator()(Record const *record)
{ {
@ -242,16 +241,16 @@ class Vfs::Tar_file_system : public File_system
* pointer to save some memory * pointer to save some memory
*/ */
Genode::size_t name_size = strlen(path_element) + 1; 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); strncpy(name, path_element, name_size);
child_node = new (env()->heap()) Node(name, record); child_node = new (_alloc) Node(name, record);
} else { } else {
/* create a directory node without record */ /* create a directory node without record */
Genode::size_t name_size = strlen(path_element) + 1; 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); 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); parent_node->insert(child_node);
} }
@ -343,19 +342,19 @@ class Vfs::Tar_file_system : public File_system
public: 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), _env(env), _alloc(alloc),
_tar_ds(_rom.dataspace()), _rom_name(config.attribute_value("name", Rom_name())),
_tar_base(env()->rm_session()->attach(_tar_ds)),
_tar_size(Dataspace_client(_tar_ds).size()),
_root_node("", 0), _root_node("", 0),
_cached_num_dirent(_root_node) _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); "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 { try {
Ram_dataspace_capability ds_cap = 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()); memcpy(local_addr, record->data(), record->size());
env()->rm_session()->detach(local_addr); _env.rm().detach(local_addr);
return ds_cap; return ds_cap;
} }
@ -393,7 +392,7 @@ class Vfs::Tar_file_system : public File_system
void release(char const *, Dataspace_capability ds_cap) override void release(char const *, Dataspace_capability ds_cap) override
{ {
env()->ram_session()->free(static_cap_cast<Genode::Ram_dataspace>(ds_cap)); _env.ram().free(static_cap_cast<Genode::Ram_dataspace>(ds_cap));
} }
Stat_result stat(char const *path, Stat &out) override Stat_result stat(char const *path, Stat &out) override

View File

@ -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 * This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2. * 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: private:
struct Label typedef Genode::String<64> Label;
{ Label _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;
Terminal::Connection _terminal; Terminal::Connection _terminal;
public: 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), Single_file_system(NODE_TYPE_CHAR_DEVICE, name(), config),
_label(config), _label(config.attribute_value("label", Label())),
_terminal(_label.string) _terminal(env, _label.string())
{ {
/* /*
* Wait for connection-established signal * Wait for connection-established signal

View File

@ -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 * This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2. * 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 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) Single_file_system(NODE_TYPE_CHAR_DEVICE, name(), config)
{ } { }

View File

@ -17,11 +17,11 @@
#include <ram_session/connection.h> #include <ram_session/connection.h>
#include <root/component.h> #include <root/component.h>
#include <vfs/dir_file_system.h> #include <vfs/dir_file_system.h>
#include <os/server.h>
#include <os/session_policy.h> #include <os/session_policy.h>
#include <vfs/file_system_factory.h> #include <vfs/file_system_factory.h>
#include <os/config.h> #include <os/config.h>
#include <base/sleep.h> #include <base/sleep.h>
#include <base/component.h>
/* Local includes */ /* Local includes */
#include "assert.h" #include "assert.h"
@ -34,7 +34,6 @@ namespace Vfs_server {
class Session_component; class Session_component;
class Root; class Root;
struct Main;
static Genode::Xml_node vfs_config() static Genode::Xml_node vfs_config()
{ {
@ -70,7 +69,7 @@ class Vfs_server::Session_component :
Genode::Heap _alloc = Genode::Heap _alloc =
{ &_ram, Genode::env()->rm_session() }; { &_ram, Genode::env()->rm_session() };
Genode::Signal_rpc_member<Session_component> Genode::Signal_handler<Session_component>
_process_packet_dispatcher; _process_packet_dispatcher;
Vfs::Dir_file_system &_vfs; Vfs::Dir_file_system &_vfs;
Directory _root; Directory _root;
@ -141,8 +140,10 @@ class Vfs_server::Session_component :
size_t const length = packet.length(); size_t const length = packet.length();
seek_off_t const seek = packet.position(); seek_off_t const seek = packet.position();
/* assume failure by default */
packet.succeeded(false);
if ((!(content && length)) || (packet.length() > packet.size())) { if ((!(content && length)) || (packet.length() > packet.size())) {
packet.succeeded(false);
return; return;
} }
@ -178,9 +179,6 @@ class Vfs_server::Session_component :
{ {
Packet_descriptor packet = tx_sink()->get_packet(); Packet_descriptor packet = tx_sink()->get_packet();
/* assume failure by default */
packet.succeeded(false);
_process_packet_op(packet); _process_packet_op(packet);
/* /*
@ -194,7 +192,7 @@ class Vfs_server::Session_component :
* Called by signal dispatcher, executed in the context of the main * Called by signal dispatcher, executed in the context of the main
* thread (not serialized with the RPC functions) * thread (not serialized with the RPC functions)
*/ */
void _process_packets(unsigned) void _process_packets()
{ {
while (tx_sink()->packet_avail()) { while (tx_sink()->packet_avail()) {
@ -221,7 +219,7 @@ class Vfs_server::Session_component :
* Check if string represents a valid path (must start with '/') * Check if string represents a valid path (must start with '/')
*/ */
static void _assert_valid_path(char const *path) { 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 '/') * 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 root_path path root of the session
* \param writable whether the session can modify files * \param writable whether the session can modify files
*/ */
Session_component(Server::Entrypoint &ep,
Session_component(Genode::Env &env,
char const *label, char const *label,
size_t ram_quota, size_t ram_quota,
size_t tx_buf_size, size_t tx_buf_size,
@ -252,9 +251,9 @@ class Vfs_server::Session_component :
char const *root_path, char const *root_path,
bool writable) 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), _label(label),
_process_packet_dispatcher(ep, *this, &Session_component::_process_packets), _process_packet_dispatcher(env.ep(), *this, &Session_component::_process_packets),
_vfs(vfs), _vfs(vfs),
_root(vfs, root_path, false), _root(vfs, root_path, false),
_writable(writable) _writable(writable)
@ -554,10 +553,11 @@ class Vfs_server::Root :
{ {
private: private:
Vfs::Dir_file_system _vfs = Genode::Env &_env;
{ vfs_config(), Vfs::global_file_system_factory() }; 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: protected:
@ -632,7 +632,7 @@ class Vfs_server::Root :
} }
Session_component *session = new(md_alloc()) Session_component *session = new(md_alloc())
Session_component(_ep, Session_component(_env,
label.string(), label.string(),
ram_quota, ram_quota,
tx_buf_size, tx_buf_size,
@ -652,48 +652,25 @@ class Vfs_server::Root :
public: public:
/** Root(Genode::Env &env, Genode::Allocator &md_alloc)
* Constructor
*
* \param ep entrypoint
* \param md_alloc meta-data allocator
*/
Root(Server::Entrypoint &ep, Genode::Allocator &md_alloc)
: :
Root_component<Session_component>(&ep.rpc_ep(), &md_alloc), Root_component<Session_component>(&env.ep().rpc_ep(), &md_alloc),
_ep(ep) _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() };
/* static Vfs_server::Root root { env, sliced_heap };
* 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);
} }

View File

@ -1,4 +1,4 @@
TARGET = vfs TARGET = vfs
SRC_CC = main.cc SRC_CC = main.cc
LIBS = base config server vfs LIBS = base config vfs
INC_DIR += $(PRG_DIR) INC_DIR += $(PRG_DIR)

View File

@ -36,6 +36,7 @@
#include <vfs/file_system_factory.h> #include <vfs/file_system_factory.h>
#include <vfs/dir_file_system.h> #include <vfs/dir_file_system.h>
#include <timer_session/connection.h> #include <timer_session/connection.h>
#include <base/heap.h>
#include <base/attached_rom_dataspace.h> #include <base/attached_rom_dataspace.h>
#include <base/snprintf.h> #include <base/snprintf.h>
#include <base/component.h> #include <base/component.h>
@ -143,12 +144,13 @@ typedef Genode::Path<Vfs::MAX_PATH_LEN> Path;
struct Stress_test struct Stress_test
{ {
::Path path; ::Path path;
Vfs::file_size count; Vfs::file_size count;
Vfs::File_system &vfs; Vfs::File_system &vfs;
Genode::Allocator &alloc;
Stress_test(Vfs::File_system &vfs, char const *parent) Stress_test(Vfs::File_system &vfs, Genode::Allocator &alloc, char const *parent)
: path(parent), count(0), vfs(vfs) { } : path(parent), count(0), vfs(vfs), alloc(alloc) { }
}; };
@ -183,8 +185,8 @@ struct Mkdir_test : public Stress_test
mkdir_a(depth); mkdir_a(depth);
} }
Mkdir_test(Vfs::File_system &vfs, char const *parent) Mkdir_test(Vfs::File_system &vfs, Genode::Allocator &alloc, char const *parent)
: Stress_test(vfs, parent) : Stress_test(vfs, alloc, parent)
{ {
try { mkdir_a(1); } catch (...) { try { mkdir_a(1); } catch (...) {
error("failed at '", path, "' after ", count, " directories"); error("failed at '", path, "' after ", count, " directories");
@ -213,7 +215,7 @@ struct Populate_test : public Stress_test
{ {
Vfs_handle *handle = nullptr; Vfs_handle *handle = nullptr;
assert_open(vfs.open( 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); Vfs_handle::Guard guard(handle);
++count; ++count;
} }
@ -237,8 +239,8 @@ struct Populate_test : public Stress_test
} }
} }
Populate_test(Vfs::File_system &vfs, char const *parent) Populate_test(Vfs::File_system &vfs, Genode::Allocator &alloc, char const *parent)
: Stress_test(vfs, parent) : Stress_test(vfs, alloc, parent)
{ {
::Path start_path(path.base()); ::Path start_path(path.base());
try { try {
@ -275,7 +277,7 @@ struct Write_test : public Stress_test
{ {
Vfs_handle *handle = nullptr; Vfs_handle *handle = nullptr;
assert_open(vfs.open( 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); Vfs_handle::Guard guard(handle);
file_size n; file_size n;
@ -303,8 +305,8 @@ struct Write_test : public Stress_test
} }
} }
Write_test(Vfs::File_system &vfs, char const *parent) Write_test(Vfs::File_system &vfs, Genode::Allocator &alloc, char const *parent)
: Stress_test(vfs, parent) : Stress_test(vfs, alloc, parent)
{ {
size_t path_len = strlen(path.base()); size_t path_len = strlen(path.base());
try { try {
@ -341,7 +343,7 @@ struct Read_test : public Stress_test
{ {
Vfs_handle *handle = nullptr; Vfs_handle *handle = nullptr;
assert_open(vfs.open( 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); Vfs_handle::Guard guard(handle);
char tmp[MAX_PATH_LEN]; char tmp[MAX_PATH_LEN];
@ -371,8 +373,8 @@ struct Read_test : public Stress_test
} }
} }
Read_test(Vfs::File_system &vfs, char const *parent) Read_test(Vfs::File_system &vfs, Genode::Allocator &alloc, char const *parent)
: Stress_test(vfs, parent) : Stress_test(vfs, alloc, parent)
{ {
size_t path_len = strlen(path.base()); size_t path_len = strlen(path.base());
try { try {
@ -426,8 +428,8 @@ struct Unlink_test : public Stress_test
} }
} }
Unlink_test(Vfs::File_system &vfs, char const *parent) Unlink_test(Vfs::File_system &vfs, Genode::Allocator &alloc, char const *parent)
: Stress_test(vfs, parent) : Stress_test(vfs, alloc, parent)
{ {
typedef Vfs::Directory_service::Unlink_result Result; typedef Vfs::Directory_service::Unlink_result Result;
try { try {
@ -463,11 +465,13 @@ void Component::construct(Genode::Env &env)
{ {
enum { ROOT_TREE_COUNT = 6 }; enum { ROOT_TREE_COUNT = 6 };
Genode::Heap heap(env.ram(), env.rm());
Attached_rom_dataspace config_rom(env, "config"); Attached_rom_dataspace config_rom(env, "config");
Xml_node const config_xml = config_rom.xml(); Xml_node const config_xml = config_rom.xml();
Vfs::Dir_file_system vfs_root(config_xml.sub_node("vfs"), Vfs::Dir_file_system vfs_root(env, heap, config_xml.sub_node("vfs"),
Vfs::global_file_system_factory()); Vfs::global_file_system_factory());
char path[Vfs::MAX_PATH_LEN]; char path[Vfs::MAX_PATH_LEN];
MAX_DEPTH = config_xml.attribute_value("depth", 16U); 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) { for (int i = 0; i < ROOT_TREE_COUNT; ++i) {
snprintf(path, 3, "/%d", i); snprintf(path, 3, "/%d", i);
vfs_root.mkdir(path, 0); vfs_root.mkdir(path, 0);
Mkdir_test test(vfs_root, path); Mkdir_test test(vfs_root, heap, path);
count += test.wait(); count += test.wait();
} }
elapsed_ms = timer.elapsed_ms() - elapsed_ms; 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) { for (int i = 0; i < ROOT_TREE_COUNT; ++i) {
snprintf(path, 3, "/%d", i); snprintf(path, 3, "/%d", i);
Populate_test test(vfs_root, path); Populate_test test(vfs_root, heap, path);
count += test.wait(); count += test.wait();
} }
@ -544,7 +548,7 @@ void Component::construct(Genode::Env &env)
for (int i = 0; i < ROOT_TREE_COUNT; ++i) { for (int i = 0; i < ROOT_TREE_COUNT; ++i) {
snprintf(path, 3, "/%d", i); snprintf(path, 3, "/%d", i);
Write_test test(vfs_root, path); Write_test test(vfs_root, heap, path);
count += test.wait(); count += test.wait();
} }
@ -576,7 +580,7 @@ void Component::construct(Genode::Env &env)
for (int i = 0; i < ROOT_TREE_COUNT; ++i) { for (int i = 0; i < ROOT_TREE_COUNT; ++i) {
snprintf(path, 3, "/%d", i); snprintf(path, 3, "/%d", i);
Read_test test(vfs_root, path); Read_test test(vfs_root, heap, path);
count += test.wait(); count += test.wait();
} }
@ -608,7 +612,7 @@ void Component::construct(Genode::Env &env)
for (int i = 0; i < ROOT_TREE_COUNT; ++i) { for (int i = 0; i < ROOT_TREE_COUNT; ++i) {
snprintf(path, 3, "/%d", i); snprintf(path, 3, "/%d", i);
Unlink_test test(vfs_root, path); Unlink_test test(vfs_root, heap, path);
count += test.wait(); count += test.wait();
} }

View File

@ -122,7 +122,7 @@ append config_of_app {
</start> </start>
<start name="nitpicker" priority="-1"> <start name="nitpicker" priority="-1">
<resource name="RAM" quantum="2M"/> <resource name="RAM" quantum="4M"/>
<provides><service name="Nitpicker"/></provides> <provides><service name="Nitpicker"/></provides>
<route> <route>
<service name="Framebuffer"> <child name="fb_drv" /> </service> <service name="Framebuffer"> <child name="fb_drv" /> </service>

View File

@ -30,6 +30,7 @@
#include <destruct_queue.h> #include <destruct_queue.h>
#include <kill_broadcaster.h> #include <kill_broadcaster.h>
#include <vfs/dir_file_system.h> #include <vfs/dir_file_system.h>
#include <base/component.h>
/* supported file systems */ /* supported file systems */
#include <random_file_system.h> #include <random_file_system.h>
@ -287,7 +288,8 @@ bool Noux::Child::syscall(Noux::Session::Syscall sc)
Vfs::Vfs_handle *vfs_handle = 0; Vfs::Vfs_handle *vfs_handle = 0;
_sysio->error.open = root_dir()->open(_sysio->open_in.path, _sysio->error.open = root_dir()->open(_sysio->open_in.path,
_sysio->open_in.mode, _sysio->open_in.mode,
&vfs_handle); &vfs_handle,
*Genode::env()->heap());
if (!vfs_handle) if (!vfs_handle)
break; break;
@ -1049,7 +1051,9 @@ static Noux::Io_channel *connect_stdio(Vfs::Dir_file_system &root,
config()->xml_node().attribute(stdio_name).value( config()->xml_node().attribute(stdio_name).value(
path, sizeof(path)); 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), "'"); error("failed to connect ", stdio_name, " to '", Cstring(path), "'");
Genode::env()->parent()->exit(1); Genode::env()->parent()->exit(1);
} }
@ -1117,14 +1121,18 @@ void operator delete (void * ptr)
template <typename FILE_SYSTEM> template <typename FILE_SYSTEM>
struct File_system_factory : Vfs::File_system_factory 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; using namespace Noux;
log("--- noux started ---"); log("--- noux started ---");
@ -1151,8 +1159,9 @@ int main(int argc, char **argv)
fs_factory.extend("random", random_file_system_factory); fs_factory.extend("random", random_file_system_factory);
/* initialize virtual file system */ /* initialize virtual file system */
static Vfs::Dir_file_system static Vfs::Dir_file_system root_dir(env, *Genode::env()->heap(),
root_dir(config()->xml_node().sub_node("fstab"), fs_factory); config()->xml_node().sub_node("fstab"),
fs_factory);
/* set user information */ /* set user information */
try { try {
@ -1199,7 +1208,7 @@ int main(int argc, char **argv)
parent_services, parent_services,
resources_ep, resources_ep,
false, false,
env()->heap(), Genode::env()->heap(),
destruct_queue, destruct_queue,
verbose); verbose);
@ -1241,10 +1250,10 @@ int main(int argc, char **argv)
destruct_queue.flush(); destruct_queue.flush();
if (verbose_quota) if (verbose_quota)
log("quota: avail=", env()->ram_session()->avail(), " " log("quota: avail=", env.ram().avail(), " "
"used=", env()->ram_session()->used()); "used=", env.ram().used());
} }
log("--- exiting noux ---"); log("--- exiting noux ---");
return exit_value; env.parent().exit(exit_value);
} }

View File

@ -237,7 +237,8 @@ namespace Noux {
public: 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), Single_file_system(NODE_TYPE_CHAR_DEVICE, name(), config),
_arc4random(0, 0) _arc4random(0, 0)

View File

@ -35,7 +35,8 @@ namespace Noux {
public: 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), Single_file_system(NODE_TYPE_CHAR_DEVICE, name(), config),
_terminal(terminal()), _terminal(terminal()),

View File

@ -39,6 +39,8 @@
static char c_vbox_file[128]; static char c_vbox_file[128];
static char c_vbox_vmname[128]; static char c_vbox_vmname[128];
extern "C" void init_libc_vbox_logger(void);
/** /**
* xpcom style memory allocation * xpcom style memory allocation
@ -207,6 +209,9 @@ int main(int argc, char **argv)
throw; throw;
} }
/* enable stdout/stderr for VBox Log infrastructure */
init_libc_vbox_logger();
int rc = RTR3InitExe(argc, &argv, 0); int rc = RTR3InitExe(argc, &argv, 0);
if (RT_FAILURE(rc)) if (RT_FAILURE(rc))
return -1; return -1;

View File

@ -144,7 +144,7 @@ namespace {
} /* unnamed namespace */ } /* unnamed namespace */
void __attribute__((constructor)) init_libc_vbox_logger(void) extern "C" void init_libc_vbox_logger(void)
{ {
static Plugin plugin; static Plugin plugin;
} }

View File

@ -38,6 +38,7 @@
static char c_vbox_file[128]; static char c_vbox_file[128];
static char c_vbox_vmname[128]; static char c_vbox_vmname[128];
extern "C" void init_libc_vbox_logger(void);
/** /**
* xpcom style memory allocation * xpcom style memory allocation
@ -239,6 +240,9 @@ int main(int argc, char **argv)
throw; throw;
} }
/* enable stdout/stderr for VBox Log infrastructure */
init_libc_vbox_logger();
int rc = RTR3InitExe(argc, &argv, 0); int rc = RTR3InitExe(argc, &argv, 0);
if (RT_FAILURE(rc)) if (RT_FAILURE(rc))
return -1; return -1;