cache_check work

This commit is contained in:
Joe Thornber
2013-03-21 15:44:28 +00:00
committed by Joe Thornber
parent 81d4e5523f
commit 52f1aa8a8a
6 changed files with 221 additions and 19 deletions

94
cache/check.cc vendored
View File

@ -17,21 +17,71 @@
// <http://www.gnu.org/licenses/>.
#include <iostream>
#include <sstream>
#include <string>
#include <stdexcept>
#include <errno.h>
#include <fcntl.h>
#include <getopt.h>
#include <libgen.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#if 0
#include "array.h"
#include "metadata.h"
#include "metadata_checker.h"
#include "version.h"
using namespace persistent_data;
using namespace std;
using namespace thin_provisioning;
//----------------------------------------------------------------
namespace {
struct stat guarded_stat(string const &path) {
struct stat info;
int r = ::stat(path.c_str(), &info);
if (r) {
ostringstream msg;
char buffer[128], *ptr;
ptr = ::strerror_r(errno, buffer, sizeof(buffer));
msg << path << ": " << ptr;
throw runtime_error(msg.str());
}
return info;
}
int open_file(string const &path, int mode) {
int fd = open(path.c_str(), mode);
if (fd < 0) {
ostringstream msg;
char buffer[128], *ptr;
ptr = strerror_r(errno, buffer, sizeof(buffer));
msg << path << ": " << ptr;
throw runtime_error(msg.str());
}
return fd;
}
int check(string const &path, bool quiet) {
struct stat info = guarded_stat(path);
if (!S_ISREG(info.st_mode) && !S_ISBLK(info.st_mode)) {
ostringstream msg;
msg << path << ": " << "Not a block device or regular file";
throw runtime_error(msg.str());
}
int fd = open_file(path, O_RDONLY);
ostringstream msg;
msg << path << ": " << "No superblock found";
throw runtime_error(msg.str());
return 0;
#if 0
try {
metadata::ptr md(new metadata(path, metadata::OPEN));
@ -48,6 +98,7 @@ namespace {
}
return 0;
#endif
}
void usage(ostream &out, string const &cmd) {
@ -57,8 +108,12 @@ namespace {
<< " {-h|--help}" << endl
<< " {-V|--version}" << endl;
}
char const *TOOLS_VERSION = "0.1.6";
}
//----------------------------------------------------------------
int main(int argc, char **argv)
{
int c;
@ -82,7 +137,7 @@ int main(int argc, char **argv)
break;
case 'V':
cout << THIN_PROVISIONING_TOOLS_VERSION << endl;
cout << TOOLS_VERSION << endl;
return 0;
default:
@ -94,15 +149,18 @@ int main(int argc, char **argv)
if (argc == optind) {
cerr << "No input file provided." << endl;
usage(cerr, basename(argv[0]));
exit(1);
return 1;
}
return check(argv[optind], quiet);
try {
check(argv[optind], quiet);
} catch (exception const &e) {
cerr << e.what() << endl;
return 1;
}
return 0;
}
#else
int main(int argc, char **argv)
{
cerr << "not implemented" << endl;
return 1;
}
#endif
//----------------------------------------------------------------