1/*
2 * Copyright 2002-2008, 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
11class BDirectory;
12class BEntry;
13class BString;
14struct entry_ref;
15
16//! Reference structure to a particular vnode on a particular device
17/*! <b>node_ref</b> - A node reference.
18
19	@author <a href="mailto:tylerdauwalder@users.sf.net">Tyler Dauwalder</a>
20	@author Be Inc.
21	@version 0.0.0
22*/
23struct node_ref {
24	node_ref();
25	node_ref(const node_ref &ref);
26
27	bool operator==(const node_ref &ref) const;
28	bool operator!=(const node_ref &ref) const;
29	node_ref& operator=(const node_ref &ref);
30
31	bool operator<(const node_ref &ref) const
32	{
33		return device < ref.device
34			|| (device == ref.device && node < ref.node);
35	}
36
37	dev_t device;
38	ino_t node;
39};
40
41
42//! A BNode represents a chunk of data in the filesystem.
43/*! The BNode class provides an interface for manipulating the data and attributes
44	belonging to filesystem entries. The BNode is unaware of the name that refers
45	to it in the filesystem (i.e. its entry); a BNode is solely concerned with
46	the entry's data and attributes.
47
48
49	@author <a href='mailto:tylerdauwalder@users.sf.net'>Tyler Dauwalder</a>
50	@version 0.0.0
51
52*/
53class BNode : public BStatable {
54public:
55	BNode();
56	BNode(const entry_ref *ref);
57	BNode(const BEntry *entry);
58	BNode(const char *path);
59	BNode(const BDirectory *dir, const char *path);
60	BNode(const BNode &node);
61	virtual ~BNode();
62
63	status_t InitCheck() const;
64
65	virtual status_t GetStat(struct stat *st) const;
66
67	status_t SetTo(const entry_ref *ref);
68	status_t SetTo(const BEntry *entry);
69	status_t SetTo(const char *path);
70	status_t SetTo(const BDirectory *dir, const char *path);
71	void Unset();
72
73	status_t Lock();
74	status_t Unlock();
75
76	status_t Sync();
77
78	ssize_t WriteAttr(const char *name, type_code type, off_t offset,
79		const void *buffer, size_t len);
80	ssize_t ReadAttr(const char *name, type_code type, off_t offset,
81		void *buffer, size_t len) const;
82	status_t RemoveAttr(const char *name);
83	status_t RenameAttr(const char *oldname, const char *newname);
84	status_t GetAttrInfo(const char *name, struct attr_info *info) const;
85	status_t GetNextAttrName(char *buffer);
86	status_t RewindAttrs();
87	status_t WriteAttrString(const char *name, const BString *data);
88	status_t ReadAttrString(const char *name, BString *result) const;
89
90	BNode& operator=(const BNode &node);
91	bool operator==(const BNode &node) const;
92	bool operator!=(const BNode &node) const;
93
94	int Dup();  // This should be "const" but R5's is not... Ugggh.
95
96private:
97	friend class BFile;
98	friend class BDirectory;
99	friend class BSymLink;
100
101	virtual void _RudeNode1();
102	virtual void _RudeNode2();
103	virtual void _RudeNode3();
104	virtual void _RudeNode4();
105	virtual void _RudeNode5();
106	virtual void _RudeNode6();
107
108	uint32 rudeData[4];
109
110private:
111	status_t set_fd(int fd);
112	virtual void close_fd();
113	void set_status(status_t newStatus);
114
115	status_t _SetTo(int fd, const char *path, bool traverse);
116	status_t _SetTo(const entry_ref *ref, bool traverse);
117
118	virtual status_t set_stat(struct stat &st, uint32 what);
119
120	int fFd;
121	int fAttrFd;
122	status_t fCStatus;
123
124	status_t InitAttrDir();
125};
126
127#endif	// _NODE_H
128