From 8999232657bf5329548bd75d829eface7837edf0 Mon Sep 17 00:00:00 2001 From: Joe Thornber Date: Mon, 10 Oct 2011 17:21:22 +0100 Subject: [PATCH] block manager can now be opened read only or read/write --- block.h | 2 +- block.tcc | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/block.h b/block.h index 7fd3920..d91e6ec 100644 --- a/block.h +++ b/block.h @@ -39,7 +39,7 @@ namespace persistent_data { public: typedef boost::shared_ptr 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]; diff --git a/block.tcc b/block.tcc index 19eb18f..4c53724 100644 --- a/block.tcc +++ b/block.tcc @@ -51,14 +51,13 @@ block_manager::write_ref::data() //---------------------------------------------------------------- template -block_manager::block_manager(std::string const &path, block_address nr_blocks) +block_manager::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"); }