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 39*ec21dc91SAugustin Cavalier bool IsRootDirectory() const; 40*ec21dc91SAugustin Cavalier 41338b8dc3SIngo Weinhold status_t FindEntry(const char *path, BEntry *entry, 42338b8dc3SIngo Weinhold bool traverse = false) const; 43338b8dc3SIngo Weinhold 44338b8dc3SIngo Weinhold bool Contains(const char *path, int32 nodeFlags = B_ANY_NODE) const; 45338b8dc3SIngo Weinhold bool Contains(const BEntry *entry, int32 nodeFlags = B_ANY_NODE) const; 46338b8dc3SIngo Weinhold 47338b8dc3SIngo Weinhold status_t GetStatFor(const char *path, struct stat *st) const; 48338b8dc3SIngo Weinhold 49338b8dc3SIngo Weinhold virtual status_t GetNextEntry(BEntry *entry, bool traverse = false); 50338b8dc3SIngo Weinhold virtual status_t GetNextRef(entry_ref *ref); 51338b8dc3SIngo Weinhold virtual int32 GetNextDirents(dirent *buf, size_t bufSize, 52338b8dc3SIngo Weinhold int32 count = INT_MAX); 53338b8dc3SIngo Weinhold virtual status_t Rewind(); 54338b8dc3SIngo Weinhold virtual int32 CountEntries(); 55338b8dc3SIngo Weinhold 56338b8dc3SIngo Weinhold status_t CreateDirectory(const char *path, BDirectory *dir); 57338b8dc3SIngo Weinhold status_t CreateFile(const char *path, BFile *file, 58338b8dc3SIngo Weinhold bool failIfExists = false); 59338b8dc3SIngo Weinhold status_t CreateSymLink(const char *path, const char *linkToPath, 60338b8dc3SIngo Weinhold BSymLink *link); 61338b8dc3SIngo Weinhold 62338b8dc3SIngo Weinhold BDirectory &operator=(const BDirectory &dir); 63338b8dc3SIngo Weinhold 64338b8dc3SIngo Weinhold private: 65338b8dc3SIngo Weinhold friend class BNode; 66*ec21dc91SAugustin Cavalier friend class BEntry; 67*ec21dc91SAugustin Cavalier friend class BFile; 68338b8dc3SIngo Weinhold 69338b8dc3SIngo Weinhold virtual void _ErectorDirectory1(); 70338b8dc3SIngo Weinhold virtual void _ErectorDirectory2(); 71338b8dc3SIngo Weinhold virtual void _ErectorDirectory3(); 72338b8dc3SIngo Weinhold virtual void _ErectorDirectory4(); 73338b8dc3SIngo Weinhold virtual void _ErectorDirectory5(); 74338b8dc3SIngo Weinhold virtual void _ErectorDirectory6(); 75338b8dc3SIngo Weinhold 76338b8dc3SIngo Weinhold private: 77338b8dc3SIngo Weinhold virtual void close_fd(); 78338b8dc3SIngo Weinhold int get_fd() const; 79338b8dc3SIngo Weinhold 80338b8dc3SIngo Weinhold status_t set_dir_fd(int fd); 81338b8dc3SIngo Weinhold 82338b8dc3SIngo Weinhold private: 83338b8dc3SIngo Weinhold uint32 _reservedData[7]; 84338b8dc3SIngo Weinhold int fDirFd; 85338b8dc3SIngo Weinhold node_ref fDirNodeRef; 86338b8dc3SIngo Weinhold }; 87338b8dc3SIngo Weinhold 88338b8dc3SIngo Weinhold status_t create_directory(const char *path, mode_t mode); 89338b8dc3SIngo Weinhold 90338b8dc3SIngo Weinhold #endif // _DIRECTORY_H 91