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