1f9d99406SAxel Dörfler/*
2b9216114SAxel Dörfler * Copyright 2002-2008, Haiku, Inc. All Rights Reserved.
3f9d99406SAxel Dörfler * Distributed under the terms of the MIT License.
4f9d99406SAxel Dörfler */
5338b8dc3SIngo Weinhold#ifndef _NODE_H
6338b8dc3SIngo Weinhold#define _NODE_H
7338b8dc3SIngo Weinhold
8338b8dc3SIngo Weinhold
9f9d99406SAxel Dörfler#include <Statable.h>
10338b8dc3SIngo Weinhold
11f9d99406SAxel Dörflerclass BDirectory;
12a1f8d8a1SIngo Weinholdclass BEntry;
13a1f8d8a1SIngo Weinholdclass BString;
14a1f8d8a1SIngo Weinholdstruct entry_ref;
15338b8dc3SIngo Weinhold
16338b8dc3SIngo Weinhold//! Reference structure to a particular vnode on a particular device
17338b8dc3SIngo Weinhold/*! <b>node_ref</b> - A node reference.
18338b8dc3SIngo Weinhold
19338b8dc3SIngo Weinhold	@author <a href="mailto:tylerdauwalder@users.sf.net">Tyler Dauwalder</a>
20338b8dc3SIngo Weinhold	@author Be Inc.
21338b8dc3SIngo Weinhold	@version 0.0.0
22338b8dc3SIngo Weinhold*/
23338b8dc3SIngo Weinholdstruct node_ref {
24a1f8d8a1SIngo Weinhold	node_ref();
25338b8dc3SIngo Weinhold	node_ref(const node_ref &ref);
26f9d99406SAxel Dörfler
27338b8dc3SIngo Weinhold	bool operator==(const node_ref &ref) const;
28338b8dc3SIngo Weinhold	bool operator!=(const node_ref &ref) const;
29338b8dc3SIngo Weinhold	node_ref& operator=(const node_ref &ref);
30338b8dc3SIngo Weinhold
31338b8dc3SIngo Weinhold	bool operator<(const node_ref &ref) const
32338b8dc3SIngo Weinhold	{
33b9216114SAxel Dörfler		return device < ref.device
34b9216114SAxel Dörfler			|| (device == ref.device && node < ref.node);
35338b8dc3SIngo Weinhold	}
36f9d99406SAxel Dörfler
37338b8dc3SIngo Weinhold	dev_t device;
38338b8dc3SIngo Weinhold	ino_t node;
39338b8dc3SIngo Weinhold};
40338b8dc3SIngo Weinhold
41338b8dc3SIngo Weinhold
42338b8dc3SIngo Weinhold//! A BNode represents a chunk of data in the filesystem.
43338b8dc3SIngo Weinhold/*! The BNode class provides an interface for manipulating the data and attributes
44338b8dc3SIngo Weinhold	belonging to filesystem entries. The BNode is unaware of the name that refers
45338b8dc3SIngo Weinhold	to it in the filesystem (i.e. its entry); a BNode is solely concerned with
46338b8dc3SIngo Weinhold	the entry's data and attributes.
47338b8dc3SIngo Weinhold
48338b8dc3SIngo Weinhold
49338b8dc3SIngo Weinhold	@author <a href='mailto:tylerdauwalder@users.sf.net'>Tyler Dauwalder</a>
50338b8dc3SIngo Weinhold	@version 0.0.0
51338b8dc3SIngo Weinhold
52338b8dc3SIngo Weinhold*/
53338b8dc3SIngo Weinholdclass BNode : public BStatable {
54338b8dc3SIngo Weinholdpublic:
55338b8dc3SIngo Weinhold	BNode();
56338b8dc3SIngo Weinhold	BNode(const entry_ref *ref);
57338b8dc3SIngo Weinhold	BNode(const BEntry *entry);
58338b8dc3SIngo Weinhold	BNode(const char *path);
59338b8dc3SIngo Weinhold	BNode(const BDirectory *dir, const char *path);
60338b8dc3SIngo Weinhold	BNode(const BNode &node);
61338b8dc3SIngo Weinhold	virtual ~BNode();
62338b8dc3SIngo Weinhold
63338b8dc3SIngo Weinhold	status_t InitCheck() const;
64338b8dc3SIngo Weinhold
65338b8dc3SIngo Weinhold	virtual status_t GetStat(struct stat *st) const;
66338b8dc3SIngo Weinhold
67338b8dc3SIngo Weinhold	status_t SetTo(const entry_ref *ref);
68338b8dc3SIngo Weinhold	status_t SetTo(const BEntry *entry);
69338b8dc3SIngo Weinhold	status_t SetTo(const char *path);
70338b8dc3SIngo Weinhold	status_t SetTo(const BDirectory *dir, const char *path);
71338b8dc3SIngo Weinhold	void Unset();
72338b8dc3SIngo Weinhold
73338b8dc3SIngo Weinhold	status_t Lock();
74338b8dc3SIngo Weinhold	status_t Unlock();
75338b8dc3SIngo Weinhold
76338b8dc3SIngo Weinhold	status_t Sync();
77338b8dc3SIngo Weinhold
78338b8dc3SIngo Weinhold	ssize_t WriteAttr(const char *name, type_code type, off_t offset,
79338b8dc3SIngo Weinhold		const void *buffer, size_t len);
80338b8dc3SIngo Weinhold	ssize_t ReadAttr(const char *name, type_code type, off_t offset,
81338b8dc3SIngo Weinhold		void *buffer, size_t len) const;
82338b8dc3SIngo Weinhold	status_t RemoveAttr(const char *name);
83338b8dc3SIngo Weinhold	status_t RenameAttr(const char *oldname, const char *newname);
84338b8dc3SIngo Weinhold	status_t GetAttrInfo(const char *name, struct attr_info *info) const;
85338b8dc3SIngo Weinhold	status_t GetNextAttrName(char *buffer);
86338b8dc3SIngo Weinhold	status_t RewindAttrs();
87338b8dc3SIngo Weinhold	status_t WriteAttrString(const char *name, const BString *data);
88338b8dc3SIngo Weinhold	status_t ReadAttrString(const char *name, BString *result) const;
89338b8dc3SIngo Weinhold
90338b8dc3SIngo Weinhold	BNode& operator=(const BNode &node);
91338b8dc3SIngo Weinhold	bool operator==(const BNode &node) const;
92338b8dc3SIngo Weinhold	bool operator!=(const BNode &node) const;
93338b8dc3SIngo Weinhold
94338b8dc3SIngo Weinhold	int Dup();  // This should be "const" but R5's is not... Ugggh.
95338b8dc3SIngo Weinhold
96338b8dc3SIngo Weinholdprivate:
97338b8dc3SIngo Weinhold	friend class BFile;
98338b8dc3SIngo Weinhold	friend class BDirectory;
99338b8dc3SIngo Weinhold	friend class BSymLink;
100338b8dc3SIngo Weinhold
101a1f8d8a1SIngo Weinhold	virtual void _RudeNode1();
102338b8dc3SIngo Weinhold	virtual void _RudeNode2();
103338b8dc3SIngo Weinhold	virtual void _RudeNode3();
104338b8dc3SIngo Weinhold	virtual void _RudeNode4();
105338b8dc3SIngo Weinhold	virtual void _RudeNode5();
106338b8dc3SIngo Weinhold	virtual void _RudeNode6();
107338b8dc3SIngo Weinhold
108338b8dc3SIngo Weinhold	uint32 rudeData[4];
109338b8dc3SIngo Weinhold
110338b8dc3SIngo Weinholdprivate:
111338b8dc3SIngo Weinhold	status_t set_fd(int fd);
112338b8dc3SIngo Weinhold	virtual void close_fd();
113338b8dc3SIngo Weinhold	void set_status(status_t newStatus);
114338b8dc3SIngo Weinhold
115338b8dc3SIngo Weinhold	status_t _SetTo(int fd, const char *path, bool traverse);
116338b8dc3SIngo Weinhold	status_t _SetTo(const entry_ref *ref, bool traverse);
117338b8dc3SIngo Weinhold
118338b8dc3SIngo Weinhold	virtual status_t set_stat(struct stat &st, uint32 what);
119338b8dc3SIngo Weinhold
120338b8dc3SIngo Weinhold	int fFd;
121338b8dc3SIngo Weinhold	int fAttrFd;
122338b8dc3SIngo Weinhold	status_t fCStatus;
123338b8dc3SIngo Weinhold
124338b8dc3SIngo Weinhold	status_t InitAttrDir();
125338b8dc3SIngo Weinhold};
126338b8dc3SIngo Weinhold
127338b8dc3SIngo Weinhold#endif	// _NODE_H
128