1 // ClientVolume.h 2 3 #ifndef NET_FS_CLIENT_VOLUME_H 4 #define NET_FS_CLIENT_VOLUME_H 5 6 #include <Locker.h> 7 8 #include "BlockingQueue.h" 9 #include "FSObject.h" 10 #include "HashString.h" 11 #include "Node.h" 12 #include "Permissions.h" 13 #include "ServerNodeID.h" 14 15 class AttrDirIterator; 16 class DirIterator; 17 class FileHandle; 18 class NodeInfo; 19 class NodeHandle; 20 class NodeHandleMap; 21 class NodeMonitoringEvent; 22 class QueryHandle; 23 class UserSecurityContext; 24 class Share; 25 class VolumeManager; 26 27 // ClientVolume 28 class ClientVolume : public FSObject, public BLocker { 29 public: 30 class NodeMonitoringProcessor; 31 32 public: 33 ClientVolume(Locker& securityContextLocker, 34 NodeMonitoringProcessor* 35 nodeMonitoringProcessor); 36 ~ClientVolume(); 37 38 status_t Init(); 39 40 int32 GetID() const; 41 42 status_t Mount(UserSecurityContext* securityContext, 43 Share* share); 44 void Unmount(); 45 bool IsMounted() const; 46 47 UserSecurityContext* GetSecurityContext() const; 48 void SetSecurityContext( 49 UserSecurityContext* securityContext); 50 51 Share* GetShare() const; 52 53 Directory* GetRootDirectory() const; 54 const NodeRef& GetRootNodeRef() const; 55 56 Permissions GetSharePermissions() const; 57 58 Permissions GetNodePermissions(dev_t volumeID, 59 ino_t nodeID); 60 Permissions GetNodePermissions(Node* node); 61 62 Node* GetNode(dev_t volumeID, ino_t nodeID); 63 Node* GetNode(NodeID nodeID); 64 Node* GetNode(const node_ref& nodeRef); 65 66 Directory* GetDirectory(dev_t volumeID, ino_t nodeID); 67 Directory* GetDirectory(NodeID nodeID); 68 status_t LoadDirectory(dev_t volumeID, ino_t nodeID, 69 Directory** directory); 70 71 Entry* GetEntry(dev_t volumeID, ino_t dirID, 72 const char* name); 73 Entry* GetEntry(Directory* directory, 74 const char* name); 75 status_t LoadEntry(dev_t volumeID, ino_t dirID, 76 const char* name, Entry** entry); 77 status_t LoadEntry(Directory* directory, 78 const char* name, Entry** entry); 79 80 status_t Open(Node* node, int openMode, 81 FileHandle** handle); 82 status_t OpenDir(Directory* directory, 83 DirIterator** iterator); 84 status_t OpenAttrDir(Node* node, 85 AttrDirIterator** iterator); 86 status_t Close(NodeHandle* handle); 87 88 status_t LockNodeHandle(int32 cookie, 89 NodeHandle** handle); 90 void UnlockNodeHandle(NodeHandle* nodeHandle); 91 92 void ProcessNodeMonitoringEvent( 93 NodeMonitoringEvent* event); 94 95 private: 96 static int32 _NextVolumeID(); 97 98 private: 99 struct NodeIDMap; 100 struct NodeMap; 101 102 int32 fID; 103 UserSecurityContext* fSecurityContext; 104 Locker& fSecurityContextLock; 105 NodeMonitoringProcessor* fNodeMonitoringProcessor; 106 NodeHandleMap* fNodeHandles; 107 Share* fShare; 108 NodeRef fRootNodeRef; 109 Permissions fSharePermissions; 110 bool fMounted; 111 112 static int32 sNextVolumeID; 113 }; 114 115 // NodeMonitoringProcessor 116 class ClientVolume::NodeMonitoringProcessor { 117 public: 118 NodeMonitoringProcessor() {} 119 virtual ~NodeMonitoringProcessor(); 120 121 virtual void ProcessNodeMonitoringEvent(int32 volumeID, 122 NodeMonitoringEvent* event) = 0; 123 }; 124 125 // NodeHandleUnlocker 126 struct NodeHandleUnlocker { 127 NodeHandleUnlocker(ClientVolume* volume, NodeHandle* nodeHandle) 128 : fVolume(volume), 129 fHandle(nodeHandle) 130 { 131 } 132 133 ~NodeHandleUnlocker() 134 { 135 if (fVolume && fHandle) { 136 fVolume->UnlockNodeHandle(fHandle); 137 fVolume = NULL; 138 fHandle = NULL; 139 } 140 } 141 142 private: 143 ClientVolume* fVolume; 144 NodeHandle* fHandle; 145 }; 146 147 #endif // NET_FS_CLIENT_VOLUME_H 148