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 BFile; 14 class BSymLink; 15 16 17 class BDirectory : public BNode, public BEntryList { 18 public: 19 BDirectory(); 20 BDirectory(const BDirectory &dir); 21 BDirectory(const entry_ref *ref); 22 BDirectory(const node_ref *nref); 23 BDirectory(const BEntry *entry); 24 BDirectory(const char *path); 25 BDirectory(const BDirectory *dir, const char *path); 26 27 virtual ~BDirectory(); 28 29 status_t SetTo(const entry_ref *ref); 30 status_t SetTo(const node_ref *nref); 31 status_t SetTo(const BEntry *entry); 32 status_t SetTo(const char *path); 33 status_t SetTo(const BDirectory *dir, const char *path); 34 35 status_t GetEntry(BEntry *entry) const; 36 37 bool IsRootDirectory() 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 private: 79 uint32 _reservedData[7]; 80 int fDirFd; 81 }; 82 83 status_t create_directory(const char *path, mode_t mode); 84 85 #endif // _DIRECTORY_H 86