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