xref: /haiku/src/add-ons/kernel/file_systems/packagefs/nodes/Directory.h (revision 9a6a20d4689307142a7ed26a1437ba47e244e73f)
1 /*
2  * Copyright 2009-2011, Ingo Weinhold, ingo_weinhold@gmx.de.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef DIRECTORY_H
6 #define DIRECTORY_H
7 
8 
9 #include "Node.h"
10 
11 
12 struct DirectoryIterator : DoublyLinkedListLinkImpl<DirectoryIterator> {
13 	Node*	node;
14 
15 	DirectoryIterator()
16 		:
17 		node(NULL)
18 	{
19 	}
20 };
21 
22 typedef DoublyLinkedList<DirectoryIterator> DirectoryIteratorList;
23 
24 
25 class Directory : public Node {
26 public:
27 								Directory(ino_t id);
28 	virtual						~Directory();
29 
30 	virtual	status_t			Init(const String& name);
31 
32 	virtual	mode_t				Mode() const;
33 	virtual	off_t				FileSize() const;
34 
35 	virtual	status_t			Read(off_t offset, void* buffer,
36 									size_t* bufferSize);
37 	virtual	status_t			Read(io_request* request);
38 
39 	virtual	status_t			ReadSymlink(void* buffer, size_t* bufferSize);
40 
41 			void				AddChild(Node* node);
42 			void				RemoveChild(Node* node);
43 			Node*				FindChild(const StringKey& name);
44 
45 	inline	Node*				FirstChild() const;
46 	inline	Node*				NextChild(Node* node) const;
47 
48 			void				AddDirectoryIterator(
49 									DirectoryIterator* iterator);
50 			void				RemoveDirectoryIterator(
51 									DirectoryIterator* iterator);
52 
53 private:
54 			NodeNameHashTable	fChildTable;
55 			NodeList			fChildList;
56 			DirectoryIteratorList fIterators;
57 };
58 
59 
60 Node*
61 Directory::FirstChild() const
62 {
63 	return fChildList.First();
64 }
65 
66 
67 Node*
68 Directory::NextChild(Node* node) const
69 {
70 	return fChildList.GetNext(node);
71 }
72 
73 
74 #endif	// DIRECTORY_H
75