rom_to_file: use VFS instead of fs session

This patch replaces the former direct use of a file-system session by
the use of the VFS API.

Issue #4390
This commit is contained in:
Norman Feske 2022-01-26 17:32:34 +01:00
parent 84f8305cdf
commit 0f56e76e7a
9 changed files with 53 additions and 92 deletions

View File

@ -93,7 +93,9 @@ append config {
</start> </start>
<start name="rom_to_file"> <start name="rom_to_file">
<resource name="RAM" quantum="2M"/> <resource name="RAM" quantum="2M"/>
<config rom="dynamic_rom"/> <config rom="dynamic_rom">
<vfs> <fs/> </vfs>
</config>
<route> <route>
<service name="ROM" label="dynamic_rom"> <child name="dynamic_rom"/> </service> <service name="ROM" label="dynamic_rom"> <child name="dynamic_rom"/> </service>
<service name="File_system" > <child name="vfs"/> </service> <service name="File_system" > <child name="vfs"/> </service>

View File

@ -69,7 +69,9 @@
</start> </start>
<start name="rom_to_file"> <start name="rom_to_file">
<resource name="RAM" quantum="2M"/> <resource name="RAM" quantum="2M"/>
<config rom="dynamic_rom"/> <config rom="dynamic_rom">
<vfs> <fs/> </vfs>
</config>
<route> <route>
<service name="ROM" label="dynamic_rom"> <child name="dynamic_rom"/> </service> <service name="ROM" label="dynamic_rom"> <child name="dynamic_rom"/> </service>
<any-service> <parent/> <any-child/> </any-service> <any-service> <parent/> <any-child/> </any-service>

View File

@ -4,7 +4,7 @@
<events> <events>
<timeout meaning="failed" sec="20" /> <timeout meaning="failed" sec="20" />
<log meaning="succeeded">&lt;config iteration="4" /></log> <log meaning="succeeded">&lt;config iteration="4"/></log>
</events> </events>
<content> <content>
@ -63,27 +63,29 @@
<config verbose="yes"> <config verbose="yes">
<rom name="dynamic_rom"> <rom name="dynamic_rom">
<inline description="iteration 1"> <inline description="iteration 1">
<config iteration="1" /> <config iteration="1"/>
</inline> </inline>
<sleep milliseconds="2000" /> <sleep milliseconds="2000"/>
<inline description="iteration 2"> <inline description="iteration 2">
<config iteration="2" /> <config iteration="2"/>
</inline> </inline>
<sleep milliseconds="2000" /> <sleep milliseconds="2000"/>
<inline description="iteration 3"> <inline description="iteration 3">
<config iteration="3" /> <config iteration="3"/>
</inline> </inline>
<sleep milliseconds="2000" /> <sleep milliseconds="2000"/>
<inline description="iteration 4"> <inline description="iteration 4">
<config iteration="4" /> <config iteration="4"/>
</inline> </inline>
<sleep milliseconds="2000" /> <sleep milliseconds="2000"/>
</rom> </rom>
</config> </config>
</start> </start>
<start name="rom_to_file"> <start name="rom_to_file">
<resource name="RAM" quantum="2M"/> <resource name="RAM" quantum="2M"/>
<config rom="dynamic_rom"/> <config rom="dynamic_rom">
<vfs> <fs/> </vfs>
</config>
<route> <route>
<service name="ROM" label="dynamic_rom"> <child name="dynamic_rom"/> </service> <service name="ROM" label="dynamic_rom"> <child name="dynamic_rom"/> </service>
<service name="File_system" > <child name="vfs_1"/> </service> <service name="File_system" > <child name="vfs_1"/> </service>

View File

@ -4,7 +4,7 @@
<events> <events>
<timeout meaning="failed" sec="35" /> <timeout meaning="failed" sec="35" />
<log meaning="succeeded">&lt;config iteration="4" /></log> <log meaning="succeeded">&lt;config iteration="4"/></log>
</events> </events>
<content> <content>
@ -48,27 +48,29 @@
<config verbose="yes"> <config verbose="yes">
<rom name="dynamic_rom"> <rom name="dynamic_rom">
<inline description="iteration 1"> <inline description="iteration 1">
<config iteration="1" /> <config iteration="1"/>
</inline> </inline>
<sleep milliseconds="2000" /> <sleep milliseconds="2000"/>
<inline description="iteration 2"> <inline description="iteration 2">
<config iteration="2" /> <config iteration="2"/>
</inline> </inline>
<sleep milliseconds="2000" /> <sleep milliseconds="2000"/>
<inline description="iteration 3"> <inline description="iteration 3">
<config iteration="3" /> <config iteration="3"/>
</inline> </inline>
<sleep milliseconds="2000" /> <sleep milliseconds="2000"/>
<inline description="iteration 4"> <inline description="iteration 4">
<config iteration="4" /> <config iteration="4"/>
</inline> </inline>
<sleep milliseconds="2000" /> <sleep milliseconds="2000"/>
</rom> </rom>
</config> </config>
</start> </start>
<start name="rom_to_file"> <start name="rom_to_file">
<resource name="RAM" quantum="2M"/> <resource name="RAM" quantum="2M"/>
<config rom="dynamic_rom"/> <config rom="dynamic_rom">
<vfs> <fs/> </vfs>
</config>
<route> <route>
<service name="ROM" label="dynamic_rom"> <child name="dynamic_rom"/> </service> <service name="ROM" label="dynamic_rom"> <child name="dynamic_rom"/> </service>
<service name="File_system" > <child name="vfs"/> </service> <service name="File_system" > <child name="vfs"/> </service>

View File

@ -1,4 +1,3 @@
base base
os os
file_system vfs
file_system_session

View File

@ -28,6 +28,7 @@ install_config {
<default-route> <default-route>
<any-service> <parent/> <any-child/> </any-service> <any-service> <parent/> <any-child/> </any-service>
</default-route> </default-route>
<default caps="100"/>
<start name="timer"> <start name="timer">
<resource name="RAM" quantum="1M"/> <resource name="RAM" quantum="1M"/>
<provides><service name="Timer"/></provides> <provides><service name="Timer"/></provides>
@ -53,7 +54,9 @@ install_config {
</start> </start>
<start name="rom_to_file"> <start name="rom_to_file">
<resource name="RAM" quantum="4M"/> <resource name="RAM" quantum="4M"/>
<config rom="test" /> <config rom="test">
<vfs> <fs/> </vfs>
</config>
<route> <route>
<service name="ROM" label="test"> <child name="dynamic_rom"/> </service> <service name="ROM" label="test"> <child name="dynamic_rom"/> </service>
<service name="File_system"> <child name="lx_fs"/> </service> <service name="File_system"> <child name="lx_fs"/> </service>
@ -73,6 +76,7 @@ build_boot_image { core ld.lib.so init timer
rom_to_file rom_to_file
lx_fs lx_fs
fs_test fs_test
vfs.lib.so
} }
append qemu_args " -nographic " append qemu_args " -nographic "

View File

@ -5,6 +5,8 @@ updates.
The name of the ROM module must be specified via the 'rom' attribute of the The name of the ROM module must be specified via the 'rom' attribute of the
components '<config>' node components '<config>' node
! <config rom="pointer"/> ! <config rom="pointer">
! <vfs> <fs/> </vfs>
! </config>
See run/rom_to_file.run for an example. See run/rom_to_file.run for an example.

View File

@ -14,17 +14,9 @@
/* Genode includes */ /* Genode includes */
#include <base/component.h> #include <base/component.h>
#include <base/heap.h> #include <base/heap.h>
#include <rom_session/connection.h>
#include <base/signal.h>
#include <base/attached_rom_dataspace.h> #include <base/attached_rom_dataspace.h>
#include <util/print_lines.h>
#include <util/reconstructible.h>
#include <base/heap.h> #include <base/heap.h>
#include <base/allocator_avl.h> #include <os/vfs.h>
#include <file_system_session/connection.h>
#include <file_system/util.h>
namespace Rom_to_file { namespace Rom_to_file {
@ -32,29 +24,21 @@ namespace Rom_to_file {
using namespace Genode; using namespace Genode;
struct Main; struct Main;
enum {
BLOCK_SIZE = 512,
QUEUE_SIZE = File_system::Session::TX_QUEUE_SIZE,
TX_BUF_SIZE = BLOCK_SIZE * (QUEUE_SIZE*2 + 1)
};
} }
struct Rom_to_file::Main struct Rom_to_file::Main
{ {
Genode::Env &_env; Env &_env;
Genode::Heap _heap { _env.ram(), _env.rm() }; Heap _heap { _env.ram(), _env.rm() };
Genode::Attached_rom_dataspace _config_rom { _env, "config" }; Attached_rom_dataspace _config_rom { _env, "config" };
Allocator_avl _alloc { &_heap }; Root_directory _root_dir { _env, _heap, _config_rom.xml().sub_node("vfs") };
File_system::Connection _fs { _env, _alloc, "", "/", true, TX_BUF_SIZE };
Constructible<Attached_rom_dataspace> _rom_ds { }; Constructible<Attached_rom_dataspace> _rom_ds { };
typedef Genode::String<100> Rom_name; typedef String<100> Rom_name;
/** /**
* Name of currently requested ROM module * Name of currently requested ROM module
@ -72,7 +56,7 @@ struct Rom_to_file::Main
Signal_handler<Main> _update_dispatcher { Signal_handler<Main> _update_dispatcher {
_env.ep(), *this, &Main::_handle_update }; _env.ep(), *this, &Main::_handle_update };
Main(Genode::Env &env) : _env(env) Main(Env &env) : _env(env)
{ {
_config_rom.sigh(_update_dispatcher); _config_rom.sigh(_update_dispatcher);
_handle_update(); _handle_update();
@ -84,7 +68,7 @@ void Rom_to_file::Main::_handle_update()
{ {
_config_rom.update(); _config_rom.update();
Genode::Xml_node config = _config_rom.xml(); Xml_node config = _config_rom.xml();
/* /*
* Query name of ROM module from config * Query name of ROM module from config
@ -114,53 +98,17 @@ void Rom_to_file::Main::_handle_update()
_rom_ds->update(); _rom_ds->update();
if (_rom_ds->valid()) { if (_rom_ds->valid()) {
using namespace File_system;
char dir_path[] = "/";
const char *file_name = _rom_name.string();
try { try {
Dir_handle dir_handle = ensure_dir(_fs, dir_path); New_file new_file { _root_dir, _rom_name };
Handle_guard dir_guard(_fs, dir_handle);
Constructible<File_handle> handle;
try { size_t const len = max(strlen(_rom_ds->local_addr<char>()),
handle.construct(_fs.file(dir_handle, file_name, File_system::WRITE_ONLY, true)); _rom_ds->size());
} catch (Node_already_exists) {
handle.construct(_fs.file(dir_handle, file_name, File_system::WRITE_ONLY, false));
}
_fs.truncate(*handle, 0); new_file.append(_rom_ds->local_addr<char>(), len);
size_t len = max(strlen(_rom_ds->local_addr<char>()), _rom_ds->size());
size_t written = write(_fs, *handle, _rom_ds->local_addr<void>(), len, 0);
if (written < len) {
warning(written, " of ", len, " bytes have been written");
}
_fs.close(*handle);
} catch (Permission_denied) {
error(Cstring(dir_path), file_name, ": permission denied");
} catch (No_space) {
error("file system out of space");
} catch (Out_of_ram) {
error("server ran out of RAM");
} catch (Out_of_caps) {
error("server ran out of caps");
} catch (Invalid_name) {
error(Cstring(dir_path), file_name, ": invalid path");
} catch (Name_too_long) {
error(Cstring(dir_path), file_name, ": name too long");
} catch (...) { } catch (...) {
error("cannot open file ", Cstring(dir_path), file_name); error("cannot create file ", _rom_name);
throw; throw;
} }
} else { } else {

View File

@ -1,3 +1,3 @@
TARGET = rom_to_file TARGET = rom_to_file
SRC_CC = main.cc SRC_CC = main.cc
LIBS = base LIBS = base vfs