1 /* 2 * Copyright 2001-2009, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef USERLAND_FS_FILE_SYSTEM_H 6 #define USERLAND_FS_FILE_SYSTEM_H 7 8 9 #include <fs_interface.h> 10 11 #include <util/OpenHashTable.h> 12 13 #include <lock.h> 14 15 #include "FSCapabilities.h" 16 #include "LazyInitializable.h" 17 #include "Locker.h" 18 #include "RequestPort.h" 19 #include "RequestPortPool.h" 20 #include "String.h" 21 #include "Vector.h" 22 23 24 struct IOCtlInfo; 25 class KMessage; 26 class Settings; 27 class Volume; 28 29 30 struct VNodeOps { 31 int32 refCount; 32 FSVNodeCapabilities capabilities; 33 fs_vnode_ops* ops; 34 VNodeOps* hash_link; 35 36 VNodeOps(const FSVNodeCapabilities& capabilities, fs_vnode_ops* ops) 37 : 38 refCount(1), 39 capabilities(capabilities), 40 ops(ops) 41 { 42 } 43 44 ~VNodeOps() 45 { 46 delete ops; 47 } 48 }; 49 50 51 struct VNodeOpsHashDefinition { 52 typedef FSVNodeCapabilities KeyType; 53 typedef VNodeOps ValueType; 54 55 size_t HashKey(const FSVNodeCapabilities& key) const 56 { return key.GetHashCode(); } 57 size_t Hash(const VNodeOps* value) const 58 { return HashKey(value->capabilities); } 59 bool Compare(const FSVNodeCapabilities& key, const VNodeOps* value) const 60 { return value->capabilities == key; } 61 VNodeOps*& GetLink(VNodeOps* value) const 62 { return value->hash_link; } 63 }; 64 65 66 class FileSystem { 67 public: 68 FileSystem(); 69 ~FileSystem(); 70 71 status_t Init(const char* name, team_id team, 72 Port::Info* infos, int32 infoCount, 73 const FSCapabilities& capabilities); 74 75 const char* GetName() const; 76 team_id GetTeam() const { return fTeam; } 77 78 const FSCapabilities& GetCapabilities() const; 79 inline bool HasCapability(uint32 capability) const; 80 81 RequestPortPool* GetPortPool(); 82 83 status_t Mount(fs_volume* fsVolume, const char* device, 84 ulong flags, const char* parameters, 85 Volume** volume); 86 // status_t Initialize(const char* deviceName, 87 // const char* parameters, size_t len); 88 void VolumeUnmounted(Volume* volume); 89 90 Volume* GetVolume(dev_t id); 91 92 const IOCtlInfo* GetIOCtlInfo(int command) const; 93 94 status_t AddSelectSyncEntry(selectsync* sync); 95 void RemoveSelectSyncEntry(selectsync* sync); 96 bool KnowsSelectSyncEntry(selectsync* sync); 97 98 status_t AddNodeListener(dev_t device, ino_t node, 99 uint32 flags, void* listener); 100 status_t RemoveNodeListener(dev_t device, ino_t node, 101 void* listener); 102 103 VNodeOps* GetVNodeOps( 104 const FSVNodeCapabilities& capabilities); 105 void PutVNodeOps(VNodeOps* ops); 106 107 bool IsUserlandServerThread() const; 108 109 private: 110 struct SelectSyncMap; 111 struct NodeListenerKey; 112 struct NodeListenerProxy; 113 struct NodeListenerHashDefinition; 114 115 friend class KernelDebug; 116 friend struct NodeListenerProxy; 117 118 typedef BOpenHashTable<VNodeOpsHashDefinition> VNodeOpsMap; 119 typedef BOpenHashTable<NodeListenerHashDefinition> NodeListenerMap; 120 121 122 private: 123 void _InitVNodeOpsVector(fs_vnode_ops* ops, 124 const FSVNodeCapabilities& capabilities); 125 126 void _NodeListenerEventOccurred( 127 NodeListenerProxy* proxy, 128 const KMessage* event); 129 130 static int32 _NotificationThreadEntry(void* data); 131 int32 _NotificationThread(); 132 133 private: 134 Vector<Volume*> fVolumes; 135 mutex fVolumeLock; 136 VNodeOpsMap fVNodeOps; 137 mutex fVNodeOpsLock; 138 String fName; 139 team_id fTeam; 140 FSCapabilities fCapabilities; 141 RequestPort* fNotificationPort; 142 thread_id fNotificationThread; 143 RequestPortPool fPortPool; 144 SelectSyncMap* fSelectSyncs; 145 mutex fNodeListenersLock; 146 NodeListenerMap* fNodeListeners; 147 Settings* fSettings; 148 team_id fUserlandServerTeam; 149 bool fInitialized; 150 volatile bool fTerminating; 151 }; 152 153 154 // HasCapability 155 inline bool 156 FileSystem::HasCapability(uint32 capability) const 157 { 158 return fCapabilities.Get(capability); 159 } 160 161 #endif // USERLAND_FS_FILE_SYSTEM_H 162