2015-10-16 02:38:34 +02:00
|
|
|
#include <messmer/blockstore/implementations/ondisk/OnDiskBlockStore.h>
|
2015-04-08 14:15:11 +02:00
|
|
|
#include <messmer/blockstore/implementations/inmemory/InMemoryBlockStore.h>
|
|
|
|
#include <messmer/blockstore/implementations/inmemory/InMemoryBlock.h>
|
2014-11-04 02:32:06 +01:00
|
|
|
#include <cmath>
|
|
|
|
#include <cstdio>
|
|
|
|
#include <cstdlib>
|
2015-09-29 22:44:19 +02:00
|
|
|
#include <messmer/cpp-utils/assert/backtrace.h>
|
2015-10-15 03:38:44 +02:00
|
|
|
#include <messmer/cpp-utils/daemon/daemonize.h>
|
2014-11-04 02:32:06 +01:00
|
|
|
|
2015-02-17 01:02:15 +01:00
|
|
|
#include "messmer/fspp/fuse/Fuse.h"
|
|
|
|
#include "messmer/fspp/impl/FilesystemImpl.h"
|
2015-09-12 20:16:13 +02:00
|
|
|
#include "filesystem/CryDevice.h"
|
|
|
|
#include "config/CryConfigLoader.h"
|
2015-09-29 14:29:10 +02:00
|
|
|
#include "program_options/Parser.h"
|
2014-11-15 16:33:24 +01:00
|
|
|
|
2015-09-19 01:02:42 +02:00
|
|
|
#include <gitversion/version.h>
|
2015-09-16 22:54:07 +02:00
|
|
|
|
2015-09-29 14:29:10 +02:00
|
|
|
using namespace cryfs;
|
2014-11-15 16:33:24 +01:00
|
|
|
namespace bf = boost::filesystem;
|
2014-11-04 02:54:23 +01:00
|
|
|
|
2014-12-09 17:19:59 +01:00
|
|
|
using blockstore::ondisk::OnDiskBlockStore;
|
2015-04-08 14:15:11 +02:00
|
|
|
using blockstore::inmemory::InMemoryBlockStore;
|
2015-09-29 14:29:10 +02:00
|
|
|
using program_options::ProgramOptions;
|
2014-12-07 08:57:23 +01:00
|
|
|
|
2015-07-21 18:32:40 +02:00
|
|
|
using cpputils::make_unique_ref;
|
2015-10-23 12:16:23 +02:00
|
|
|
using cpputils::Random;
|
|
|
|
using cpputils::IOStreamConsole;
|
2015-09-16 22:54:07 +02:00
|
|
|
using std::cout;
|
|
|
|
using std::endl;
|
2015-09-29 14:29:10 +02:00
|
|
|
using std::vector;
|
2015-10-17 18:31:17 +02:00
|
|
|
using boost::none;
|
2014-12-07 08:57:23 +01:00
|
|
|
|
2015-09-29 22:44:19 +02:00
|
|
|
//TODO Support files > 4GB
|
2015-10-14 15:01:08 +02:00
|
|
|
//TODO Improve parallelity.
|
2015-10-16 02:38:34 +02:00
|
|
|
//TODO Did deadlock in bonnie++ second run (in the create files sequentially) - maybe also in a later run or different step?
|
|
|
|
//TODO Improve error message when root blob wasn't found.
|
2015-10-14 02:17:50 +02:00
|
|
|
|
2015-09-28 13:41:23 +02:00
|
|
|
void showVersion() {
|
2015-09-19 01:02:42 +02:00
|
|
|
cout << "CryFS Version " << version::VERSION_STRING << endl;
|
|
|
|
if (version::IS_DEV_VERSION) {
|
|
|
|
cout << "WARNING! This is a development version based on git commit " << version::GIT_COMMIT_ID <<
|
2015-09-28 13:41:23 +02:00
|
|
|
". Please do not use in production!" << endl;
|
2015-09-19 01:02:42 +02:00
|
|
|
} else if (!version::IS_STABLE_VERSION) {
|
2015-09-18 22:09:33 +02:00
|
|
|
cout << "WARNING! This is an experimental version. Please backup your data frequently!" << endl;
|
2015-10-16 02:38:34 +02:00
|
|
|
} else {
|
|
|
|
//TODO This is shown for stable version numbers like 0.8 - remove once we reach 1.0
|
|
|
|
cout << "WARNING! This version is not considered stable. Please backup your data frequently!" << endl;
|
2015-09-18 22:09:33 +02:00
|
|
|
}
|
2015-10-15 00:16:00 +02:00
|
|
|
#ifndef NDEBUG
|
|
|
|
cout << "WARNING! This is a debug build. Performance might be slow." << endl;
|
|
|
|
#endif
|
2015-09-18 22:09:33 +02:00
|
|
|
cout << endl;
|
2015-09-28 13:41:23 +02:00
|
|
|
}
|
|
|
|
|
2015-10-23 12:16:23 +02:00
|
|
|
CryConfigFile loadOrCreateConfig(const ProgramOptions &options) {
|
|
|
|
auto console = make_unique_ref<IOStreamConsole>();
|
|
|
|
auto &keyGenerator = Random::OSRandom();
|
|
|
|
return CryConfigLoader(std::move(console), keyGenerator).loadOrCreate(bf::path(options.configFile()));
|
|
|
|
}
|
|
|
|
|
2015-09-29 14:29:10 +02:00
|
|
|
void runFilesystem(const ProgramOptions &options) {
|
2015-10-23 12:16:23 +02:00
|
|
|
auto config = loadOrCreateConfig(options);
|
2015-10-16 02:38:34 +02:00
|
|
|
//TODO This daemonize causes error messages when initializing CryDevice to get lost.
|
|
|
|
// However, initializing CryDevice might (?) already spawn threads and we have to do daemonization before that
|
|
|
|
// because it doesn't fork threads. What to do?
|
|
|
|
if (!options.foreground()) {
|
2015-10-17 18:31:17 +02:00
|
|
|
cpputils::daemonize();
|
|
|
|
if (options.logFile() == none) {
|
|
|
|
// Setup logging to syslog.
|
|
|
|
cpputils::logging::setLogger(spdlog::syslog_logger("cryfs", "cryfs", LOG_PID));
|
|
|
|
}
|
2015-10-16 02:38:34 +02:00
|
|
|
}
|
2015-09-29 14:29:10 +02:00
|
|
|
auto blockStore = make_unique_ref<OnDiskBlockStore>(bf::path(options.baseDir()));
|
|
|
|
CryDevice device(std::move(config), std::move(blockStore));
|
2015-09-18 22:09:33 +02:00
|
|
|
fspp::FilesystemImpl fsimpl(&device);
|
|
|
|
fspp::fuse::Fuse fuse(&fsimpl);
|
2015-09-29 14:29:10 +02:00
|
|
|
|
|
|
|
vector<char*> fuseOptions = options.fuseOptions();
|
|
|
|
fuse.run(fuseOptions.size(), fuseOptions.data());
|
2015-09-28 13:41:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]) {
|
2015-09-29 22:44:19 +02:00
|
|
|
cpputils::showBacktraceOnSigSegv();
|
2015-09-28 13:41:23 +02:00
|
|
|
showVersion();
|
2015-10-15 03:38:44 +02:00
|
|
|
|
2015-09-29 14:29:10 +02:00
|
|
|
ProgramOptions options = program_options::Parser(argc, argv).parse();
|
2015-10-17 18:31:17 +02:00
|
|
|
//TODO Test that --logfile parameter works. Should be: file if specified, otherwise stderr if foreground, else syslog.
|
|
|
|
if (options.logFile() != none) {
|
|
|
|
cpputils::logging::setLogger(spdlog::create<spdlog::sinks::simple_file_sink<std::mutex>>("cryfs", *options.logFile()));
|
|
|
|
}
|
2015-09-29 14:29:10 +02:00
|
|
|
runFilesystem(options);
|
2015-09-18 22:09:33 +02:00
|
|
|
return 0;
|
2014-11-04 02:32:06 +01:00
|
|
|
}
|