1/*
2 * Copyright 2002-2006, Haiku, Inc. All Rights Reserved.
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#include <EntryList.h>
11#include <StorageDefs.h>
12
13
14class BFile;
15class BSymLink;
16struct stat_beos;
17
18
19class BDirectory : public BNode, public BEntryList {
20	public:
21		BDirectory();
22		BDirectory(const BDirectory &dir);
23		BDirectory(const entry_ref *ref);
24		BDirectory(const node_ref *nref);
25		BDirectory(const BEntry *entry);
26		BDirectory(const char *path);
27		BDirectory(const BDirectory *dir, const char *path);
28
29		virtual ~BDirectory();
30
31		status_t SetTo(const entry_ref *ref);
32		status_t SetTo(const node_ref *nref);
33		status_t SetTo(const BEntry *entry);
34		status_t SetTo(const char *path);
35		status_t SetTo(const BDirectory *dir, const char *path);
36
37		status_t GetEntry(BEntry *entry) const;
38
39		bool IsRootDirectory() const;
40
41		status_t FindEntry(const char *path, BEntry *entry,
42			bool traverse = false) const;
43
44		bool Contains(const char *path, int32 nodeFlags = B_ANY_NODE) const;
45		bool Contains(const BEntry *entry, int32 nodeFlags = B_ANY_NODE) const;
46
47		status_t GetStatFor(const char *path, struct stat *st) const;
48
49		virtual status_t GetNextEntry(BEntry *entry, bool traverse = false);
50		virtual status_t GetNextRef(entry_ref *ref);
51		virtual int32 GetNextDirents(dirent *buf, size_t bufSize,
52			int32 count = INT_MAX);
53		virtual status_t Rewind();
54		virtual int32 CountEntries();
55
56		status_t CreateDirectory(const char *path, BDirectory *dir);
57		status_t CreateFile(const char *path, BFile *file,
58			bool failIfExists = false);
59		status_t CreateSymLink(const char *path, const char *linkToPath,
60			BSymLink *link);
61
62		BDirectory &operator=(const BDirectory &dir);
63
64	private:
65		friend class BNode;
66		friend class BEntry;
67		friend class BFile;
68
69		status_t _GetStatFor(const char *path, struct stat *st) const;
70		status_t _GetStatFor(const char *path, struct stat_beos *st) const;
71
72		virtual void _ErectorDirectory1();
73		virtual void _ErectorDirectory2();
74		virtual void _ErectorDirectory3();
75		virtual void _ErectorDirectory4();
76		virtual void _ErectorDirectory5();
77		virtual void _ErectorDirectory6();
78
79	private:
80		virtual void close_fd();
81		int get_fd() const;
82
83	private:
84		uint32 _reservedData[7];
85		int fDirFd;
86};
87
88status_t create_directory(const char *path, mode_t mode);
89
90#endif	// _DIRECTORY_H
91