1// Volume.h
2//
3// Copyright (c) 2003, Ingo Weinhold (bonefish@cs.tu-berlin.de)
4//
5// This program is free software; you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation; either version 2 of the License, or
8// (at your option) any later version.
9//
10// This program 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 this program; if not, write to the Free Software
17// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18//
19// You can alternatively use *this file* under the terms of the the MIT
20// license included in this package.
21
22#ifndef VOLUME_H
23#define VOLUME_H
24
25#include <fs_interface.h>
26#include <SupportDefs.h>
27
28#include "hashes.h"
29#include "List.h"
30
31struct reiserfs_super_block;
32
33class BlockCache;
34class Tree;
35class Settings;
36class SuperBlock;
37class VNode;
38
39class Volume {
40public:
41	Volume();
42	~Volume();
43
44	status_t Identify(int fd, partition_data *partition);
45
46	status_t Mount(fs_volume *fsVolume, const char *path);
47	status_t Unmount();
48
49	dev_t GetID() const				{ return fFSVolume->id; }
50	fs_volume *GetFSVolume() const	{ return fFSVolume; }
51
52	off_t GetBlockSize() const;
53	off_t CountBlocks() const;
54	off_t CountFreeBlocks() const;
55	const char *GetName() const;
56	void UpdateName(partition_id partitionID);
57	const char *GetDeviceName() const;
58
59	BlockCache *GetBlockCache() const	{ return fBlockCache; }
60	Tree *GetTree() const				{ return fTree; }
61	Settings *GetSettings() const		{ return fSettings; }
62
63	status_t GetKeyOffsetForName(const char * name, int len, uint64 *result);
64
65	VNode *GetRootVNode() const			{ return fRootVNode; }
66
67	status_t GetVNode(ino_t id, VNode **node);
68	status_t PutVNode(ino_t id);
69
70	status_t FindVNode(ino_t id, VNode *node);
71	status_t FindVNode(uint32 dirID, uint32 objectID, VNode *node);
72
73	status_t FindDirEntry(VNode *dir, const char *entryName,
74						  VNode *foundNode, bool failIfHidden = false);
75
76	status_t ReadLink(VNode *node, char *buffer, size_t bufferSize,
77					  size_t *linkLength);
78
79	status_t FindEntry(const VNode *rootDir, const char *path,
80					   VNode *foundNode);
81
82	bool IsNegativeEntry(ino_t id);
83	bool IsNegativeEntry(uint32 dirID, uint32 objectID);
84
85	bool GetHideEsoteric() const;
86
87private:
88	status_t _ReadSuperBlock();
89	void _InitHashFunction();
90	uint32 _DetectHashFunction();
91	bool _VerifyHashFunction(hash_function_t function);
92	void _InitNegativeEntries();
93
94private:
95	fs_volume				*fFSVolume;
96	int						fDevice;
97	BlockCache				*fBlockCache;
98	Tree					*fTree;
99	SuperBlock				*fSuperBlock;
100	hash_function_t			fHashFunction;
101	VNode					*fRootVNode;
102	char					*fDeviceName;
103	Settings				*fSettings;
104	List<ino_t>				fNegativeEntries;
105	char					fVolumeName[B_OS_NAME_LENGTH];
106};
107
108#endif	// VOLUME_H
109