file_vault: use VFS to sync data file

Issue #4820.
This commit is contained in:
Josef Söntgen 2023-04-24 17:27:47 +02:00 committed by Christian Helmuth
parent 67c1ca1e61
commit 75917f6595
3 changed files with 35 additions and 24 deletions

View File

@ -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", [&] () {

View File

@ -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 <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#pragma GCC diagnostic pop /* restore -Wconversion warnings */
}
int main(int, char **)
/* Genode includes */
#include <base/attached_rom_dataspace.h>
#include <base/component.h>
#include <base/heap.h>
#include <os/vfs.h>
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);
}

View File

@ -1,3 +1,3 @@
TARGET = file_vault-sync_to_cbe_vfs_init
LIBS = posix
LIBS = base vfs
SRC_CC = main.cc