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