1/*
2 * Copyright 2002-2011 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
5#ifndef _NODE_H
6#define _NODE_H
7
8
9#include <Statable.h>
10
11
12class BDirectory;
13class BEntry;
14class BString;
15struct entry_ref;
16
17
18struct node_ref {
19	node_ref();
20	node_ref(dev_t device, ino_t node);
21	node_ref(const node_ref& other);
22
23	bool operator==(const node_ref& other) const;
24	bool operator!=(const node_ref& other) const;
25	bool operator<(const node_ref& other) const;
26	node_ref& operator=(const node_ref& other);
27
28	dev_t device;
29	ino_t node;
30};
31
32
33class BNode : public BStatable {
34public:
35								BNode();
36								BNode(const entry_ref* ref);
37								BNode(const BEntry* entry);
38								BNode(const char* path);
39								BNode(const BDirectory* dir, const char* path);
40								BNode(const BNode& node);
41	virtual						~BNode();
42
43			status_t			InitCheck() const;
44
45	virtual	status_t			GetStat(struct stat* st) const;
46
47			status_t			SetTo(const entry_ref* ref);
48			status_t			SetTo(const BEntry* entry);
49			status_t			SetTo(const char* path);
50			status_t			SetTo(const BDirectory* dir, const char* path);
51			void				Unset();
52
53			status_t			Lock();
54			status_t			Unlock();
55
56			status_t			Sync();
57
58			ssize_t				WriteAttr(const char* name, type_code type,
59									off_t offset, const void* buffer,
60									size_t length);
61			ssize_t				ReadAttr(const char* name, type_code type,
62									off_t offset, void* buffer,
63									size_t length) const;
64			status_t			RemoveAttr(const char* name);
65			status_t			RenameAttr(const char* oldName,
66									const char* newName);
67			status_t			GetAttrInfo(const char* name,
68									struct attr_info* info) const;
69			status_t			GetNextAttrName(char* buffer);
70			status_t			RewindAttrs();
71			status_t			WriteAttrString(const char* name,
72									const BString* data);
73			status_t			ReadAttrString(const char* name,
74									BString* result) const;
75
76			BNode&				operator=(const BNode& node);
77			bool				operator==(const BNode& node) const;
78			bool				operator!=(const BNode& node) const;
79
80			int					Dup();
81				// This should be "const" but R5's is not... Ugggh.
82
83private:
84	friend class BFile;
85	friend class BDirectory;
86	friend class BSymLink;
87
88	virtual	void				_RudeNode1();
89	virtual	void				_RudeNode2();
90	virtual	void				_RudeNode3();
91	virtual	void				_RudeNode4();
92	virtual	void				_RudeNode5();
93	virtual	void				_RudeNode6();
94
95private:
96			status_t			set_fd(int fd);
97	virtual	void				close_fd();
98			void				set_status(status_t newStatus);
99
100			status_t			_SetTo(int fd, const char* path, bool traverse);
101			status_t			_SetTo(const entry_ref* ref, bool traverse);
102
103	virtual	status_t			set_stat(struct stat& stat, uint32 what);
104
105			status_t			_GetStat(struct stat* stat) const;
106	virtual	status_t			_GetStat(struct stat_beos* stat) const;
107			status_t			InitAttrDir();
108
109private:
110			uint32				rudeData[4];
111			int					fFd;
112				// Ffile descriptor for the given node
113			int					fAttrFd;
114				// file descriptor for the attribute directory of the node,
115				// initialized lazily
116			status_t			fCStatus;
117				// the node's initialization status
118};
119
120
121#endif	// _NODE_H
122