thin-provisioning-tools/persistent-data/file_utils.cc

40 lines
1.1 KiB
C++
Raw Normal View History

#include "persistent-data/math_utils.h"
2013-09-11 16:10:46 +05:30
#include "persistent-data/file_utils.h"
#include <linux/fs.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sstream>
#include <unistd.h>
using namespace base;
using namespace bcache;
using namespace persistent_data;
using namespace std;
//----------------------------------------------------------------
2013-05-28 18:18:10 +05:30
persistent_data::block_address
persistent_data::get_nr_blocks(std::string const &path, sector_t block_size)
{
return div_down<block_address>(file_utils::get_file_length(path),
block_size);
}
block_address
persistent_data::get_nr_metadata_blocks(std::string const &path)
{
return get_nr_blocks(path, MD_BLOCK_SIZE);
}
2013-09-11 16:10:46 +05:30
persistent_data::block_manager<>::ptr
persistent_data::open_bm(std::string const &dev_path, block_manager<>::mode m, bool excl)
2013-09-11 16:10:46 +05:30
{
block_address nr_blocks = get_nr_metadata_blocks(dev_path);
return block_manager<>::ptr(new block_manager<>(dev_path, nr_blocks, 1, m, excl));
2013-09-11 16:10:46 +05:30
}
//----------------------------------------------------------------