1f9d99406SAxel Dörfler/*
2a30a4a41SJohn Scipione * Copyright 2002-2011 Haiku, Inc. All rights reserved.
3f9d99406SAxel Dörfler * Distributed under the terms of the MIT License.
4f9d99406SAxel Dörfler */
582b75665STyler Dauwalder#ifndef _NODE_H
682b75665STyler Dauwalder#define _NODE_H
8c80c5077SAxel Dörfler
9f9d99406SAxel Dörfler#include <Statable.h>
1142c9b01aSIngo Weinhold
12f9d99406SAxel Dörflerclass BDirectory;
13f2e230caSJérôme Duvalclass BEntry;
14f6e4cbb9SAxel Dörflerclass BString;
15f6e4cbb9SAxel Dörflerstruct entry_ref;
16f6e4cbb9SAxel Dörfler
1852a38012Sejakowatzstruct node_ref {
1942c9b01aSIngo Weinhold	node_ref();
202d8ec1d5SIngo Weinhold	node_ref(dev_t device, ino_t node);
218d39283bSJohn Scipione	node_ref(const node_ref& other);
22f9d99406SAxel Dörfler
23a30a4a41SJohn Scipione	bool operator==(const node_ref& other) const;
24a30a4a41SJohn Scipione	bool operator!=(const node_ref& other) const;
25a30a4a41SJohn Scipione	bool operator<(const node_ref& other) const;
26a30a4a41SJohn Scipione	node_ref& operator=(const node_ref& other);
27f9d99406SAxel Dörfler
2852a38012Sejakowatz	dev_t device;
2952a38012Sejakowatz	ino_t node;
3352a38012Sejakowatzclass BNode : public BStatable {
35c80c5077SAxel Dörfler								BNode();
36c80c5077SAxel Dörfler								BNode(const entry_ref* ref);
37c80c5077SAxel Dörfler								BNode(const BEntry* entry);
38c80c5077SAxel Dörfler								BNode(const char* path);
39c80c5077SAxel Dörfler								BNode(const BDirectory* dir, const char* path);
40c80c5077SAxel Dörfler								BNode(const BNode& node);
41c80c5077SAxel Dörfler	virtual						~BNode();
42c80c5077SAxel Dörfler
43c80c5077SAxel Dörfler			status_t			InitCheck() const;
44c80c5077SAxel Dörfler
45c80c5077SAxel Dörfler	virtual	status_t			GetStat(struct stat* st) const;
46c80c5077SAxel Dörfler
47c80c5077SAxel Dörfler			status_t			SetTo(const entry_ref* ref);
48c80c5077SAxel Dörfler			status_t			SetTo(const BEntry* entry);
49c80c5077SAxel Dörfler			status_t			SetTo(const char* path);
50c80c5077SAxel Dörfler			status_t			SetTo(const BDirectory* dir, const char* path);
51c80c5077SAxel Dörfler			void				Unset();
52c80c5077SAxel Dörfler
53c80c5077SAxel Dörfler			status_t			Lock();
54c80c5077SAxel Dörfler			status_t			Unlock();
55c80c5077SAxel Dörfler
56c80c5077SAxel Dörfler			status_t			Sync();
57c80c5077SAxel Dörfler
58c80c5077SAxel Dörfler			ssize_t				WriteAttr(const char* name, type_code type,
59c80c5077SAxel Dörfler									off_t offset, const void* buffer,
60c80c5077SAxel Dörfler									size_t length);
61c80c5077SAxel Dörfler			ssize_t				ReadAttr(const char* name, type_code type,
62c80c5077SAxel Dörfler									off_t offset, void* buffer,
63c80c5077SAxel Dörfler									size_t length) const;
64c80c5077SAxel Dörfler			status_t			RemoveAttr(const char* name);
65c80c5077SAxel Dörfler			status_t			RenameAttr(const char* oldName,
66c80c5077SAxel Dörfler									const char* newName);
67c80c5077SAxel Dörfler			status_t			GetAttrInfo(const char* name,
68c80c5077SAxel Dörfler									struct attr_info* info) const;
69c80c5077SAxel Dörfler			status_t			GetNextAttrName(char* buffer);
70c80c5077SAxel Dörfler			status_t			RewindAttrs();
71c80c5077SAxel Dörfler			status_t			WriteAttrString(const char* name,
72c80c5077SAxel Dörfler									const BString* data);
73c80c5077SAxel Dörfler			status_t			ReadAttrString(const char* name,
74c80c5077SAxel Dörfler									BString* result) const;
75c80c5077SAxel Dörfler
76c80c5077SAxel Dörfler			BNode&				operator=(const BNode& node);
77c80c5077SAxel Dörfler			bool				operator==(const BNode& node) const;
78c80c5077SAxel Dörfler			bool				operator!=(const BNode& node) const;
79c80c5077SAxel Dörfler
80c80c5077SAxel Dörfler			int					Dup();
81c80c5077SAxel Dörfler				// This should be "const" but R5's is not... Ugggh.
8452a38012Sejakowatz	friend class BFile;
8552a38012Sejakowatz	friend class BDirectory;
8652a38012Sejakowatz	friend class BSymLink;
88c80c5077SAxel Dörfler	virtual	void				_RudeNode1();
89c80c5077SAxel Dörfler	virtual	void				_RudeNode2();
90c80c5077SAxel Dörfler	virtual	void				_RudeNode3();
91c80c5077SAxel Dörfler	virtual	void				_RudeNode4();
92c80c5077SAxel Dörfler	virtual	void				_RudeNode5();
93c80c5077SAxel Dörfler	virtual	void				_RudeNode6();
96c80c5077SAxel Dörfler			status_t			set_fd(int fd);
97c80c5077SAxel Dörfler	virtual	void				close_fd();
98c80c5077SAxel Dörfler			void				set_status(status_t newStatus);
100c80c5077SAxel Dörfler			status_t			_SetTo(int fd, const char* path, bool traverse);
101c80c5077SAxel Dörfler			status_t			_SetTo(const entry_ref* ref, bool traverse);
102db10640dSIngo Weinhold
103a30a4a41SJohn Scipione	virtual	status_t			set_stat(struct stat& stat, uint32 what);
105a30a4a41SJohn Scipione			status_t			_GetStat(struct stat* stat) const;
106a30a4a41SJohn Scipione	virtual	status_t			_GetStat(struct stat_beos* stat) const;
107c80c5077SAxel Dörfler			status_t			InitAttrDir();
10842c9b01aSIngo Weinhold
10942c9b01aSIngo Weinholdprivate:
110c80c5077SAxel Dörfler			uint32				rudeData[4];
111c80c5077SAxel Dörfler			int					fFd;
112a30a4a41SJohn Scipione				// Ffile descriptor for the given node
113c80c5077SAxel Dörfler			int					fAttrFd;
114a30a4a41SJohn Scipione				// file descriptor for the attribute directory of the node,
115a30a4a41SJohn Scipione				// initialized lazily
116c80c5077SAxel Dörfler			status_t			fCStatus;
117a30a4a41SJohn Scipione				// the node's initialization status
120c80c5077SAxel Dörfler
12182b75665STyler Dauwalder#endif	// _NODE_H