1/*
2 * Copyright 2007, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * All rights reserved. Distributed under the terms of the MIT license.
4 */
5#ifndef DIRECTORY_H
6#define DIRECTORY_H
7
8#include <util/DoublyLinkedList.h>
9
10#include "Node.h"
11
12
13class Entry;
14class File;
15class SymLink;
16
17class Directory : public Node {
18public:
19	Directory(Volume *volume);
20	virtual ~Directory();
21
22	virtual status_t Link(Entry *entry);
23	virtual status_t Unlink(Entry *entry);
24
25	virtual status_t SetSize(off_t newSize);
26	virtual off_t GetSize() const;
27
28	Directory *GetParent() const;
29
30	status_t CreateDirectory(const char *name, Directory **directory);
31	status_t CreateFile(const char *name, File **file);
32	status_t CreateSymLink(const char *name, const char *path,
33						   SymLink **symLink);
34
35	bool IsEmpty() const { return fEntries.IsEmpty(); }
36
37	status_t AddEntry(Entry *entry);
38	status_t CreateEntry(Node *node, const char *name, Entry **entry = NULL);
39	status_t RemoveEntry(Entry *entry);
40	status_t DeleteEntry(Entry *entry);
41
42	status_t FindEntry(const char *name, Entry **entry) const;
43	status_t FindNode(const char *name, Node **node) const;
44	status_t FindAndGetNode(const char *name, Node **node,
45							Entry **entry = NULL) const;
46
47	status_t GetPreviousEntry(Entry **entry) const;
48	status_t GetNextEntry(Entry **entry) const;
49
50	// debugging
51	virtual void GetAllocationInfo(AllocationInfo &info);
52
53private:
54	status_t _CreateCommon(Node *node, const char *name);
55
56private:
57	DoublyLinkedList<Entry>	fEntries;
58};
59
60#endif	// DIRECTORY_H
61