1 // ShareVolume.h 2 3 #ifndef NET_FS_SHARE_VOLUME_H 4 #define NET_FS_SHARE_VOLUME_H 5 6 #include <fsproto.h> 7 8 #include <util/DoublyLinkedList.h> 9 10 #include "EntryInfo.h" 11 #include "FSObject.h" 12 #include "Locker.h" 13 #include "RequestHandler.h" 14 #include "RequestMemberArray.h" 15 #include "ServerNodeID.h" 16 #include "Volume.h" 17 18 class AttrDirInfo; 19 class ExtendedServerInfo; 20 class ExtendedShareInfo; 21 class Node; 22 class ReadQueryReply; 23 class RemoteShareDirIterator; 24 class RequestConnection; 25 class RootShareVolume; 26 class ServerConnection; 27 class ServerConnectionProvider; 28 class ShareAttrDirIterator; 29 class ShareDir; 30 class ShareDirEntry; 31 class ShareNode; 32 class WalkReply; 33 34 class ShareVolume : public Volume { 35 public: 36 ShareVolume(VolumeManager* volumeManager, 37 ServerConnectionProvider* 38 connectionProvider, 39 ExtendedServerInfo* serverInfo, 40 ExtendedShareInfo* shareInfo); 41 ~ShareVolume(); 42 43 int32 GetID() const; 44 45 bool IsReadOnly() const; 46 bool SupportsQueries() const; 47 48 status_t Init(const char* name); 49 void Uninit(); 50 51 virtual Node* GetRootNode() const; 52 53 virtual void PrepareToUnmount(); 54 55 virtual void RemoveChildVolume(Volume* volume); 56 57 // FS 58 virtual status_t Unmount(); 59 virtual status_t Sync(); 60 61 // vnodes 62 virtual status_t ReadVNode(vnode_id vnid, char reenter, 63 Node** node); 64 virtual status_t WriteVNode(Node* node, char reenter); 65 virtual status_t RemoveVNode(Node* node, char reenter); 66 67 // nodes 68 virtual status_t FSync(Node* node); 69 virtual status_t ReadStat(Node* node, struct stat* st); 70 virtual status_t WriteStat(Node* node, struct stat *st, 71 uint32 mask); 72 virtual status_t Access(Node* node, int mode); 73 74 // files 75 virtual status_t Create(Node* dir, const char* name, 76 int openMode, int mode, vnode_id* vnid, 77 void** cookie); 78 virtual status_t Open(Node* node, int openMode, 79 void** cookie); 80 virtual status_t Close(Node* node, void* cookie); 81 virtual status_t FreeCookie(Node* node, void* cookie); 82 virtual status_t Read(Node* node, void* cookie, off_t pos, 83 void* buffer, size_t bufferSize, 84 size_t* bytesRead); 85 virtual status_t Write(Node* node, void* cookie, off_t pos, 86 const void* buffer, size_t bufferSize, 87 size_t* bytesWritten); 88 89 // hard links / symlinks 90 virtual status_t Link(Node* dir, const char* name, 91 Node* node); 92 virtual status_t Unlink(Node* dir, const char* name); 93 virtual status_t Symlink(Node* dir, const char* name, 94 const char* target); 95 virtual status_t ReadLink(Node* node, char* buffer, 96 size_t bufferSize, size_t* bytesRead); 97 virtual status_t Rename(Node* oldDir, const char* oldName, 98 Node* newDir, const char* newName); 99 100 // directories 101 virtual status_t MkDir(Node* dir, const char* name, 102 int mode); 103 virtual status_t RmDir(Node* dir, const char* name); 104 virtual status_t OpenDir(Node* node, void** cookie); 105 virtual status_t CloseDir(Node* node, void* cookie); 106 virtual status_t FreeDirCookie(Node* node, void* cookie); 107 virtual status_t ReadDir(Node* node, void* cookie, 108 struct dirent* buffer, size_t bufferSize, 109 int32 count, int32* countRead); 110 virtual status_t RewindDir(Node* node, void* cookie); 111 virtual status_t Walk(Node* dir, const char* entryName, 112 char** resolvedPath, vnode_id* vnid); 113 114 // attributes 115 virtual status_t OpenAttrDir(Node* node, void** cookie); 116 virtual status_t CloseAttrDir(Node* node, void* cookie); 117 virtual status_t FreeAttrDirCookie(Node* node, 118 void* cookie); 119 virtual status_t ReadAttrDir(Node* node, void* cookie, 120 struct dirent* buffer, size_t bufferSize, 121 int32 count, int32* countRead); 122 virtual status_t RewindAttrDir(Node* node, void* cookie); 123 virtual status_t ReadAttr(Node* node, const char* name, 124 int type, off_t pos, void* buffer, 125 size_t bufferSize, size_t* bytesRead); 126 virtual status_t WriteAttr(Node* node, const char* name, 127 int type, off_t pos, const void* buffer, 128 size_t bufferSize, size_t* bytesWritten); 129 virtual status_t RemoveAttr(Node* node, const char* name); 130 virtual status_t RenameAttr(Node* node, 131 const char* oldName, const char* newName); 132 virtual status_t StatAttr(Node* node, const char* name, 133 struct attr_info* attrInfo); 134 135 // queries 136 status_t GetQueryEntry(const EntryInfo& entryInfo, 137 const NodeInfo& dirInfo, 138 struct dirent* buffer, size_t bufferSize, 139 int32* countRead); 140 141 142 // service methods called from "outside" 143 void ProcessNodeMonitoringRequest( 144 NodeMonitoringRequest* request); 145 void ConnectionClosed(); 146 147 private: 148 struct NodeMap; 149 struct EntryKey; 150 struct EntryMap; 151 struct LocalNodeIDMap; 152 struct RemoteNodeIDMap; 153 struct DirCookie; 154 struct AttrDirCookie; 155 struct AttrDirIteratorMap; 156 157 private: 158 status_t _ReadRemoteDir(ShareDir* directory, 159 RemoteShareDirIterator* remoteIterator); 160 161 void _HandleEntryCreatedRequest( 162 EntryCreatedRequest* request); 163 void _HandleEntryRemovedRequest( 164 EntryRemovedRequest* request); 165 void _HandleEntryMovedRequest( 166 EntryMovedRequest* request); 167 void _HandleStatChangedRequest( 168 StatChangedRequest* request); 169 void _HandleAttributeChangedRequest( 170 AttributeChangedRequest* request); 171 172 status_t _GetLocalNodeID(NodeID remoteID, ino_t* localID, 173 bool enter); 174 status_t _GetRemoteNodeID(ino_t localID, 175 NodeID* remoteID); 176 void _RemoveLocalNodeID(ino_t localID); 177 178 ShareNode* _GetNodeByLocalID(ino_t localID); 179 ShareNode* _GetNodeByRemoteID(NodeID remoteID); 180 status_t _LoadNode(const NodeInfo& nodeInfo, 181 ShareNode** node); 182 status_t _UpdateNode(const NodeInfo& nodeInfo); 183 184 ShareDirEntry* _GetEntryByLocalID(ino_t localDirID, 185 const char* name); 186 ShareDirEntry* _GetEntryByRemoteID(NodeID remoteDirID, 187 const char* name); 188 status_t _LoadEntry(ShareDir* directory, 189 const EntryInfo& entryInfo, 190 ShareDirEntry** entry); 191 void _RemoveEntry(ShareDirEntry* entry); 192 bool _IsObsoleteEntryInfo( 193 const EntryInfo& entryInfo); 194 195 status_t _AddAttrDirIterator(ShareNode* node, 196 ShareAttrDirIterator* iterator); 197 void _RemoveAttrDirIterator(ShareNode* node, 198 ShareAttrDirIterator* iterator); 199 status_t _LoadAttrDir(ShareNode* node, 200 const AttrDirInfo& attrDirInfo); 201 status_t _UpdateAttrDir(NodeID remoteID, 202 const AttrDirInfo& attrDirInfo); 203 204 void _NodeRemoved(NodeID remoteID); 205 void _EntryCreated(NodeID remoteDirID, 206 const char* name, 207 const EntryInfo* entryInfo, int64 revision); 208 void _EntryRemoved(NodeID remoteDirID, 209 const char* name, int64 revision); 210 void _EntryMoved(NodeID remoteOldDirID, 211 const char* oldName, NodeID remoteNewDirID, 212 const char* name, 213 const EntryInfo* entryInfo, int64 revision); 214 215 status_t _Walk(NodeID remoteDirID, const char* entryName, 216 bool resolveLink, WalkReply** reply); 217 status_t _MultiWalk( 218 RequestMemberArray<EntryInfo>& entryInfos, 219 MultiWalkReply** reply); 220 status_t _Close(intptr_t cookie); 221 222 uint32 _GetConnectionState(); 223 bool _IsConnected(); 224 bool _EnsureShareMounted(); 225 status_t _MountShare(); 226 227 private: 228 int32 fID; 229 uint32 fFlags; 230 Locker fMountLock; 231 ShareDir* fRootNode; 232 NodeMap* fNodes; // local ID -> ShareNode 233 EntryMap* fEntries; // local ID, name -> ShareDirEntry 234 AttrDirIteratorMap* fAttrDirIterators; 235 // local ID -> DoublyLinkedList<> 236 LocalNodeIDMap* fLocalNodeIDs; // remote ID -> local ID 237 RemoteNodeIDMap* fRemoteNodeIDs; // local ID -> remote ID 238 ServerConnectionProvider* fServerConnectionProvider; 239 ExtendedServerInfo* fServerInfo; 240 ExtendedShareInfo* fShareInfo; 241 ServerConnection* fServerConnection; 242 RequestConnection* fConnection; 243 uint32 fSharePermissions; 244 uint32 fConnectionState; 245 }; 246 247 #endif // NET_FS_SHARE_VOLUME_H 248