1/*
2 * Copyright 2010, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
5#ifndef FILE_H
6#define FILE_H
7
8
9#include "Node.h"
10
11
12struct file_io_vec;
13
14
15class File : public Node {
16public:
17								File(Volume* volume, uint64 blockIndex,
18									const checksumfs_node& nodeData);
19								File(Volume* volume, mode_t mode);
20	virtual						~File();
21
22	virtual	status_t			InitForVFS();
23	virtual	void				DeletingNode();
24
25	virtual	status_t			Resize(uint64 newSize, bool fillWithZeroes,
26									Transaction& transaction);
27	virtual	status_t			Read(off_t pos, void* buffer, size_t size,
28									size_t& _bytesRead);
29	virtual	status_t			Write(off_t pos, const void* buffer,
30									size_t size, size_t& _bytesWritten,
31									bool& _sizeChanged);
32	virtual	status_t			Sync();
33
34	virtual	void				RevertNodeData(const checksumfs_node& nodeData);
35
36			status_t			GetFileVecs(uint64 offset, size_t size,
37									file_io_vec* vecs, size_t count,
38									size_t& _count);
39
40			void*				FileMap() const	{ return fFileMap; }
41
42private:
43			struct LevelInfo;
44
45private:
46	static	uint32				_DepthForBlockCount(uint64 blockCount);
47	static	void				_UpdateLevelInfos(LevelInfo* infos,
48									int32 levelCount, uint64 blockCount);
49	static	LevelInfo*			_GetLevelInfos(uint64 blockCount,
50									int32& _levelCount);
51
52			status_t			_ShrinkTree(uint64 blockCount,
53									uint64 newBlockCount,
54									Transaction& transaction);
55			status_t			_GrowTree(uint64 blockCount,
56									uint64 newBlockCount,
57									Transaction& transaction);
58
59			status_t			_WriteZeroes(uint64 offset, uint64 size);
60			status_t			_WriteData(uint64 offset, const void* buffer,
61									size_t size, size_t& _bytesWritten);
62
63private:
64			void*				fFileCache;
65			void*				fFileMap;
66};
67
68
69#endif	// FILE_H
70