[thin_check] --clear-needs-check-flag

This commit is contained in:
Joe Thornber
2014-03-27 12:00:17 +00:00
parent fe019f6946
commit c3249ff757
4 changed files with 82 additions and 17 deletions

View File

@@ -148,6 +148,15 @@ namespace {
//--------------------------------
struct flags {
flags()
: check_device_tree(true),
check_mapping_tree_level1(true),
check_mapping_tree_level2(true),
ignore_non_fatal_errors(false),
quiet(false),
clear_needs_check_flag_on_success(false) {
}
bool check_device_tree;
bool check_mapping_tree_level1;
bool check_mapping_tree_level2;
@@ -155,6 +164,7 @@ namespace {
bool ignore_non_fatal_errors;
bool quiet;
bool clear_needs_check_flag_on_success;
};
error_state metadata_check(string const &path, flags fs) {
@@ -214,12 +224,29 @@ namespace {
dev_rep.get_error()));
}
int check(string const &path, flags fs) {
void clear_needs_check(string const &path) {
block_manager<>::ptr bm = open_bm(path, block_io<>::READ_WRITE);
superblock_detail::superblock sb = read_superblock(bm);
sb.set_needs_check_flag(false);
write_superblock(bm, sb);
}
bool check(string const &path, flags fs) {
error_state err;
bool success = false;
try {
err = metadata_check(path, fs);
if (fs.ignore_non_fatal_errors)
success = (err == FATAL) ? 1 : 0;
else
success = (err == NO_ERROR) ? 0 : 1;
if (success && fs.clear_needs_check_flag_on_success)
clear_needs_check(path);
} catch (std::exception &e) {
if (!fs.quiet)
cerr << e.what() << endl;
@@ -227,10 +254,7 @@ namespace {
return 1;
}
if (fs.ignore_non_fatal_errors)
return (err == FATAL) ? 1 : 0;
else
return (err == NO_ERROR) ? 0 : 1;
return success;
}
void usage(ostream &out, string const &cmd) {
@@ -239,9 +263,10 @@ namespace {
<< " {-q|--quiet}" << endl
<< " {-h|--help}" << endl
<< " {-V|--version}" << endl
<< " {--super-block-only}" << endl
<< " {--clear-needs-check-flag}" << endl
<< " {--ignore-non-fatal-errors}" << endl
<< " {--skip-mappings}" << endl
<< " {--ignore-non-fatal-errors}" << endl;
<< " {--super-block-only}" << endl;
}
}
@@ -249,11 +274,6 @@ int main(int argc, char **argv)
{
int c;
flags fs;
fs.check_device_tree = true;
fs.check_mapping_tree_level1 = true,
fs.check_mapping_tree_level2 = true,
fs.ignore_non_fatal_errors = false,
fs.quiet = false;
char const shortopts[] = "qhV";
option const longopts[] = {
@@ -263,6 +283,7 @@ int main(int argc, char **argv)
{ "super-block-only", no_argument, NULL, 1},
{ "skip-mappings", no_argument, NULL, 2},
{ "ignore-non-fatal-errors", no_argument, NULL, 3},
{ "clear-needs-check-flag", no_argument, NULL, 4 },
{ NULL, no_argument, NULL, 0 }
};
@@ -297,6 +318,11 @@ int main(int argc, char **argv)
fs.ignore_non_fatal_errors = true;
break;
case 4:
// clear needs-check flag
fs.clear_needs_check_flag_on_success = true;
break;
default:
usage(cerr, basename(argv[0]));
return 1;