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