1*ec21dc91SAugustin Cavalier /* 2*ec21dc91SAugustin Cavalier * Copyright 2002-2006, Haiku, Inc. All Rights Reserved. 3*ec21dc91SAugustin Cavalier * Distributed under the terms of the MIT License. 4338b8dc3SIngo Weinhold */ 5338b8dc3SIngo Weinhold #ifndef _DIRECTORY_H 6338b8dc3SIngo Weinhold #define _DIRECTORY_H 7338b8dc3SIngo Weinhold 8*ec21dc91SAugustin Cavalier 9338b8dc3SIngo Weinhold #include <Node.h> 10338b8dc3SIngo Weinhold #include <EntryList.h> 11338b8dc3SIngo Weinhold #include <StorageDefs.h> 12338b8dc3SIngo Weinhold 13338b8dc3SIngo Weinhold 14a1f8d8a1SIngo Weinhold class BFile; 15338b8dc3SIngo Weinhold class BSymLink; 16*ec21dc91SAugustin Cavalier struct stat_beos; 17338b8dc3SIngo Weinhold 18338b8dc3SIngo Weinhold 19338b8dc3SIngo Weinhold class BDirectory : public BNode, public BEntryList { 20338b8dc3SIngo Weinhold public: 21338b8dc3SIngo Weinhold BDirectory(); 22338b8dc3SIngo Weinhold BDirectory(const BDirectory &dir); 23338b8dc3SIngo Weinhold BDirectory(const entry_ref *ref); 24338b8dc3SIngo Weinhold BDirectory(const node_ref *nref); 25338b8dc3SIngo Weinhold BDirectory(const BEntry *entry); 26338b8dc3SIngo Weinhold BDirectory(const char *path); 27338b8dc3SIngo Weinhold BDirectory(const BDirectory *dir, const char *path); 28338b8dc3SIngo Weinhold 29338b8dc3SIngo Weinhold virtual ~BDirectory(); 30338b8dc3SIngo Weinhold 31338b8dc3SIngo Weinhold status_t SetTo(const entry_ref *ref); 32338b8dc3SIngo Weinhold status_t SetTo(const node_ref *nref); 33338b8dc3SIngo Weinhold status_t SetTo(const BEntry *entry); 34338b8dc3SIngo Weinhold status_t SetTo(const char *path); 35338b8dc3SIngo Weinhold status_t SetTo(const BDirectory *dir, const char *path); 36338b8dc3SIngo Weinhold 37338b8dc3SIngo Weinhold status_t GetEntry(BEntry *entry) const; 38338b8dc3SIngo Weinhold 39338b8dc3SIngo Weinhold status_t FindEntry(const char *path, BEntry *entry, 40338b8dc3SIngo Weinhold bool traverse = false) const; 41338b8dc3SIngo Weinhold 42338b8dc3SIngo Weinhold bool Contains(const char *path, int32 nodeFlags = B_ANY_NODE) const; 43338b8dc3SIngo Weinhold bool Contains(const BEntry *entry, int32 nodeFlags = B_ANY_NODE) const; 44338b8dc3SIngo Weinhold 45338b8dc3SIngo Weinhold status_t GetStatFor(const char *path, struct stat *st) const; 46338b8dc3SIngo Weinhold 47338b8dc3SIngo Weinhold virtual status_t GetNextEntry(BEntry *entry, bool traverse = false); 48338b8dc3SIngo Weinhold virtual status_t GetNextRef(entry_ref *ref); 49338b8dc3SIngo Weinhold virtual int32 GetNextDirents(dirent *buf, size_t bufSize, 50338b8dc3SIngo Weinhold int32 count = INT_MAX); 51338b8dc3SIngo Weinhold virtual status_t Rewind(); 52338b8dc3SIngo Weinhold virtual int32 CountEntries(); 53338b8dc3SIngo Weinhold 54338b8dc3SIngo Weinhold status_t CreateDirectory(const char *path, BDirectory *dir); 55338b8dc3SIngo Weinhold status_t CreateFile(const char *path, BFile *file, 56338b8dc3SIngo Weinhold bool failIfExists = false); 57338b8dc3SIngo Weinhold status_t CreateSymLink(const char *path, const char *linkToPath, 58338b8dc3SIngo Weinhold BSymLink *link); 59338b8dc3SIngo Weinhold 60338b8dc3SIngo Weinhold BDirectory &operator=(const BDirectory &dir); 61338b8dc3SIngo Weinhold 62338b8dc3SIngo Weinhold private: 63338b8dc3SIngo Weinhold friend class BNode; 64*ec21dc91SAugustin Cavalier friend class BEntry; 65*ec21dc91SAugustin Cavalier friend class BFile; 66338b8dc3SIngo Weinhold 67338b8dc3SIngo Weinhold virtual void _ErectorDirectory1(); 68338b8dc3SIngo Weinhold virtual void _ErectorDirectory2(); 69338b8dc3SIngo Weinhold virtual void _ErectorDirectory3(); 70338b8dc3SIngo Weinhold virtual void _ErectorDirectory4(); 71338b8dc3SIngo Weinhold virtual void _ErectorDirectory5(); 72338b8dc3SIngo Weinhold virtual void _ErectorDirectory6(); 73338b8dc3SIngo Weinhold 74338b8dc3SIngo Weinhold private: 75338b8dc3SIngo Weinhold virtual void close_fd(); 76338b8dc3SIngo Weinhold int get_fd() const; 77338b8dc3SIngo Weinhold 78338b8dc3SIngo Weinhold status_t set_dir_fd(int fd); 79338b8dc3SIngo Weinhold 80338b8dc3SIngo Weinhold private: 81338b8dc3SIngo Weinhold uint32 _reservedData[7]; 82338b8dc3SIngo Weinhold int fDirFd; 83338b8dc3SIngo Weinhold node_ref fDirNodeRef; 84338b8dc3SIngo Weinhold }; 85338b8dc3SIngo Weinhold 86338b8dc3SIngo Weinhold status_t create_directory(const char *path, mode_t mode); 87338b8dc3SIngo Weinhold 88338b8dc3SIngo Weinhold #endif // _DIRECTORY_H 89