2011-12-22 16:19:25 +01:00
|
|
|
/*
|
|
|
|
* \brief Front end of the partition server
|
|
|
|
* \author Sebastian Sumpf
|
2013-12-05 15:02:44 +01:00
|
|
|
* \author Stefan Kalkowski
|
2014-09-20 22:12:26 +02:00
|
|
|
* \author Josef Soentgen
|
2011-12-22 16:19:25 +01:00
|
|
|
* \date 2011-05-30
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-01-13 20:04:17 +01:00
|
|
|
* 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
|
2017-02-20 13:23:52 +01:00
|
|
|
* under the terms of the GNU Affero General Public License version 3.
|
2011-12-22 16:19:25 +01:00
|
|
|
*/
|
|
|
|
|
2017-01-30 11:35:12 +01:00
|
|
|
#include <base/attached_rom_dataspace.h>
|
2011-12-22 16:19:25 +01:00
|
|
|
#include <block_session/rpc_object.h>
|
|
|
|
|
2013-12-05 15:02:44 +01:00
|
|
|
#include "component.h"
|
2014-09-20 22:12:26 +02:00
|
|
|
#include "driver.h"
|
|
|
|
#include "gpt.h"
|
|
|
|
#include "mbr.h"
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
|
2016-08-03 10:35:32 +02:00
|
|
|
void Block::Driver::_ready_to_submit() {
|
|
|
|
Block::Session_component::wake_up(); }
|
|
|
|
|
|
|
|
|
|
|
|
class Main
|
2013-12-05 15:02:44 +01:00
|
|
|
{
|
2016-08-03 10:35:32 +02:00
|
|
|
private:
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2016-08-03 10:35:32 +02: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" };
|
|
|
|
|
2017-05-18 11:12:11 +02:00
|
|
|
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
|
|
|
|
2016-08-03 10:35:32 +02:00
|
|
|
public:
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2016-08-03 10:35:32 +02:00
|
|
|
class No_partion_table : Genode::Exception {};
|
2014-09-20 22:12:26 +02:00
|
|
|
|
2016-08-03 10:35:32 +02:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
};
|
2014-09-20 22:12:26 +02:00
|
|
|
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2016-08-03 10:35:32 +02:00
|
|
|
Block::Partition_table & Main::_table()
|
|
|
|
{
|
2014-09-20 22:12:26 +02:00
|
|
|
bool valid_mbr = false;
|
|
|
|
bool valid_gpt = false;
|
2016-08-03 10:35:32 +02:00
|
|
|
bool use_gpt = false;
|
2017-05-18 11:12:11 +02:00
|
|
|
bool report = false;
|
|
|
|
|
2016-08-03 10:35:32 +02:00
|
|
|
try {
|
2017-05-23 11:22:42 +02:00
|
|
|
use_gpt = _config.xml().attribute_value("use_gpt", false);
|
2016-08-03 10:35:32 +02:00
|
|
|
} catch(...) {}
|
2014-09-20 22:12:26 +02:00
|
|
|
|
2017-05-18 11:12:11 +02:00
|
|
|
try {
|
2017-05-23 11:22:42 +02:00
|
|
|
report = _config.xml().sub_node("report").attribute_value
|
2017-05-18 11:12:11 +02:00
|
|
|
("partitions", false);
|
|
|
|
if (report)
|
|
|
|
_reporter.enabled(true);
|
|
|
|
} catch(...) {}
|
|
|
|
|
2014-09-20 22:12:26 +02:00
|
|
|
if (use_gpt)
|
2016-08-03 10:35:32 +02:00
|
|
|
try { valid_gpt = _gpt.parse(); } catch (...) { }
|
2014-09-20 22:12:26 +02:00
|
|
|
|
|
|
|
/* fall back to MBR */
|
|
|
|
if (!valid_gpt) {
|
2016-08-03 10:35:32 +02:00
|
|
|
try { valid_mbr = _mbr.parse(); }
|
2014-09-20 22:12:26 +02:00
|
|
|
catch (Mbr_partition_table::Protective_mbr_found) {
|
|
|
|
if (!use_gpt)
|
2016-08-03 10:35:32 +02:00
|
|
|
Genode::error("Aborting: found protective MBR but ",
|
|
|
|
"GPT usage was not requested.");
|
|
|
|
throw;
|
2014-09-20 22:12:26 +02:00
|
|
|
}
|
2011-12-22 16:19:25 +01:00
|
|
|
}
|
|
|
|
|
2016-08-03 10:35:32 +02:00
|
|
|
if (valid_gpt) return _gpt;
|
|
|
|
if (valid_mbr) return _mbr;
|
2014-09-20 22:12:26 +02:00
|
|
|
|
2016-08-03 10:35:32 +02:00
|
|
|
Genode::error("Aborting: no partition table found.");
|
|
|
|
throw No_partion_table();
|
|
|
|
}
|
2015-06-16 13:03:01 +02:00
|
|
|
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2016-11-28 15:13:14 +01:00
|
|
|
void Component::construct(Genode::Env &env) { static Main main(env); }
|