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