From cf904e0a5d92fe7c5b467454d7b49870f615ad92 Mon Sep 17 00:00:00 2001 From: Johannes Schlatow Date: Mon, 2 Aug 2021 17:17:28 +0200 Subject: [PATCH] vfs: add append mode to New_file genodelabs/genode#4352 --- repos/os/include/os/vfs.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/repos/os/include/os/vfs.h b/repos/os/include/os/vfs.h index 66cf242681..0fe34ee528 100644 --- a/repos/os/include/os/vfs.h +++ b/repos/os/include/os/vfs.h @@ -683,7 +683,9 @@ class Genode::New_file : Noncopyable Vfs::File_system &_fs; Vfs::Vfs_handle &_handle; - Vfs::Vfs_handle &_init_handle(Directory &dir, Directory::Path const &rel_path) + Vfs::Vfs_handle &_init_handle(Directory &dir, + Directory::Path const &rel_path, + bool append) { /* create compound directory */ { @@ -708,7 +710,11 @@ class Genode::New_file : Noncopyable throw Create_failed(); } - handle_ptr->fs().ftruncate(handle_ptr, 0); + Vfs::Directory_service::Stat stat { }; + if (!append) + handle_ptr->fs().ftruncate(handle_ptr, 0); + else if (handle_ptr->ds().stat(path.string(), stat) == Vfs::Directory_service::STAT_OK) + handle_ptr->seek(stat.size); return *handle_ptr; } @@ -720,10 +726,10 @@ class Genode::New_file : Noncopyable * * \throw Create_failed */ - New_file(Directory &dir, Directory::Path const &path) + New_file(Directory &dir, Directory::Path const &path, bool append = false) : _ep(dir._ep), _alloc(dir._alloc), _fs(dir._fs), - _handle(_init_handle(dir, path)) + _handle(_init_handle(dir, path, append)) { } ~New_file()