1 // Volume.h 2 // 3 // Copyright (c) 2003, Ingo Weinhold (bonefish@cs.tu-berlin.de) 4 // 5 // This program is free software; you can redistribute it and/or modify 6 // it under the terms of the GNU General Public License as published by 7 // the Free Software Foundation; either version 2 of the License, or 8 // (at your option) any later version. 9 // 10 // This program is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU General Public License for more details. 14 // 15 // You should have received a copy of the GNU General Public License 16 // along with this program; if not, write to the Free Software 17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 // 19 // You can alternatively use *this file* under the terms of the the MIT 20 // license included in this package. 21 22 #ifndef VOLUME_H 23 #define VOLUME_H 24 25 #include <fs_interface.h> 26 #include <SupportDefs.h> 27 28 #include "DLList.h" 29 #include "Entry.h" 30 #include "List.h" 31 #include "Locker.h" 32 #include "Query.h" 33 #include "String.h" 34 35 class AllocationInfo; 36 class Block; 37 class BlockAllocator; 38 class BlockReference; 39 class Directory; 40 class DirectoryEntryTable; 41 class Entry; 42 class EntryListener; 43 class EntryListenerTree; 44 class Index; 45 class IndexDirectory; 46 class LastModifiedIndex; 47 class NameIndex; 48 class Node; 49 class NodeAttributeTable; 50 class NodeListener; 51 class NodeListenerTree; 52 class NodeTable; 53 class SizeIndex; 54 55 const vnode_id kRootParentID = 0; 56 57 // NodeListenerValue 58 class NodeListenerValue { 59 public: 60 inline NodeListenerValue(int) {} 61 inline NodeListenerValue(NodeListener *listener, Node *node, uint32 flags) 62 : listener(listener), node(node), flags(flags) {} 63 64 inline bool operator==(const NodeListenerValue &other) 65 { return listener == other.listener; } 66 67 NodeListener *listener; 68 Node *node; 69 uint32 flags; 70 }; 71 typedef List<NodeListenerValue> NodeListenerList; 72 73 // EntryListenerValue 74 class EntryListenerValue { 75 public: 76 inline EntryListenerValue(int) {} 77 inline EntryListenerValue(EntryListener *listener, Entry *entry, 78 uint32 flags) 79 : listener(listener), entry(entry), flags(flags) {} 80 81 inline bool operator==(const EntryListenerValue &other) 82 { return listener == other.listener; } 83 84 EntryListener *listener; 85 Entry *entry; 86 uint32 flags; 87 }; 88 typedef List<EntryListenerValue> EntryListenerList; 89 90 // Volume 91 class Volume { 92 public: 93 Volume(); 94 ~Volume(); 95 96 status_t Mount(mount_id nsid); 97 status_t Unmount(); 98 99 mount_id GetID() const { return fID; } 100 101 off_t GetBlockSize() const; 102 off_t CountBlocks() const; 103 off_t CountFreeBlocks() const; 104 105 status_t SetName(const char *name); 106 const char *GetName() const; 107 108 Directory *GetRootDirectory() const { return fRootDirectory; } 109 110 status_t NewVNode(Node *node); 111 status_t PublishVNode(Node *node); 112 status_t GetVNode(vnode_id id, Node **node); 113 status_t GetVNode(Node *node); 114 status_t PutVNode(vnode_id id); 115 status_t PutVNode(Node *node); 116 status_t RemoveVNode(Node *node); 117 status_t UnremoveVNode(Node *node); 118 119 // node table and listeners 120 status_t NodeAdded(Node *node); 121 status_t NodeRemoved(Node *node); 122 status_t FindNode(vnode_id id, Node **node); 123 status_t AddNodeListener(NodeListener *listener, Node *node, 124 uint32 flags); 125 status_t RemoveNodeListener(NodeListener *listener, Node *node); 126 127 // entry table and listeners 128 status_t EntryAdded(vnode_id id, Entry *entry); 129 status_t EntryRemoved(vnode_id id, Entry *entry); 130 status_t FindEntry(vnode_id id, const char *name, Entry **entry); 131 status_t AddEntryListener(EntryListener *listener, Entry *entry, 132 uint32 flags); 133 status_t RemoveEntryListener(EntryListener *listener, Entry *entry); 134 135 // node attribute table 136 status_t NodeAttributeAdded(vnode_id id, Attribute *attribute); 137 status_t NodeAttributeRemoved(vnode_id id, Attribute *attribute); 138 status_t FindNodeAttribute(vnode_id id, const char *name, 139 Attribute **attribute); 140 141 // indices 142 IndexDirectory *GetIndexDirectory() const { return fIndexDirectory; } 143 NameIndex *GetNameIndex() const; 144 LastModifiedIndex *GetLastModifiedIndex() const; 145 SizeIndex *GetSizeIndex() const; 146 Index *FindIndex(const char *name); 147 AttributeIndex *FindAttributeIndex(const char *name, uint32 type); 148 149 // queries 150 void AddQuery(Query *query); 151 void RemoveQuery(Query *query); 152 void UpdateLiveQueries(Entry *entry, Node* node, const char *attribute, 153 int32 type, const uint8 *oldKey, size_t oldLength, 154 const uint8 *newKey, size_t newLength); 155 156 vnode_id NextNodeID() { return fNextNodeID++; } 157 158 status_t AllocateBlock(size_t size, BlockReference **block); 159 void FreeBlock(BlockReference *block); 160 BlockReference *ResizeBlock(BlockReference *block, size_t size); 161 // debugging only 162 bool CheckBlock(BlockReference *block, size_t size = 0); 163 void GetAllocationInfo(AllocationInfo &info); 164 165 bigtime_t GetAccessTime() const { return fAccessTime; } 166 167 // locking 168 bool ReadLock(); 169 void ReadUnlock(); 170 bool WriteLock(); 171 void WriteUnlock(); 172 173 bool IteratorLock(); 174 void IteratorUnlock(); 175 176 private: 177 typedef DLList<Query> QueryList; 178 179 mount_id fID; 180 vnode_id fNextNodeID; 181 NodeTable *fNodeTable; 182 DirectoryEntryTable *fDirectoryEntryTable; 183 NodeAttributeTable *fNodeAttributeTable; 184 IndexDirectory *fIndexDirectory; 185 Directory *fRootDirectory; 186 String fName; 187 Locker fLocker; 188 Locker fIteratorLocker; 189 Locker fQueryLocker; 190 NodeListenerTree *fNodeListeners; 191 NodeListenerList fAnyNodeListeners; 192 EntryListenerTree *fEntryListeners; 193 EntryListenerList fAnyEntryListeners; 194 QueryList fQueries; 195 BlockAllocator *fBlockAllocator; 196 off_t fBlockSize; 197 off_t fAllocatedBlocks; 198 bigtime_t fAccessTime; 199 bool fMounted; 200 }; 201 202 #endif // VOLUME_H 203