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