2013-04-23 19:51:44 +05:30
|
|
|
#include "persistent-data/math_utils.h"
|
2013-09-11 16:10:46 +05:30
|
|
|
#include "persistent-data/file_utils.h"
|
2013-04-23 19:51:44 +05:30
|
|
|
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2017-04-29 23:21:52 +05:30
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sstream>
|
2013-04-23 19:51:44 +05:30
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
using namespace base;
|
2016-03-04 16:13:58 +05:30
|
|
|
using namespace bcache;
|
|
|
|
using namespace persistent_data;
|
2017-04-29 23:21:52 +05:30
|
|
|
using namespace std;
|
2013-04-23 19:51:44 +05:30
|
|
|
|
|
|
|
//----------------------------------------------------------------
|
|
|
|
|
2013-05-28 18:18:10 +05:30
|
|
|
persistent_data::block_address
|
2017-04-29 23:21:52 +05:30
|
|
|
persistent_data::get_nr_blocks(std::string const &path, sector_t block_size)
|
2013-04-23 19:51:44 +05:30
|
|
|
{
|
2017-04-29 23:21:52 +05:30
|
|
|
return div_down<block_address>(file_utils::get_file_length(path),
|
|
|
|
block_size);
|
2013-04-23 19:51:44 +05:30
|
|
|
}
|
|
|
|
|
2016-03-04 16:13:58 +05:30
|
|
|
block_address
|
2017-04-29 23:21:52 +05:30
|
|
|
persistent_data::get_nr_metadata_blocks(std::string const &path)
|
2016-03-04 16:13:58 +05:30
|
|
|
{
|
|
|
|
return get_nr_blocks(path, MD_BLOCK_SIZE);
|
|
|
|
}
|
|
|
|
|
2013-09-11 16:10:46 +05:30
|
|
|
persistent_data::block_manager<>::ptr
|
2015-07-07 18:17:00 +05:30
|
|
|
persistent_data::open_bm(std::string const &dev_path, block_manager<>::mode m, bool excl)
|
2013-09-11 16:10:46 +05:30
|
|
|
{
|
2016-03-04 16:13:58 +05:30
|
|
|
block_address nr_blocks = get_nr_metadata_blocks(dev_path);
|
2015-07-07 18:17:00 +05:30
|
|
|
return block_manager<>::ptr(new block_manager<>(dev_path, nr_blocks, 1, m, excl));
|
2013-09-11 16:10:46 +05:30
|
|
|
}
|
|
|
|
|
2013-04-23 19:51:44 +05:30
|
|
|
//----------------------------------------------------------------
|