2014-01-23 06:16:03 +05:30
|
|
|
#include <fstream>
|
|
|
|
#include <getopt.h>
|
|
|
|
#include <libgen.h>
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#include "version.h"
|
2014-08-27 18:31:31 +05:30
|
|
|
#include "era/commands.h"
|
2014-01-23 06:16:03 +05:30
|
|
|
#include "era/era_array.h"
|
2014-01-30 03:07:25 +05:30
|
|
|
#include "era/writeset_tree.h"
|
2014-01-23 06:16:03 +05:30
|
|
|
#include "era/metadata.h"
|
|
|
|
#include "era/metadata_dump.h"
|
|
|
|
#include "era/xml_format.h"
|
|
|
|
#include "persistent-data/file_utils.h"
|
|
|
|
|
|
|
|
using namespace era;
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
//----------------------------------------------------------------
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
struct flags {
|
|
|
|
flags()
|
2014-02-14 20:05:25 +05:30
|
|
|
: repair_(false),
|
|
|
|
logical_(false) {
|
2014-01-23 06:16:03 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
bool repair_;
|
2014-02-14 20:05:25 +05:30
|
|
|
bool logical_;
|
2014-01-23 06:16:03 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
//--------------------------------
|
|
|
|
|
|
|
|
string const STDOUT_PATH("-");
|
|
|
|
|
|
|
|
bool want_stdout(string const &output) {
|
|
|
|
return output == STDOUT_PATH;
|
|
|
|
}
|
|
|
|
|
|
|
|
int dump(string const &dev, string const &output, flags const &fs) {
|
|
|
|
try {
|
2014-07-22 21:11:39 +05:30
|
|
|
block_manager<>::ptr bm = open_bm(dev, block_manager<>::READ_ONLY);
|
2014-01-23 06:16:03 +05:30
|
|
|
metadata::ptr md(new metadata(bm, metadata::OPEN));
|
|
|
|
|
|
|
|
if (want_stdout(output)) {
|
|
|
|
emitter::ptr e = create_xml_emitter(cout);
|
2014-02-14 20:05:25 +05:30
|
|
|
metadata_dump(md, e, fs.repair_, fs.logical_);
|
2014-01-23 06:16:03 +05:30
|
|
|
} else {
|
|
|
|
ofstream out(output.c_str());
|
|
|
|
emitter::ptr e = create_xml_emitter(out);
|
2014-02-14 20:05:25 +05:30
|
|
|
metadata_dump(md, e, fs.repair_, fs.logical_);
|
2014-01-23 06:16:03 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
} catch (std::exception &e) {
|
|
|
|
cerr << e.what() << endl;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void usage(ostream &out, string const &cmd) {
|
|
|
|
out << "Usage: " << cmd << " [options] {device|file}" << endl
|
|
|
|
<< "Options:" << endl
|
|
|
|
<< " {-h|--help}" << endl
|
|
|
|
<< " {-o <xml file>}" << endl
|
|
|
|
<< " {-V|--version}" << endl
|
2014-02-14 20:05:25 +05:30
|
|
|
<< " {--repair}" << endl
|
|
|
|
<< " {--logical}" << endl;
|
2014-01-23 06:16:03 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------
|
|
|
|
|
2014-08-27 18:31:31 +05:30
|
|
|
int era_dump_main(int argc, char **argv)
|
2014-01-23 06:16:03 +05:30
|
|
|
{
|
|
|
|
int c;
|
|
|
|
flags fs;
|
|
|
|
string output("-");
|
|
|
|
char const shortopts[] = "ho:V";
|
|
|
|
|
|
|
|
option const longopts[] = {
|
|
|
|
{ "help", no_argument, NULL, 'h' },
|
|
|
|
{ "output", required_argument, NULL, 'o' },
|
|
|
|
{ "version", no_argument, NULL, 'V' },
|
|
|
|
{ "repair", no_argument, NULL, 1 },
|
2014-02-14 20:05:25 +05:30
|
|
|
{ "logical", no_argument, NULL, 2 },
|
2014-01-23 06:16:03 +05:30
|
|
|
{ NULL, no_argument, NULL, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) {
|
|
|
|
switch(c) {
|
|
|
|
case 1:
|
|
|
|
fs.repair_ = true;
|
|
|
|
break;
|
|
|
|
|
2014-02-14 20:05:25 +05:30
|
|
|
case 2:
|
|
|
|
fs.logical_ = true;
|
|
|
|
break;
|
|
|
|
|
2014-01-23 06:16:03 +05:30
|
|
|
case 'h':
|
|
|
|
usage(cout, basename(argv[0]));
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case 'o':
|
|
|
|
output = optarg;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'V':
|
|
|
|
cout << THIN_PROVISIONING_TOOLS_VERSION << endl;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
default:
|
|
|
|
usage(cerr, basename(argv[0]));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc == optind) {
|
|
|
|
cerr << "No input file provided." << endl;
|
|
|
|
usage(cerr, basename(argv[0]));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return dump(argv[optind], output, fs);
|
|
|
|
}
|
|
|
|
|
2014-08-27 18:31:31 +05:30
|
|
|
base::command era::era_dump_cmd("era_dump", era_dump_main);
|
|
|
|
|
2014-01-23 06:16:03 +05:30
|
|
|
//----------------------------------------------------------------
|