1 /*
2    Copyright 2013-2015 Skytechnology sp. z o.o.
3 
4    This file is part of LizardFS.
5 
6    LizardFS is free software: you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation, version 3.
9 
10    LizardFS is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13    GNU General Public License for more details.
14 
15    You should have received a copy of the GNU General Public License
16    along with LizardFS. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #pragma once
20 
21 #include "common/platform.h"
22 
23 #include <cstdint>
24 
25 struct WriteCacheBlock {
26 public:
27 	enum Type {
28 		kWritableBlock, // normal block, written by clients
29 		kReadOnlyBlock, // a kWriteableBlock after it is passed to ChunkWriter for the first time
30 		kParityBlock,   // a parity block
31 		kReadBlock      // a block read from a chunkserver to calculate a parity
32 	};
33 
34 	uint8_t* blockData;
35 	uint32_t chunkIndex;
36 	uint32_t blockIndex;
37 	uint32_t from;
38 	uint32_t to;
39 	Type type;
40 
41 	WriteCacheBlock(uint32_t chunkIndex, uint32_t blockIndex, Type type);
42 	WriteCacheBlock(const WriteCacheBlock&) = delete;
43 	WriteCacheBlock(WriteCacheBlock&& block) noexcept;
44 	~WriteCacheBlock();
45 	WriteCacheBlock& operator=(const WriteCacheBlock&) = delete;
46 	WriteCacheBlock& operator=(WriteCacheBlock&&);
47 	bool expand(uint32_t from, uint32_t to, const uint8_t *buffer);
48 	uint64_t offsetInFile() const;
49 	uint32_t offsetInChunk() const;
50 	uint32_t size() const;
51 	const uint8_t* data() const;
52 	uint8_t* data();
53 };
54