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