1224e7c42SIngo Weinhold // Volume.h 2224e7c42SIngo Weinhold // 3224e7c42SIngo Weinhold // Copyright (c) 2003, Ingo Weinhold (bonefish@cs.tu-berlin.de) 4224e7c42SIngo Weinhold // 5224e7c42SIngo Weinhold // This program is free software; you can redistribute it and/or modify 6224e7c42SIngo Weinhold // it under the terms of the GNU General Public License as published by 7224e7c42SIngo Weinhold // the Free Software Foundation; either version 2 of the License, or 8224e7c42SIngo Weinhold // (at your option) any later version. 9224e7c42SIngo Weinhold // 10224e7c42SIngo Weinhold // This program is distributed in the hope that it will be useful, 11224e7c42SIngo Weinhold // but WITHOUT ANY WARRANTY; without even the implied warranty of 12224e7c42SIngo Weinhold // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13224e7c42SIngo Weinhold // GNU General Public License for more details. 14224e7c42SIngo Weinhold // 15224e7c42SIngo Weinhold // You should have received a copy of the GNU General Public License 16224e7c42SIngo Weinhold // along with this program; if not, write to the Free Software 17224e7c42SIngo Weinhold // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18224e7c42SIngo Weinhold // 19224e7c42SIngo Weinhold // You can alternatively use *this file* under the terms of the the MIT 20224e7c42SIngo Weinhold // license included in this package. 21224e7c42SIngo Weinhold 22224e7c42SIngo Weinhold #ifndef VOLUME_H 23224e7c42SIngo Weinhold #define VOLUME_H 24224e7c42SIngo Weinhold 25c7a72423SIngo Weinhold #include <fs_interface.h> 26224e7c42SIngo Weinhold #include <SupportDefs.h> 27224e7c42SIngo Weinhold 28224e7c42SIngo Weinhold #include "DLList.h" 29224e7c42SIngo Weinhold #include "Entry.h" 30224e7c42SIngo Weinhold #include "List.h" 31224e7c42SIngo Weinhold #include "Locker.h" 32224e7c42SIngo Weinhold #include "Query.h" 33224e7c42SIngo Weinhold #include "String.h" 34224e7c42SIngo Weinhold 35224e7c42SIngo Weinhold class AllocationInfo; 36224e7c42SIngo Weinhold class Block; 37224e7c42SIngo Weinhold class BlockAllocator; 38224e7c42SIngo Weinhold class BlockReference; 39224e7c42SIngo Weinhold class Directory; 40224e7c42SIngo Weinhold class DirectoryEntryTable; 41224e7c42SIngo Weinhold class Entry; 42224e7c42SIngo Weinhold class EntryListener; 43224e7c42SIngo Weinhold class EntryListenerTree; 44224e7c42SIngo Weinhold class Index; 45224e7c42SIngo Weinhold class IndexDirectory; 46224e7c42SIngo Weinhold class LastModifiedIndex; 47224e7c42SIngo Weinhold class NameIndex; 48224e7c42SIngo Weinhold class Node; 49224e7c42SIngo Weinhold class NodeAttributeTable; 50224e7c42SIngo Weinhold class NodeListener; 51224e7c42SIngo Weinhold class NodeListenerTree; 52224e7c42SIngo Weinhold class NodeTable; 53224e7c42SIngo Weinhold class SizeIndex; 54224e7c42SIngo Weinhold 55*245aecdaSAxel Dörfler const ino_t kRootParentID = 0; 56224e7c42SIngo Weinhold 57224e7c42SIngo Weinhold // NodeListenerValue 58224e7c42SIngo Weinhold class NodeListenerValue { 59224e7c42SIngo Weinhold public: 60224e7c42SIngo Weinhold inline NodeListenerValue(int) {} 61224e7c42SIngo Weinhold inline NodeListenerValue(NodeListener *listener, Node *node, uint32 flags) 62224e7c42SIngo Weinhold : listener(listener), node(node), flags(flags) {} 63224e7c42SIngo Weinhold 64224e7c42SIngo Weinhold inline bool operator==(const NodeListenerValue &other) 65224e7c42SIngo Weinhold { return listener == other.listener; } 66224e7c42SIngo Weinhold 67224e7c42SIngo Weinhold NodeListener *listener; 68224e7c42SIngo Weinhold Node *node; 69224e7c42SIngo Weinhold uint32 flags; 70224e7c42SIngo Weinhold }; 71224e7c42SIngo Weinhold typedef List<NodeListenerValue> NodeListenerList; 72224e7c42SIngo Weinhold 73224e7c42SIngo Weinhold // EntryListenerValue 74224e7c42SIngo Weinhold class EntryListenerValue { 75224e7c42SIngo Weinhold public: 76224e7c42SIngo Weinhold inline EntryListenerValue(int) {} 77224e7c42SIngo Weinhold inline EntryListenerValue(EntryListener *listener, Entry *entry, 78224e7c42SIngo Weinhold uint32 flags) 79224e7c42SIngo Weinhold : listener(listener), entry(entry), flags(flags) {} 80224e7c42SIngo Weinhold 81224e7c42SIngo Weinhold inline bool operator==(const EntryListenerValue &other) 82224e7c42SIngo Weinhold { return listener == other.listener; } 83224e7c42SIngo Weinhold 84224e7c42SIngo Weinhold EntryListener *listener; 85224e7c42SIngo Weinhold Entry *entry; 86224e7c42SIngo Weinhold uint32 flags; 87224e7c42SIngo Weinhold }; 88224e7c42SIngo Weinhold typedef List<EntryListenerValue> EntryListenerList; 89224e7c42SIngo Weinhold 90224e7c42SIngo Weinhold // Volume 91224e7c42SIngo Weinhold class Volume { 92224e7c42SIngo Weinhold public: 93224e7c42SIngo Weinhold Volume(); 94224e7c42SIngo Weinhold ~Volume(); 95224e7c42SIngo Weinhold 96*245aecdaSAxel Dörfler status_t Mount(dev_t nsid); 97224e7c42SIngo Weinhold status_t Unmount(); 98224e7c42SIngo Weinhold 99*245aecdaSAxel Dörfler dev_t GetID() const { return fID; } 100224e7c42SIngo Weinhold 101224e7c42SIngo Weinhold off_t GetBlockSize() const; 102224e7c42SIngo Weinhold off_t CountBlocks() const; 103224e7c42SIngo Weinhold off_t CountFreeBlocks() const; 104224e7c42SIngo Weinhold 105224e7c42SIngo Weinhold status_t SetName(const char *name); 106224e7c42SIngo Weinhold const char *GetName() const; 107224e7c42SIngo Weinhold 108224e7c42SIngo Weinhold Directory *GetRootDirectory() const { return fRootDirectory; } 109224e7c42SIngo Weinhold 110224e7c42SIngo Weinhold status_t NewVNode(Node *node); 111c7a72423SIngo Weinhold status_t PublishVNode(Node *node); 112*245aecdaSAxel Dörfler status_t GetVNode(ino_t id, Node **node); 113224e7c42SIngo Weinhold status_t GetVNode(Node *node); 114*245aecdaSAxel Dörfler status_t PutVNode(ino_t id); 115224e7c42SIngo Weinhold status_t PutVNode(Node *node); 116224e7c42SIngo Weinhold status_t RemoveVNode(Node *node); 117224e7c42SIngo Weinhold status_t UnremoveVNode(Node *node); 118224e7c42SIngo Weinhold 119224e7c42SIngo Weinhold // node table and listeners 120224e7c42SIngo Weinhold status_t NodeAdded(Node *node); 121224e7c42SIngo Weinhold status_t NodeRemoved(Node *node); 122*245aecdaSAxel Dörfler status_t FindNode(ino_t id, Node **node); 123224e7c42SIngo Weinhold status_t AddNodeListener(NodeListener *listener, Node *node, 124224e7c42SIngo Weinhold uint32 flags); 125224e7c42SIngo Weinhold status_t RemoveNodeListener(NodeListener *listener, Node *node); 126224e7c42SIngo Weinhold 127224e7c42SIngo Weinhold // entry table and listeners 128*245aecdaSAxel Dörfler status_t EntryAdded(ino_t id, Entry *entry); 129*245aecdaSAxel Dörfler status_t EntryRemoved(ino_t id, Entry *entry); 130*245aecdaSAxel Dörfler status_t FindEntry(ino_t id, const char *name, Entry **entry); 131224e7c42SIngo Weinhold status_t AddEntryListener(EntryListener *listener, Entry *entry, 132224e7c42SIngo Weinhold uint32 flags); 133224e7c42SIngo Weinhold status_t RemoveEntryListener(EntryListener *listener, Entry *entry); 134224e7c42SIngo Weinhold 135224e7c42SIngo Weinhold // node attribute table 136*245aecdaSAxel Dörfler status_t NodeAttributeAdded(ino_t id, Attribute *attribute); 137*245aecdaSAxel Dörfler status_t NodeAttributeRemoved(ino_t id, Attribute *attribute); 138*245aecdaSAxel Dörfler status_t FindNodeAttribute(ino_t id, const char *name, 139224e7c42SIngo Weinhold Attribute **attribute); 140224e7c42SIngo Weinhold 141224e7c42SIngo Weinhold // indices 142224e7c42SIngo Weinhold IndexDirectory *GetIndexDirectory() const { return fIndexDirectory; } 143224e7c42SIngo Weinhold NameIndex *GetNameIndex() const; 144224e7c42SIngo Weinhold LastModifiedIndex *GetLastModifiedIndex() const; 145224e7c42SIngo Weinhold SizeIndex *GetSizeIndex() const; 146224e7c42SIngo Weinhold Index *FindIndex(const char *name); 147224e7c42SIngo Weinhold AttributeIndex *FindAttributeIndex(const char *name, uint32 type); 148224e7c42SIngo Weinhold 149224e7c42SIngo Weinhold // queries 150224e7c42SIngo Weinhold void AddQuery(Query *query); 151224e7c42SIngo Weinhold void RemoveQuery(Query *query); 152224e7c42SIngo Weinhold void UpdateLiveQueries(Entry *entry, Node* node, const char *attribute, 153224e7c42SIngo Weinhold int32 type, const uint8 *oldKey, size_t oldLength, 154224e7c42SIngo Weinhold const uint8 *newKey, size_t newLength); 155224e7c42SIngo Weinhold 156*245aecdaSAxel Dörfler ino_t NextNodeID() { return fNextNodeID++; } 157224e7c42SIngo Weinhold 158224e7c42SIngo Weinhold status_t AllocateBlock(size_t size, BlockReference **block); 159224e7c42SIngo Weinhold void FreeBlock(BlockReference *block); 160224e7c42SIngo Weinhold BlockReference *ResizeBlock(BlockReference *block, size_t size); 161224e7c42SIngo Weinhold // debugging only 162224e7c42SIngo Weinhold bool CheckBlock(BlockReference *block, size_t size = 0); 163224e7c42SIngo Weinhold void GetAllocationInfo(AllocationInfo &info); 164224e7c42SIngo Weinhold 165224e7c42SIngo Weinhold bigtime_t GetAccessTime() const { return fAccessTime; } 166224e7c42SIngo Weinhold 167224e7c42SIngo Weinhold // locking 168224e7c42SIngo Weinhold bool ReadLock(); 169224e7c42SIngo Weinhold void ReadUnlock(); 170224e7c42SIngo Weinhold bool WriteLock(); 171224e7c42SIngo Weinhold void WriteUnlock(); 172224e7c42SIngo Weinhold 173224e7c42SIngo Weinhold bool IteratorLock(); 174224e7c42SIngo Weinhold void IteratorUnlock(); 175224e7c42SIngo Weinhold 176224e7c42SIngo Weinhold private: 177224e7c42SIngo Weinhold typedef DLList<Query> QueryList; 178224e7c42SIngo Weinhold 179*245aecdaSAxel Dörfler dev_t fID; 180*245aecdaSAxel Dörfler ino_t fNextNodeID; 181224e7c42SIngo Weinhold NodeTable *fNodeTable; 182224e7c42SIngo Weinhold DirectoryEntryTable *fDirectoryEntryTable; 183224e7c42SIngo Weinhold NodeAttributeTable *fNodeAttributeTable; 184224e7c42SIngo Weinhold IndexDirectory *fIndexDirectory; 185224e7c42SIngo Weinhold Directory *fRootDirectory; 186224e7c42SIngo Weinhold String fName; 187224e7c42SIngo Weinhold Locker fLocker; 188224e7c42SIngo Weinhold Locker fIteratorLocker; 189224e7c42SIngo Weinhold Locker fQueryLocker; 190224e7c42SIngo Weinhold NodeListenerTree *fNodeListeners; 191224e7c42SIngo Weinhold NodeListenerList fAnyNodeListeners; 192224e7c42SIngo Weinhold EntryListenerTree *fEntryListeners; 193224e7c42SIngo Weinhold EntryListenerList fAnyEntryListeners; 194224e7c42SIngo Weinhold QueryList fQueries; 195224e7c42SIngo Weinhold BlockAllocator *fBlockAllocator; 196224e7c42SIngo Weinhold off_t fBlockSize; 197224e7c42SIngo Weinhold off_t fAllocatedBlocks; 198224e7c42SIngo Weinhold bigtime_t fAccessTime; 199224e7c42SIngo Weinhold bool fMounted; 200224e7c42SIngo Weinhold }; 201224e7c42SIngo Weinhold 202224e7c42SIngo Weinhold #endif // VOLUME_H 203