1 // Node.h 2 3 #ifndef NODE_H 4 #define NODE_H 5 6 #include <fs_interface.h> 7 #include <NodeMonitor.h> 8 9 #include "Attribute.h" 10 #include "Entry.h" 11 #include "String.h" 12 13 class AllocationInfo; 14 class AttributeIterator; 15 class Directory; 16 class Volume; 17 18 // node type 19 enum { 20 NODE_TYPE_DIRECTORY, 21 NODE_TYPE_FILE, 22 NODE_TYPE_SYMLINK, 23 }; 24 25 // access modes 26 enum { 27 ACCESS_R = S_IROTH, 28 ACCESS_W = S_IWOTH, 29 ACCESS_X = S_IXOTH, 30 }; 31 32 class Node : public DoublyLinkedListLinkImpl<Node> { 33 public: 34 Node(Volume *volume, uint8 type); 35 virtual ~Node(); 36 37 virtual status_t InitCheck() const; 38 39 inline void SetVolume(Volume *volume) { fVolume = volume; } 40 inline Volume *GetVolume() const { return fVolume; } 41 42 inline ino_t GetID() const { return fID; } 43 44 status_t AddReference(); 45 void RemoveReference(); 46 int32 GetRefCount() { return fRefCount; } 47 48 virtual status_t Link(Entry *entry); 49 virtual status_t Unlink(Entry *entry); 50 51 inline bool IsDirectory() const { return S_ISDIR(fMode); } 52 inline bool IsFile() const { return S_ISREG(fMode); } 53 inline bool IsSymLink() const { return S_ISLNK(fMode); } 54 55 virtual status_t SetSize(off_t newSize) = 0; 56 virtual off_t GetSize() const = 0; 57 58 // stat data 59 60 inline void SetMode(mode_t mode) 61 { fMode = (fMode & ~S_IUMSK) | (mode & S_IUMSK); } 62 inline mode_t GetMode() const { return fMode; } 63 64 inline void SetUID(uid_t uid) { fUID = uid; MarkModified(B_STAT_UID); } 65 inline uid_t GetUID() const { return fUID; } 66 67 inline void SetGID(uid_t gid) { fGID = gid; MarkModified(B_STAT_GID); } 68 inline uid_t GetGID() const { return fGID; } 69 70 inline void SetATime(time_t aTime) { fATime = aTime; } 71 inline time_t GetATime() const { return fATime; } 72 73 void SetMTime(time_t mTime); 74 inline time_t GetMTime() const { return fMTime; } 75 76 inline void SetCTime(time_t cTime) { fCTime = cTime; } 77 inline time_t GetCTime() const { return fCTime; } 78 79 inline void SetCrTime(time_t crTime) { fCrTime = crTime; } 80 inline time_t GetCrTime() const { return fCrTime; } 81 82 inline void MarkModified(uint32 flags) { fModified |= flags; } 83 inline uint32 MarkUnmodified(); 84 inline bool IsModified() const { return fModified; } 85 86 status_t CheckPermissions(int mode) const; 87 88 bool IsKnownToVFS() const { return fIsKnownToVFS; } 89 90 // attributes 91 status_t CreateAttribute(const char *name, Attribute **attribute); 92 status_t DeleteAttribute(Attribute *attribute); 93 status_t AddAttribute(Attribute *attribute); 94 status_t RemoveAttribute(Attribute *attribute); 95 96 status_t FindAttribute(const char *name, Attribute **attribute) const; 97 98 status_t GetPreviousAttribute(Attribute **attribute) const; 99 status_t GetNextAttribute(Attribute **attribute) const; 100 101 Entry *GetFirstReferrer() const; 102 Entry *GetLastReferrer() const; 103 Entry *GetPreviousReferrer(Entry *entry) const; 104 Entry *GetNextReferrer(Entry *entry) const; 105 106 // debugging 107 virtual void GetAllocationInfo(AllocationInfo &info); 108 109 private: 110 Volume *fVolume; 111 ino_t fID; 112 int32 fRefCount; 113 mode_t fMode; 114 uid_t fUID; 115 uid_t fGID; 116 time_t fATime; 117 time_t fMTime; 118 time_t fCTime; 119 time_t fCrTime; 120 uint32 fModified; 121 bool fIsKnownToVFS; 122 123 // attribute management 124 DoublyLinkedList<Attribute> fAttributes; 125 126 protected: 127 // entries referring to this node 128 DoublyLinkedList<Entry, GetNodeReferrerLink> fReferrers; 129 }; 130 131 // MarkUnmodified 132 inline 133 uint32 134 Node::MarkUnmodified() 135 { 136 uint32 modified = fModified; 137 if (modified) { 138 fCTime = time(NULL); 139 SetMTime(fCTime); 140 fModified = 0; 141 } 142 return modified; 143 } 144 145 // open_mode_to_access 146 inline static 147 int 148 open_mode_to_access(int openMode) 149 { 150 switch (openMode & O_RWMASK) { 151 case O_RDONLY: 152 return ACCESS_R; 153 case O_WRONLY: 154 return ACCESS_W; 155 case O_RDWR: 156 return ACCESS_R | ACCESS_W; 157 } 158 return 0; 159 } 160 161 162 // NodeMTimeUpdater 163 class NodeMTimeUpdater { 164 public: 165 NodeMTimeUpdater(Node *node) : fNode(node) {} 166 ~NodeMTimeUpdater() 167 { 168 if (fNode && fNode->IsModified()) 169 fNode->MarkUnmodified(); 170 } 171 172 private: 173 Node *fNode; 174 }; 175 176 #endif // NODE_H 177