1 #ifndef FS_DESCRIPTORS_H 2 #define FS_DESCRIPTORS_H 3 4 #include <dirent.h> 5 6 #include <string> 7 8 #include <SupportDefs.h> 9 10 #include "NodeRef.h" 11 12 using std::string; 13 14 struct stat; 15 16 namespace BPrivate { 17 18 // Descriptor 19 struct Descriptor { 20 int fd; 21 22 virtual ~Descriptor(); 23 24 virtual status_t Close() = 0; 25 virtual status_t Dup(Descriptor *&clone) = 0; 26 virtual status_t GetStat(bool traverseLink, struct stat *st) = 0; 27 28 virtual bool IsSystemFD() const; 29 virtual status_t GetPath(string& path) const; 30 31 virtual status_t GetNodeRef(NodeRef &ref); 32 }; 33 34 // FileDescriptor 35 struct FileDescriptor : Descriptor { 36 FileDescriptor(int fd); 37 virtual ~FileDescriptor(); 38 39 virtual status_t Close(); 40 virtual status_t Dup(Descriptor *&clone); 41 virtual status_t GetStat(bool traverseLink, struct stat *st); 42 43 virtual bool IsSystemFD() const; 44 }; 45 46 // DirectoryDescriptor 47 struct DirectoryDescriptor : Descriptor { 48 DIR *dir; 49 NodeRef ref; 50 51 DirectoryDescriptor(DIR *dir, const NodeRef &ref); 52 virtual ~DirectoryDescriptor(); 53 54 virtual status_t Close(); 55 virtual status_t Dup(Descriptor *&clone); 56 virtual status_t GetStat(bool traverseLink, struct stat *st); 57 58 virtual status_t GetNodeRef(NodeRef &ref); 59 }; 60 61 // SymlinkDescriptor 62 struct SymlinkDescriptor : Descriptor { 63 string path; 64 65 SymlinkDescriptor(const char *path); 66 67 virtual status_t Close(); 68 virtual status_t Dup(Descriptor *&clone); 69 virtual status_t GetStat(bool traverseLink, struct stat *st); 70 71 virtual status_t GetPath(string& path) const; 72 }; 73 74 // AttrDirDescriptor 75 struct AttrDirDescriptor : DirectoryDescriptor { 76 77 AttrDirDescriptor(DIR *dir, const NodeRef &ref); 78 virtual ~AttrDirDescriptor(); 79 80 virtual status_t Close(); 81 virtual status_t Dup(Descriptor *&clone); 82 virtual status_t GetStat(bool traverseLink, struct stat *st); 83 84 virtual status_t GetNodeRef(NodeRef &ref); 85 }; 86 87 88 Descriptor* get_descriptor(int fd); 89 int add_descriptor(Descriptor *descriptor); 90 status_t delete_descriptor(int fd); 91 92 } // namespace BPrivate 93 94 #endif // FS_DESCRIPTORS_H 95