block manager can now be opened read only or read/write

This commit is contained in:
Joe Thornber 2011-10-10 17:21:22 +01:00
parent 61293708e3
commit 8999232657
2 changed files with 3 additions and 4 deletions

View File

@ -39,7 +39,7 @@ namespace persistent_data {
public:
typedef boost::shared_ptr<block_manager> ptr;
block_manager(std::string const &path, block_address nr_blocks);
block_manager(std::string const &path, block_address nr_blocks, bool writeable = false);
~block_manager();
typedef unsigned char buffer[BlockSize];

View File

@ -51,14 +51,13 @@ block_manager<BlockSize>::write_ref::data()
//----------------------------------------------------------------
template <uint32_t BlockSize>
block_manager<BlockSize>::block_manager(std::string const &path, block_address nr_blocks)
block_manager<BlockSize>::block_manager(std::string const &path, block_address nr_blocks, bool writeable)
: nr_blocks_(nr_blocks),
lock_count_(0),
superblock_count_(0),
ordinary_count_(0)
{
//fd_ = ::open(path.c_str(), O_RDWR | O_CREAT, 0666);
fd_ = ::open(path.c_str(), O_RDONLY, 0666);
fd_ = ::open(path.c_str(), writeable ? (O_RDWR | O_CREAT) : O_RDONLY, 0666);
if (fd_ < 0)
throw std::runtime_error("couldn't open file");
}