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 <util/DoublyLinkedList.h> 29 30 #include "Entry.h" 31 #include "List.h" 32 #include "Locker.h" 33 #include "Query.h" 34 #include "String.h" 35 36 class AllocationInfo; 37 class Block; 38 class BlockAllocator; 39 class BlockReference; 40 class Directory; 41 class DirectoryEntryTable; 42 class Entry; 43 class EntryListener; 44 class EntryListenerTree; 45 class Index; 46 class IndexDirectory; 47 class LastModifiedIndex; 48 class NameIndex; 49 class Node; 50 class NodeAttributeTable; 51 class NodeListener; 52 class NodeListenerTree; 53 class NodeTable; 54 class SizeIndex; 55 56 const ino_t kRootParentID = 0; 57 58 // NodeListenerValue 59 class NodeListenerValue { 60 public: 61 inline NodeListenerValue() {} 62 inline NodeListenerValue(int) {} 63 inline NodeListenerValue(NodeListener *listener, Node *node, uint32 flags) 64 : listener(listener), node(node), flags(flags) {} 65 66 inline bool operator==(const NodeListenerValue &other) 67 { return listener == other.listener; } 68 69 NodeListener *listener; 70 Node *node; 71 uint32 flags; 72 }; 73 typedef List<NodeListenerValue> NodeListenerList; 74 75 // EntryListenerValue 76 class EntryListenerValue { 77 public: 78 inline EntryListenerValue() {} 79 inline EntryListenerValue(int) {} 80 inline EntryListenerValue(EntryListener *listener, Entry *entry, 81 uint32 flags) 82 : listener(listener), entry(entry), flags(flags) {} 83 84 inline bool operator==(const EntryListenerValue &other) 85 { return listener == other.listener; } 86 87 EntryListener *listener; 88 Entry *entry; 89 uint32 flags; 90 }; 91 typedef List<EntryListenerValue> EntryListenerList; 92 93 // Volume 94 class Volume { 95 public: 96 Volume(); 97 ~Volume(); 98 99 status_t Mount(dev_t nsid); 100 status_t Unmount(); 101 102 dev_t GetID() const { return fID; } 103 104 off_t GetBlockSize() const; 105 off_t CountBlocks() const; 106 off_t CountFreeBlocks() const; 107 108 status_t SetName(const char *name); 109 const char *GetName() const; 110 111 Directory *GetRootDirectory() const { return fRootDirectory; } 112 113 status_t NewVNode(Node *node); 114 status_t PublishVNode(Node *node); 115 status_t GetVNode(ino_t id, Node **node); 116 status_t GetVNode(Node *node); 117 status_t PutVNode(ino_t id); 118 status_t PutVNode(Node *node); 119 status_t RemoveVNode(Node *node); 120 status_t UnremoveVNode(Node *node); 121 122 // node table and listeners 123 status_t NodeAdded(Node *node); 124 status_t NodeRemoved(Node *node); 125 status_t FindNode(ino_t id, Node **node); 126 status_t AddNodeListener(NodeListener *listener, Node *node, 127 uint32 flags); 128 status_t RemoveNodeListener(NodeListener *listener, Node *node); 129 130 // entry table and listeners 131 status_t EntryAdded(ino_t id, Entry *entry); 132 status_t EntryRemoved(ino_t id, Entry *entry); 133 status_t FindEntry(ino_t id, const char *name, Entry **entry); 134 status_t AddEntryListener(EntryListener *listener, Entry *entry, 135 uint32 flags); 136 status_t RemoveEntryListener(EntryListener *listener, Entry *entry); 137 138 // node attribute table 139 status_t NodeAttributeAdded(ino_t id, Attribute *attribute); 140 status_t NodeAttributeRemoved(ino_t id, Attribute *attribute); 141 status_t FindNodeAttribute(ino_t id, const char *name, 142 Attribute **attribute); 143 144 // indices 145 IndexDirectory *GetIndexDirectory() const { return fIndexDirectory; } 146 NameIndex *GetNameIndex() const; 147 LastModifiedIndex *GetLastModifiedIndex() const; 148 SizeIndex *GetSizeIndex() const; 149 Index *FindIndex(const char *name); 150 AttributeIndex *FindAttributeIndex(const char *name, uint32 type); 151 152 // queries 153 void AddQuery(Query *query); 154 void RemoveQuery(Query *query); 155 void UpdateLiveQueries(Entry *entry, Node* node, const char *attribute, 156 int32 type, const uint8 *oldKey, size_t oldLength, 157 const uint8 *newKey, size_t newLength); 158 159 ino_t NextNodeID() { return fNextNodeID++; } 160 161 status_t AllocateBlock(size_t size, BlockReference **block); 162 void FreeBlock(BlockReference *block); 163 BlockReference *ResizeBlock(BlockReference *block, size_t size); 164 // debugging only 165 bool CheckBlock(BlockReference *block, size_t size = 0); 166 void GetAllocationInfo(AllocationInfo &info); 167 168 bigtime_t GetAccessTime() const { return fAccessTime; } 169 170 // locking 171 bool ReadLock(); 172 void ReadUnlock(); 173 bool WriteLock(); 174 void WriteUnlock(); 175 176 bool IteratorLock(); 177 void IteratorUnlock(); 178 179 private: 180 typedef DoublyLinkedList<Query> QueryList; 181 182 dev_t fID; 183 ino_t fNextNodeID; 184 NodeTable *fNodeTable; 185 DirectoryEntryTable *fDirectoryEntryTable; 186 NodeAttributeTable *fNodeAttributeTable; 187 IndexDirectory *fIndexDirectory; 188 Directory *fRootDirectory; 189 String fName; 190 Locker fLocker; 191 Locker fIteratorLocker; 192 Locker fQueryLocker; 193 NodeListenerTree *fNodeListeners; 194 NodeListenerList fAnyNodeListeners; 195 EntryListenerTree *fEntryListeners; 196 EntryListenerList fAnyEntryListeners; 197 QueryList fQueries; 198 BlockAllocator *fBlockAllocator; 199 off_t fBlockSize; 200 off_t fAllocatedBlocks; 201 bigtime_t fAccessTime; 202 bool fMounted; 203 }; 204 205 #endif // VOLUME_H 206