[cache_dump] add --repair flag (not functional yet)

This commit is contained in:
Joe Thornber 2013-10-08 11:54:22 +01:00
parent 505cf95109
commit 2ecf051336

View File

@ -17,6 +17,14 @@ using namespace caching::superblock_damage;
//---------------------------------------------------------------- //----------------------------------------------------------------
namespace { namespace {
struct flags {
flags()
: repair_(false) {
}
bool repair_;
};
string to_string(unsigned char const *data) { string to_string(unsigned char const *data) {
// FIXME: we're assuming the data is zero terminated here // FIXME: we're assuming the data is zero terminated here
return std::string(reinterpret_cast<char const *>(data)); return std::string(reinterpret_cast<char const *>(data));
@ -30,7 +38,7 @@ namespace {
return output == STDOUT_PATH; return output == STDOUT_PATH;
} }
int dump_(string const &dev, ostream &out) { int dump_(string const &dev, ostream &out, flags const &fs) {
block_manager<>::ptr bm = open_bm(dev, block_io<>::READ_ONLY); block_manager<>::ptr bm = open_bm(dev, block_io<>::READ_ONLY);
metadata::ptr md(new metadata(bm, metadata::OPEN)); metadata::ptr md(new metadata(bm, metadata::OPEN));
emitter::ptr e = create_xml_emitter(out); emitter::ptr e = create_xml_emitter(out);
@ -56,13 +64,13 @@ namespace {
return 0; return 0;
} }
int dump(string const &dev, string const &output) { int dump(string const &dev, string const &output, flags const &fs) {
try { try {
if (want_stdout(output)) if (want_stdout(output))
return dump_(dev, cout); return dump_(dev, cout, fs);
else { else {
ofstream out(output.c_str()); ofstream out(output.c_str());
return dump_(dev, out); return dump_(dev, out, fs);
} }
} catch (std::exception &e) { } catch (std::exception &e) {
@ -76,7 +84,8 @@ namespace {
<< "Options:" << endl << "Options:" << endl
<< " {-h|--help}" << endl << " {-h|--help}" << endl
<< " {-o <xml file>}" << endl << " {-o <xml file>}" << endl
<< " {-V|--version}" << endl; << " {-V|--version}" << endl
<< " {--repair}" << endl;
} }
} }
@ -85,18 +94,24 @@ namespace {
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
int c; int c;
flags fs;
string output("-"); string output("-");
char const shortopts[] = "ho:V"; char const shortopts[] = "ho:V";
option const longopts[] = { option const longopts[] = {
{ "help", no_argument, NULL, 'h'}, { "help", no_argument, NULL, 'h' },
{ "output", required_argument, NULL, 'o'}, { "output", required_argument, NULL, 'o' },
{ "version", no_argument, NULL, 'V'}, { "version", no_argument, NULL, 'V' },
{ "repair", no_argument, NULL, 1 },
{ NULL, no_argument, NULL, 0 } { NULL, no_argument, NULL, 0 }
}; };
while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) { while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) {
switch(c) { switch(c) {
case 1:
fs.repair_ = true;
break;
case 'h': case 'h':
usage(cout, basename(argv[0])); usage(cout, basename(argv[0]));
return 0; return 0;
@ -121,7 +136,7 @@ int main(int argc, char **argv)
return 1; return 1;
} }
return dump(argv[optind], output); return dump(argv[optind], output, fs);
} }
//---------------------------------------------------------------- //----------------------------------------------------------------