xref: /haiku/headers/build/os/storage/Directory.h (revision ed24eb5ff12640d052171c6a7feba37fab8a75d1)
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 
14 class BFile;
15 class BSymLink;
16 struct stat_beos;
17 
18 
19 class 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 		status_t FindEntry(const char *path, BEntry *entry,
40 			bool traverse = false) const;
41 
42 		bool Contains(const char *path, int32 nodeFlags = B_ANY_NODE) const;
43 		bool Contains(const BEntry *entry, int32 nodeFlags = B_ANY_NODE) const;
44 
45 		status_t GetStatFor(const char *path, struct stat *st) const;
46 
47 		virtual status_t GetNextEntry(BEntry *entry, bool traverse = false);
48 		virtual status_t GetNextRef(entry_ref *ref);
49 		virtual int32 GetNextDirents(dirent *buf, size_t bufSize,
50 			int32 count = INT_MAX);
51 		virtual status_t Rewind();
52 		virtual int32 CountEntries();
53 
54 		status_t CreateDirectory(const char *path, BDirectory *dir);
55 		status_t CreateFile(const char *path, BFile *file,
56 			bool failIfExists = false);
57 		status_t CreateSymLink(const char *path, const char *linkToPath,
58 			BSymLink *link);
59 
60 		BDirectory &operator=(const BDirectory &dir);
61 
62 	private:
63 		friend class BNode;
64 		friend class BEntry;
65 		friend class BFile;
66 
67 		virtual void _ErectorDirectory1();
68 		virtual void _ErectorDirectory2();
69 		virtual void _ErectorDirectory3();
70 		virtual void _ErectorDirectory4();
71 		virtual void _ErectorDirectory5();
72 		virtual void _ErectorDirectory6();
73 
74 	private:
75 		virtual void close_fd();
76 		int get_fd() const;
77 
78 		status_t set_dir_fd(int fd);
79 
80 	private:
81 		uint32 _reservedData[7];
82 		int fDirFd;
83 		node_ref fDirNodeRef;
84 };
85 
86 status_t create_directory(const char *path, mode_t mode);
87 
88 #endif	// _DIRECTORY_H
89