1// VNode.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 V_NODE_H
23#define V_NODE_H
24
25#include "fsproto.h"
26#include "StatItem.h"
27
28class VNode {
29public:
30	VNode();
31	VNode(const VNode &node);
32	VNode(vnode_id id);
33	VNode(uint32 dirID, uint32 objectID);
34	~VNode();
35
36	status_t SetTo(vnode_id id);
37	status_t SetTo(uint32 dirID, uint32 objectID);
38
39//	void SetParentDirID(uint32 id)		{ fParentDirID = id; }
40//	uint32 GetParentDirID() const		{ return fParentDirID; }
41//	void SetParentObjectID(uint32 id)	{ fParentObjectID = id; }
42//	uint32 GetParentObjectID() const	{ return fParentObjectID; }
43	void SetDirID(uint32 id)			{ fDirID = id; }
44	uint32 GetDirID() const				{ return fDirID; }
45	void SetObjectID(uint32 id)			{ fObjectID = id; }
46	uint32 GetObjectID() const			{ return fObjectID; }
47
48	vnode_id GetID() const;
49	void SetParentID(uint32 dirID, uint32 objectID);
50	void SetParentID(vnode_id id)		{ fParentID = id; }
51	// only valid for dirs!
52	vnode_id GetParentID() const		{ return fParentID; }
53
54	StatData *GetStatData() { return &fStatData; }
55	const StatData *GetStatData() const { return &fStatData; }
56
57	bool IsDir() const { return fStatData.IsDir(); }
58	bool IsFile() const { return fStatData.IsFile(); }
59	bool IsSymlink() const { return fStatData.IsSymlink(); }
60	bool IsEsoteric() const { return fStatData.IsEsoteric(); }
61
62	// vnode ID <-> dir,object ID conversion
63	static vnode_id GetIDFor(uint32 dirID, uint32 objectID)
64		{ return (vnode_id)((uint64)dirID << 32 | (uint64)objectID); }
65	static uint32 GetDirIDFor(vnode_id id) { return uint32((uint64)id >> 32); }
66	static uint32 GetObjectIDFor(vnode_id id)
67		{ return uint32((uint64)id & 0xffffffffULL); }
68
69	VNode &operator=(const VNode &node);
70
71private:
72	vnode_id	fParentID;
73	uint32		fDirID;
74	uint32		fObjectID;
75	StatData	fStatData;
76};
77
78#endif	// V_NODE_H
79