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