From 84f8305cdf9b1725cf2eebfc26be822f76cdc1bd Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Wed, 26 Jan 2022 17:10:31 +0100 Subject: [PATCH] usb_report_filter: use VFS instead of fs session This patch replaces the direct use of a file-system session via the 'file_system/util.h' helpers by the VFS using the os/vfs.h API. This makes the component more flexible while removing the dependence from read and write utilities of file_system/util.h, which happen to rely on the (now removed) blocking packet-stream semantics. Issue #4390 --- repos/os/src/app/usb_report_filter/README | 1 + repos/os/src/app/usb_report_filter/main.cc | 84 ++++++++++---------- repos/os/src/app/usb_report_filter/target.mk | 2 +- repos/ports/run/vbox5_genode_usb_hid_raw.run | 2 + repos/ports/run/virtualbox_auto.inc | 2 + 5 files changed, 49 insertions(+), 42 deletions(-) diff --git a/repos/os/src/app/usb_report_filter/README b/repos/os/src/app/usb_report_filter/README index df3bd3ce91..5807f6336a 100644 --- a/repos/os/src/app/usb_report_filter/README +++ b/repos/os/src/app/usb_report_filter/README @@ -10,6 +10,7 @@ Configuration A typical example configuration looks as follows: ! +! ! ! ! diff --git a/repos/os/src/app/usb_report_filter/main.cc b/repos/os/src/app/usb_report_filter/main.cc index 1ac9787a4b..0b3c4cf502 100644 --- a/repos/os/src/app/usb_report_filter/main.cc +++ b/repos/os/src/app/usb_report_filter/main.cc @@ -17,12 +17,11 @@ #include #include #include +#include #include #include #include #include -#include -#include namespace Usb_filter { @@ -50,15 +49,13 @@ class Usb_filter::Device_registry Genode::Env &_env; Genode::Allocator &_alloc; + Genode::Directory &_root_dir; Genode::Reporter _reporter { _env, "usb_devices" }; Attached_rom_dataspace _devices_rom { _env, "devices" }; Attached_rom_dataspace _usb_drv_config_rom { _env, "usb_drv_config" }; - Genode::Allocator_avl _fs_packet_alloc { &_alloc }; - File_system::Connection _fs { _env, _fs_packet_alloc, "usb_drv.config" }; - struct Entry : public Genode::List::Element { unsigned bus; @@ -149,36 +146,17 @@ class Usb_filter::Device_registry }); } - void _write_usb_drv_config(Xml_node & usb_devices) + void _write_usb_drv_config(Xml_node const &drv_config, + Xml_node const &usb_devices) { using namespace Genode; - Constructible file; + bool const uhci_enabled = drv_config.attribute_value("uhci", false); + bool const ehci_enabled = drv_config.attribute_value("ehci", false); + bool const xhci_enabled = drv_config.attribute_value("xhci", false); - try { - File_system::Dir_handle root_dir = _fs.dir("/", false); - file.construct(_fs.file(root_dir, config_file, File_system::READ_WRITE, false)); - } catch (...) { - error("could not open '", config_file, "'"); - return; - } - - char old_file[1024]; - size_t n = File_system::read(_fs, *file, old_file, - sizeof(old_file)); - if (n == 0) { - error("could not read '", config_file, "'"); - return; - } - - Xml_node drv_config(old_file, n); - - bool const uhci_enabled = drv_config.attribute_value("uhci", false); - bool const ehci_enabled = drv_config.attribute_value("ehci", false); - bool const xhci_enabled = drv_config.attribute_value("xhci", false); - - char new_file[1024]; - Genode::Xml_generator xml(new_file, sizeof(new_file), "config", [&] { + char new_content[1024]; + Xml_generator xml(new_content, sizeof(new_content), "config", [&] { if (uhci_enabled) xml.attribute("uhci", "yes"); if (ehci_enabled) xml.attribute("ehci", "yes"); if (xhci_enabled) xml.attribute("xhci", "yes"); @@ -214,18 +192,38 @@ class Usb_filter::Device_registry }); }); - new_file[xml.used()] = 0; + new_content[xml.used()] = 0; if (verbose) - log("new usb_drv configuration:\n", Cstring(new_file)); + log("new usb_drv configuration:\n", Cstring(new_content)); - n = File_system::write(_fs, *file, new_file, xml.used()); - if (n == 0) + try { + New_file new_file(_root_dir, config_file); + new_file.append(new_content, xml.used()); + } + catch (...) { error("could not write '", config_file, "'"); - - _fs.close(*file); + } } - Genode::Signal_handler _devices_handler = + void _write_usb_drv_config(Xml_node const &usb_devices) + { + using namespace Genode; + + try { + File_content::Limit limit { 64*1024 }; + File_content old_file { _alloc, _root_dir, config_file, + limit }; + + old_file.xml([&] (Xml_node const &old_drv_config) { + _write_usb_drv_config(old_drv_config, usb_devices); }); + + } catch (...) { + error("could not access '", config_file, "'"); + return; + } + } + + Genode::Signal_handler _devices_handler { _env.ep(), *this, &Device_registry::_handle_devices }; void _handle_devices() @@ -361,8 +359,10 @@ class Usb_filter::Device_registry /** * Constructor */ - Device_registry(Genode::Env &env, Genode::Allocator &alloc) - : _env(env), _alloc(alloc) + Device_registry(Genode::Env &env, Genode::Allocator &alloc, + Genode::Directory &root_dir) + : + _env(env), _alloc(alloc), _root_dir(root_dir) { _reporter.enabled(true); @@ -418,6 +418,8 @@ struct Usb_filter::Main Genode::Attached_rom_dataspace _config { _env, "config" }; + Genode::Root_directory _root_dir { _env, _heap, _config.xml().sub_node("vfs") }; + Genode::Signal_handler
_config_handler = { _env.ep(), *this, &Main::_handle_config }; @@ -427,7 +429,7 @@ struct Usb_filter::Main device_registry.update_entries(_config.xml()); } - Device_registry device_registry { _env, _heap }; + Device_registry device_registry { _env, _heap, _root_dir }; Main(Genode::Env &env) : _env(env) { diff --git a/repos/os/src/app/usb_report_filter/target.mk b/repos/os/src/app/usb_report_filter/target.mk index 1d63629c48..19043ea83c 100644 --- a/repos/os/src/app/usb_report_filter/target.mk +++ b/repos/os/src/app/usb_report_filter/target.mk @@ -1,3 +1,3 @@ TARGET = usb_report_filter SRC_CC = main.cc -LIBS = base +LIBS = base vfs diff --git a/repos/ports/run/vbox5_genode_usb_hid_raw.run b/repos/ports/run/vbox5_genode_usb_hid_raw.run index 66736ff5c9..c61d96d25e 100644 --- a/repos/ports/run/vbox5_genode_usb_hid_raw.run +++ b/repos/ports/run/vbox5_genode_usb_hid_raw.run @@ -90,6 +90,8 @@ append config { + + diff --git a/repos/ports/run/virtualbox_auto.inc b/repos/ports/run/virtualbox_auto.inc index f4882f09b5..806829c20f 100644 --- a/repos/ports/run/virtualbox_auto.inc +++ b/repos/ports/run/virtualbox_auto.inc @@ -287,6 +287,8 @@ append_if [expr $use_usb] config { + +