From 75917f6595c16f89bf5a2c2812bd8a1217a14a41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josef=20S=C3=B6ntgen?= Date: Mon, 24 Apr 2023 17:27:47 +0200 Subject: [PATCH] file_vault: use VFS to sync data file Issue #4820. --- repos/gems/src/app/file_vault/sandbox.h | 2 +- .../file_vault/sync_to_cbe_vfs_init/main.cc | 55 +++++++++++-------- .../file_vault/sync_to_cbe_vfs_init/target.mk | 2 +- 3 files changed, 35 insertions(+), 24 deletions(-) diff --git a/repos/gems/src/app/file_vault/sandbox.h b/repos/gems/src/app/file_vault/sandbox.h index cc579cb049..0d6b89ef2c 100644 --- a/repos/gems/src/app/file_vault/sandbox.h +++ b/repos/gems/src/app/file_vault/sandbox.h @@ -364,7 +364,7 @@ namespace File_vault { xml.node("policy", [&] () { xml.attribute("label", "sync_to_cbe_vfs_init -> "); xml.attribute("root", "/dev"); - xml.attribute("writeable", "no"); + xml.attribute("writeable", "yes"); }); }); xml.node("route", [&] () { diff --git a/repos/gems/src/app/file_vault/sync_to_cbe_vfs_init/main.cc b/repos/gems/src/app/file_vault/sync_to_cbe_vfs_init/main.cc index a0e6a001e1..0056a7726c 100644 --- a/repos/gems/src/app/file_vault/sync_to_cbe_vfs_init/main.cc +++ b/repos/gems/src/app/file_vault/sync_to_cbe_vfs_init/main.cc @@ -11,29 +11,40 @@ * under the terms of the GNU Affero General Public License version 3. */ -/* libC includes */ -extern "C" { -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#include -#include -#include -#include -#pragma GCC diagnostic pop /* restore -Wconversion warnings */ -} -int main(int, char **) +/* Genode includes */ +#include +#include +#include +#include + +using namespace Genode; + +struct Main : private Vfs::Env::User { - char const *file_path { "/cbe/cbe/current/data" }; - int const file_descriptor = open(file_path, O_RDONLY); - if (file_descriptor < 0) { - printf("Error: failed to open file %s\n", file_path); - exit(-1); + Env &_env; + Heap _heap { _env.ram(), _env.rm() }; + Attached_rom_dataspace _config_rom { _env, "config" }; + + Vfs::Simple_env _vfs_env { _env, _heap, + _config_rom.xml().sub_node("vfs"), *this }; + + Directory _root_dir { _vfs_env }; + + void wakeup_vfs_user() override { } + + Main(Env &env) : _env { env } + { + { + Append_file { _root_dir, + Directory::Path("/cbe/cbe/current/data") }; + } + _env.parent().exit(0); } - int const result { fsync(file_descriptor) }; - if (result != 0) { - printf("Error: fsync on file %s failed\n", file_path); - exit(-1); - } - exit(0); +}; + + +void Component::construct(Env &env) +{ + static Main main(env); } diff --git a/repos/gems/src/app/file_vault/sync_to_cbe_vfs_init/target.mk b/repos/gems/src/app/file_vault/sync_to_cbe_vfs_init/target.mk index e8d84b44b4..9dd672f548 100644 --- a/repos/gems/src/app/file_vault/sync_to_cbe_vfs_init/target.mk +++ b/repos/gems/src/app/file_vault/sync_to_cbe_vfs_init/target.mk @@ -1,3 +1,3 @@ TARGET = file_vault-sync_to_cbe_vfs_init -LIBS = posix +LIBS = base vfs SRC_CC = main.cc