2012-02-27 19:37:16 +05:30
|
|
|
// Copyright (C) 2011 Red Hat, Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// This file is part of the thin-provisioning-tools source.
|
|
|
|
//
|
|
|
|
// thin-provisioning-tools is free software: you can redistribute it
|
|
|
|
// and/or modify it under the terms of the GNU General Public License
|
|
|
|
// as published by the Free Software Foundation, either version 3 of
|
|
|
|
// the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// thin-provisioning-tools is distributed in the hope that it will be
|
|
|
|
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
|
|
|
|
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License along
|
|
|
|
// with thin-provisioning-tools. If not, see
|
|
|
|
// <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <getopt.h>
|
|
|
|
#include <libgen.h>
|
|
|
|
|
|
|
|
#include "metadata.h"
|
|
|
|
#include "metadata_checker.h"
|
|
|
|
#include "version.h"
|
|
|
|
|
|
|
|
using namespace persistent_data;
|
|
|
|
using namespace std;
|
|
|
|
using namespace thin_provisioning;
|
|
|
|
|
|
|
|
namespace {
|
2012-03-02 18:29:59 +05:30
|
|
|
int check(string const &path, bool quiet) {
|
2012-03-02 15:30:31 +05:30
|
|
|
try {
|
|
|
|
metadata::ptr md(new metadata(path, metadata::OPEN));
|
2012-02-27 19:37:16 +05:30
|
|
|
|
2012-03-02 15:30:31 +05:30
|
|
|
optional<error_set::ptr> maybe_errors = metadata_check(md);
|
|
|
|
if (maybe_errors) {
|
2012-03-02 18:29:59 +05:30
|
|
|
if (!quiet)
|
|
|
|
cerr << error_selector(*maybe_errors, 3);
|
2012-03-02 15:30:31 +05:30
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
} catch (std::exception &e) {
|
2012-03-02 18:29:59 +05:30
|
|
|
if (!quiet)
|
2012-03-13 17:40:13 +05:30
|
|
|
cerr << e.what() << endl;
|
2012-02-27 19:37:16 +05:30
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-03-13 19:36:10 +05:30
|
|
|
void usage(ostream &out, string const &cmd) {
|
|
|
|
out << "Usage: " << cmd << " [options] {device|file}" << endl
|
|
|
|
<< "Options:" << endl
|
|
|
|
<< " {-q|--quiet}" << endl
|
|
|
|
<< " {-h|--help}" << endl
|
|
|
|
<< " {-V|--version}" << endl;
|
2012-02-27 19:37:16 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int c;
|
2012-03-02 18:29:59 +05:30
|
|
|
bool quiet = false;
|
2012-03-02 18:40:53 +05:30
|
|
|
const char shortopts[] = "qhV";
|
2012-02-27 19:37:16 +05:30
|
|
|
const struct option longopts[] = {
|
2012-03-02 18:29:59 +05:30
|
|
|
{ "quiet", no_argument, NULL, 'q'},
|
2012-02-27 19:37:16 +05:30
|
|
|
{ "help", no_argument, NULL, 'h'},
|
|
|
|
{ "version", no_argument, NULL, 'V'},
|
|
|
|
{ NULL, no_argument, NULL, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) {
|
|
|
|
switch(c) {
|
|
|
|
case 'h':
|
2012-03-13 19:36:10 +05:30
|
|
|
usage(cout, basename(argv[0]));
|
2012-02-27 19:37:16 +05:30
|
|
|
return 0;
|
2012-03-02 18:29:59 +05:30
|
|
|
|
|
|
|
case 'q':
|
|
|
|
quiet = true;
|
|
|
|
break;
|
|
|
|
|
2012-02-27 19:37:16 +05:30
|
|
|
case 'V':
|
2012-03-13 18:02:30 +05:30
|
|
|
cout << THIN_PROVISIONING_TOOLS_VERSION << endl;
|
2012-02-27 19:37:16 +05:30
|
|
|
return 0;
|
2012-03-13 18:02:30 +05:30
|
|
|
|
2012-03-06 00:04:05 +05:30
|
|
|
default:
|
2012-03-13 19:36:10 +05:30
|
|
|
usage(cerr, basename(argv[0]));
|
2012-03-06 00:04:05 +05:30
|
|
|
return 1;
|
2012-02-27 19:37:16 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-06 00:04:05 +05:30
|
|
|
if (argc == optind) {
|
2012-03-13 19:36:10 +05:30
|
|
|
cerr << "No input file provided." << endl;
|
|
|
|
usage(cerr, basename(argv[0]));
|
2012-02-27 19:37:16 +05:30
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2012-03-05 17:16:07 +05:30
|
|
|
return check(argv[optind], quiet);
|
2012-02-27 19:37:16 +05:30
|
|
|
}
|