genode/repos/os/src/server/part_blk/main.cc

105 lines
2.4 KiB
C++
Raw Normal View History

2011-12-22 16:19:25 +01:00
/*
* \brief Front end of the partition server
* \author Sebastian Sumpf
* \author Stefan Kalkowski
* \author Josef Soentgen
2011-12-22 16:19:25 +01:00
* \date 2011-05-30
*/
/*
* Copyright (C) 2011-2017 Genode Labs GmbH
2011-12-22 16:19:25 +01:00
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU Affero General Public License version 3.
2011-12-22 16:19:25 +01:00
*/
#include <base/attached_rom_dataspace.h>
2011-12-22 16:19:25 +01:00
#include <block_session/rpc_object.h>
#include "component.h"
#include "driver.h"
#include "gpt.h"
#include "mbr.h"
2011-12-22 16:19:25 +01:00
void Block::Driver::_ready_to_submit() {
Block::Session_component::wake_up(); }
class Main
{
private:
2011-12-22 16:19:25 +01:00
Block::Partition_table & _table();
2011-12-22 16:19:25 +01:00
2017-05-23 11:22:42 +02:00
Genode::Env &_env;
Genode::Attached_rom_dataspace _config { _env, "config" };
Genode::Heap _heap { _env.ram(), _env.rm() };
Block::Driver _driver { _env, _heap };
Genode::Reporter _reporter { _env, "partitions" };
Mbr_partition_table _mbr { _heap, _driver, _reporter };
Gpt _gpt { _heap, _driver, _reporter };
2017-05-23 11:22:42 +02:00
Block::Root _root { _env, _config.xml(), _heap, _driver, _table() };
2011-12-22 16:19:25 +01:00
public:
2011-12-22 16:19:25 +01:00
class No_partion_table : Genode::Exception {};
Main(Genode::Env &env) : _env(env)
{
/*
* we read all partition information,
* now it's safe to turn in asynchronous mode
*/
_driver.work_asynchronously();
/* announce at parent */
env.parent().announce(env.ep().manage(_root));
}
};
2011-12-22 16:19:25 +01:00
Block::Partition_table & Main::_table()
{
bool valid_mbr = false;
bool valid_gpt = false;
bool use_gpt = false;
bool report = false;
try {
2017-05-23 11:22:42 +02:00
use_gpt = _config.xml().attribute_value("use_gpt", false);
} catch(...) {}
try {
2017-05-23 11:22:42 +02:00
report = _config.xml().sub_node("report").attribute_value
("partitions", false);
if (report)
_reporter.enabled(true);
} catch(...) {}
if (use_gpt)
try { valid_gpt = _gpt.parse(); } catch (...) { }
/* fall back to MBR */
if (!valid_gpt) {
try { valid_mbr = _mbr.parse(); }
catch (Mbr_partition_table::Protective_mbr_found) {
if (!use_gpt)
Genode::error("Aborting: found protective MBR but ",
"GPT usage was not requested.");
throw;
}
2011-12-22 16:19:25 +01:00
}
if (valid_gpt) return _gpt;
if (valid_mbr) return _mbr;
Genode::error("Aborting: no partition table found.");
throw No_partion_table();
}
2011-12-22 16:19:25 +01:00
void Component::construct(Genode::Env &env) { static Main main(env); }