xref: /haiku/headers/os/storage/Node.h (revision 204dee708a999d5a71d0cb9497650ee7cef85d0a)
1 /*
2  * Copyright 2002-2011, 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 
12 class BDirectory;
13 class BEntry;
14 class BString;
15 struct entry_ref;
16 
17 
18 struct node_ref {
19 	node_ref();
20 	node_ref(dev_t device, ino_t node);
21 	node_ref(const node_ref &ref);
22 
23 	bool operator==(const node_ref& ref) const;
24 	bool operator!=(const node_ref& ref) const;
25 	node_ref& operator=(const node_ref& ref);
26 
27 	dev_t device;
28 	ino_t node;
29 };
30 
31 
32 class BNode : public BStatable {
33 public:
34 								BNode();
35 								BNode(const entry_ref* ref);
36 								BNode(const BEntry* entry);
37 								BNode(const char* path);
38 								BNode(const BDirectory* dir, const char* path);
39 								BNode(const BNode& node);
40 	virtual						~BNode();
41 
42 			status_t			InitCheck() const;
43 
44 	virtual	status_t			GetStat(struct stat* st) const;
45 
46 			status_t			SetTo(const entry_ref* ref);
47 			status_t			SetTo(const BEntry* entry);
48 			status_t			SetTo(const char* path);
49 			status_t			SetTo(const BDirectory* dir, const char* path);
50 			void				Unset();
51 
52 			status_t			Lock();
53 			status_t			Unlock();
54 
55 			status_t			Sync();
56 
57 			ssize_t				WriteAttr(const char* name, type_code type,
58 									off_t offset, const void* buffer,
59 									size_t length);
60 			ssize_t				ReadAttr(const char* name, type_code type,
61 									off_t offset, void* buffer,
62 									size_t length) const;
63 			status_t			RemoveAttr(const char* name);
64 			status_t			RenameAttr(const char* oldName,
65 									const char* newName);
66 			status_t			GetAttrInfo(const char* name,
67 									struct attr_info* info) const;
68 			status_t			GetNextAttrName(char* buffer);
69 			status_t			RewindAttrs();
70 			status_t			WriteAttrString(const char* name,
71 									const BString* data);
72 			status_t			ReadAttrString(const char* name,
73 									BString* result) const;
74 
75 			BNode&				operator=(const BNode& node);
76 			bool				operator==(const BNode& node) const;
77 			bool				operator!=(const BNode& node) const;
78 
79 			int					Dup();
80 				// This should be "const" but R5's is not... Ugggh.
81 
82 private:
83 	friend class BFile;
84 	friend class BDirectory;
85 	friend class BSymLink;
86 
87 	virtual	void				_RudeNode1();
88 	virtual	void				_RudeNode2();
89 	virtual	void				_RudeNode3();
90 	virtual	void				_RudeNode4();
91 	virtual	void				_RudeNode5();
92 	virtual	void				_RudeNode6();
93 
94 private:
95 			status_t			set_fd(int fd);
96 	virtual	void				close_fd();
97 			void				set_status(status_t newStatus);
98 
99 			status_t			_SetTo(int fd, const char* path, bool traverse);
100 			status_t			_SetTo(const entry_ref* ref, bool traverse);
101 
102 	virtual	status_t			set_stat(struct stat& st, uint32 what);
103 
104 			status_t			_GetStat(struct stat* st) const;
105 	virtual	status_t			_GetStat(struct stat_beos* st) const;
106 			status_t			InitAttrDir();
107 
108 private:
109 			uint32				rudeData[4];
110 			int					fFd;
111 			int					fAttrFd;
112 			status_t			fCStatus;
113 };
114 
115 
116 #endif	// _NODE_H
117