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