RAMFS: Minor code style cleanups to Volume.

This commit is contained in:
Augustin Cavalier 2024-11-22 17:42:00 -05:00
parent fe0e833f1f
commit 374d7a1eb1
2 changed files with 59 additions and 58 deletions

View File

@ -44,9 +44,9 @@
#include "Volume.h" #include "Volume.h"
// default volume name // default volume name
static const char *kDefaultVolumeName = "RAM FS"; static const char *kDefaultVolumeName = "RAMFS";
// NodeListenerGetPrimaryKey
class NodeListenerGetPrimaryKey { class NodeListenerGetPrimaryKey {
public: public:
inline Node *operator()(const NodeListenerValue &a) inline Node *operator()(const NodeListenerValue &a)
@ -60,7 +60,6 @@ public:
} }
}; };
// NodeListenerGetSecondaryKey
class NodeListenerGetSecondaryKey { class NodeListenerGetSecondaryKey {
public: public:
inline NodeListener *operator()(const NodeListenerValue &a) inline NodeListener *operator()(const NodeListenerValue &a)
@ -74,7 +73,6 @@ public:
} }
}; };
// NodeListenerTree
typedef TwoKeyAVLTree<NodeListenerValue, Node*, typedef TwoKeyAVLTree<NodeListenerValue, Node*,
TwoKeyAVLTreeStandardCompare<Node*>, TwoKeyAVLTreeStandardCompare<Node*>,
NodeListenerGetPrimaryKey, NodeListener*, NodeListenerGetPrimaryKey, NodeListener*,
@ -82,7 +80,7 @@ typedef TwoKeyAVLTree<NodeListenerValue, Node*,
NodeListenerGetSecondaryKey > _NodeListenerTree; NodeListenerGetSecondaryKey > _NodeListenerTree;
class NodeListenerTree : public _NodeListenerTree {}; class NodeListenerTree : public _NodeListenerTree {};
// EntryListenerGetPrimaryKey
class EntryListenerGetPrimaryKey { class EntryListenerGetPrimaryKey {
public: public:
inline Entry *operator()(const EntryListenerValue &a) inline Entry *operator()(const EntryListenerValue &a)
@ -96,7 +94,7 @@ public:
} }
}; };
// EntryListenerGetSecondaryKey
class EntryListenerGetSecondaryKey { class EntryListenerGetSecondaryKey {
public: public:
inline EntryListener *operator()(const EntryListenerValue &a) inline EntryListener *operator()(const EntryListenerValue &a)
@ -110,7 +108,7 @@ public:
} }
}; };
// EntryListenerTree
typedef TwoKeyAVLTree<EntryListenerValue, Entry*, typedef TwoKeyAVLTree<EntryListenerValue, Entry*,
TwoKeyAVLTreeStandardCompare<Entry*>, TwoKeyAVLTreeStandardCompare<Entry*>,
EntryListenerGetPrimaryKey, EntryListener*, EntryListenerGetPrimaryKey, EntryListener*,
@ -124,16 +122,16 @@ class EntryListenerTree : public _EntryListenerTree {};
\brief Represents a volume. \brief Represents a volume.
*/ */
// constructor
Volume::Volume(fs_volume* volume) Volume::Volume(fs_volume* volume)
: :
fVolume(volume), fVolume(volume),
fName(kDefaultVolumeName),
fNextNodeID(kRootParentID + 1), fNextNodeID(kRootParentID + 1),
fNodeTable(NULL), fNodeTable(NULL),
fDirectoryEntryTable(NULL), fDirectoryEntryTable(NULL),
fIndexDirectory(NULL), fIndexDirectory(NULL),
fRootDirectory(NULL), fRootDirectory(NULL),
fName(kDefaultVolumeName),
fNodeListeners(NULL), fNodeListeners(NULL),
fAnyNodeListeners(), fAnyNodeListeners(),
fEntryListeners(NULL), fEntryListeners(NULL),
@ -147,7 +145,6 @@ Volume::Volume(fs_volume* volume)
} }
// destructor
Volume::~Volume() Volume::~Volume()
{ {
Unmount(); Unmount();
@ -158,7 +155,7 @@ Volume::~Volume()
} }
// Mount
status_t status_t
Volume::Mount(uint32 flags) Volume::Mount(uint32 flags)
{ {
@ -217,7 +214,7 @@ Volume::Mount(uint32 flags)
RETURN_ERROR(error); RETURN_ERROR(error);
} }
// Unmount
status_t status_t
Volume::Unmount() Volume::Unmount()
{ {
@ -254,7 +251,7 @@ Volume::Unmount()
return B_OK; return B_OK;
} }
// CountBlocks
off_t off_t
Volume::CountBlocks() const Volume::CountBlocks() const
{ {
@ -262,14 +259,14 @@ Volume::CountBlocks() const
return 0; return 0;
} }
// CountFreeBlocks
off_t off_t
Volume::CountFreeBlocks() const Volume::CountFreeBlocks() const
{ {
return vm_page_num_free_pages(); return vm_page_num_free_pages();
} }
// SetName
status_t status_t
Volume::SetName(const char *name) Volume::SetName(const char *name)
{ {
@ -281,14 +278,14 @@ Volume::SetName(const char *name)
return error; return error;
} }
// GetName
const char * const char *
Volume::GetName() const Volume::GetName() const
{ {
return fName.GetString(); return fName.GetString();
} }
// NewVNode
status_t status_t
Volume::NewVNode(Node *node) Volume::NewVNode(Node *node)
{ {
@ -301,7 +298,7 @@ Volume::NewVNode(Node *node)
return error; return error;
} }
// PublishVNode
status_t status_t
Volume::PublishVNode(Node *node) Volume::PublishVNode(Node *node)
{ {
@ -315,14 +312,14 @@ Volume::PublishVNode(Node *node)
return error; return error;
} }
// GetVNode
status_t status_t
Volume::GetVNode(ino_t id, Node **node) Volume::GetVNode(ino_t id, Node **node)
{ {
return (fMounted ? get_vnode(FSVolume(), id, (void**)node) : B_BAD_VALUE); return (fMounted ? get_vnode(FSVolume(), id, (void**)node) : B_BAD_VALUE);
} }
// GetVNode
status_t status_t
Volume::GetVNode(Node *node) Volume::GetVNode(Node *node)
{ {
@ -337,21 +334,21 @@ Volume::GetVNode(Node *node)
return error; return error;
} }
// PutVNode
status_t status_t
Volume::PutVNode(ino_t id) Volume::PutVNode(ino_t id)
{ {
return (fMounted ? put_vnode(FSVolume(), id) : B_BAD_VALUE); return (fMounted ? put_vnode(FSVolume(), id) : B_BAD_VALUE);
} }
// PutVNode
status_t status_t
Volume::PutVNode(Node *node) Volume::PutVNode(Node *node)
{ {
return (fMounted ? put_vnode(FSVolume(), node->GetID()) : B_BAD_VALUE); return (fMounted ? put_vnode(FSVolume(), node->GetID()) : B_BAD_VALUE);
} }
// RemoveVNode
status_t status_t
Volume::RemoveVNode(Node *node) Volume::RemoveVNode(Node *node)
{ {
@ -364,14 +361,14 @@ Volume::RemoveVNode(Node *node)
return error; return error;
} }
// UnremoveVNode
status_t status_t
Volume::UnremoveVNode(Node *node) Volume::UnremoveVNode(Node *node)
{ {
return (fMounted ? unremove_vnode(FSVolume(), node->GetID()) : B_BAD_VALUE); return (fMounted ? unremove_vnode(FSVolume(), node->GetID()) : B_BAD_VALUE);
} }
// NodeAdded
status_t status_t
Volume::NodeAdded(Node *node) Volume::NodeAdded(Node *node)
{ {
@ -402,7 +399,7 @@ Volume::NodeAdded(Node *node)
return error; return error;
} }
// NodeRemoved
status_t status_t
Volume::NodeRemoved(Node *node) Volume::NodeRemoved(Node *node)
{ {
@ -433,7 +430,7 @@ Volume::NodeRemoved(Node *node)
return error; return error;
} }
// FindNode
/*! \brief Finds the node identified by a ino_t. /*! \brief Finds the node identified by a ino_t.
\note The method does not initialize the parent ID for non-directory nodes. \note The method does not initialize the parent ID for non-directory nodes.
@ -454,7 +451,7 @@ Volume::FindNode(ino_t id, Node **node)
return error; return error;
} }
// AddNodeListener
status_t status_t
Volume::AddNodeListener(NodeListener *listener, Node *node, uint32 flags) Volume::AddNodeListener(NodeListener *listener, Node *node, uint32 flags)
{ {
@ -474,7 +471,7 @@ Volume::AddNodeListener(NodeListener *listener, Node *node, uint32 flags)
return error; return error;
} }
// RemoveNodeListener
status_t status_t
Volume::RemoveNodeListener(NodeListener *listener, Node *node) Volume::RemoveNodeListener(NodeListener *listener, Node *node)
{ {
@ -491,7 +488,7 @@ Volume::RemoveNodeListener(NodeListener *listener, Node *node)
return error; return error;
} }
// EntryAdded
status_t status_t
Volume::EntryAdded(ino_t id, Entry *entry) Volume::EntryAdded(ino_t id, Entry *entry)
{ {
@ -522,7 +519,7 @@ Volume::EntryAdded(ino_t id, Entry *entry)
return error; return error;
} }
// EntryRemoved
status_t status_t
Volume::EntryRemoved(ino_t id, Entry *entry) Volume::EntryRemoved(ino_t id, Entry *entry)
{ {
@ -553,7 +550,7 @@ Volume::EntryRemoved(ino_t id, Entry *entry)
return error; return error;
} }
// FindEntry
status_t status_t
Volume::FindEntry(ino_t id, const char *name, Entry **entry) Volume::FindEntry(ino_t id, const char *name, Entry **entry)
{ {
@ -566,7 +563,7 @@ Volume::FindEntry(ino_t id, const char *name, Entry **entry)
return error; return error;
} }
// AddEntryListener
status_t status_t
Volume::AddEntryListener(EntryListener *listener, Entry *entry, uint32 flags) Volume::AddEntryListener(EntryListener *listener, Entry *entry, uint32 flags)
{ {
@ -586,7 +583,7 @@ Volume::AddEntryListener(EntryListener *listener, Entry *entry, uint32 flags)
return error; return error;
} }
// RemoveEntryListener
status_t status_t
Volume::RemoveEntryListener(EntryListener *listener, Entry *entry) Volume::RemoveEntryListener(EntryListener *listener, Entry *entry)
{ {
@ -603,7 +600,7 @@ Volume::RemoveEntryListener(EntryListener *listener, Entry *entry)
return error; return error;
} }
// NodeAttributeAdded
status_t status_t
Volume::NodeAttributeAdded(ino_t id, Attribute *attribute) Volume::NodeAttributeAdded(ino_t id, Attribute *attribute)
{ {
@ -620,7 +617,7 @@ Volume::NodeAttributeAdded(ino_t id, Attribute *attribute)
return error; return error;
} }
// NodeAttributeRemoved
status_t status_t
Volume::NodeAttributeRemoved(ino_t id, Attribute *attribute) Volume::NodeAttributeRemoved(ino_t id, Attribute *attribute)
{ {
@ -646,35 +643,35 @@ Volume::NodeAttributeRemoved(ino_t id, Attribute *attribute)
return error; return error;
} }
// GetNameIndex
NameIndex * NameIndex *
Volume::GetNameIndex() const Volume::GetNameIndex() const
{ {
return (fIndexDirectory ? fIndexDirectory->GetNameIndex() : NULL); return (fIndexDirectory ? fIndexDirectory->GetNameIndex() : NULL);
} }
// GetLastModifiedIndex
LastModifiedIndex * LastModifiedIndex *
Volume::GetLastModifiedIndex() const Volume::GetLastModifiedIndex() const
{ {
return (fIndexDirectory ? fIndexDirectory->GetLastModifiedIndex() : NULL); return (fIndexDirectory ? fIndexDirectory->GetLastModifiedIndex() : NULL);
} }
// GetSizeIndex
SizeIndex * SizeIndex *
Volume::GetSizeIndex() const Volume::GetSizeIndex() const
{ {
return (fIndexDirectory ? fIndexDirectory->GetSizeIndex() : NULL); return (fIndexDirectory ? fIndexDirectory->GetSizeIndex() : NULL);
} }
// FindIndex
Index * Index *
Volume::FindIndex(const char *name) Volume::FindIndex(const char *name)
{ {
return (fIndexDirectory ? fIndexDirectory->FindIndex(name) : NULL); return (fIndexDirectory ? fIndexDirectory->FindIndex(name) : NULL);
} }
// FindAttributeIndex
AttributeIndex * AttributeIndex *
Volume::FindAttributeIndex(const char *name, uint32 type) Volume::FindAttributeIndex(const char *name, uint32 type)
{ {
@ -682,7 +679,7 @@ Volume::FindAttributeIndex(const char *name, uint32 type)
? fIndexDirectory->FindAttributeIndex(name, type) : NULL); ? fIndexDirectory->FindAttributeIndex(name, type) : NULL);
} }
// AddQuery
void void
Volume::AddQuery(Query *query) Volume::AddQuery(Query *query)
{ {
@ -692,7 +689,7 @@ Volume::AddQuery(Query *query)
fQueries.Insert(query); fQueries.Insert(query);
} }
// RemoveQuery
void void
Volume::RemoveQuery(Query *query) Volume::RemoveQuery(Query *query)
{ {
@ -702,7 +699,7 @@ Volume::RemoveQuery(Query *query)
fQueries.Remove(query); fQueries.Remove(query);
} }
// UpdateLiveQueries
void void
Volume::UpdateLiveQueries(Entry *entry, Node* node, const char *attribute, Volume::UpdateLiveQueries(Entry *entry, Node* node, const char *attribute,
int32 type, const uint8 *oldKey, size_t oldLength, const uint8 *newKey, int32 type, const uint8 *oldKey, size_t oldLength, const uint8 *newKey,
@ -718,7 +715,7 @@ Volume::UpdateLiveQueries(Entry *entry, Node* node, const char *attribute,
} }
} }
// GetAllocationInfo
void void
Volume::GetAllocationInfo(AllocationInfo &info) Volume::GetAllocationInfo(AllocationInfo &info)
{ {
@ -733,7 +730,7 @@ Volume::GetAllocationInfo(AllocationInfo &info)
info.AddStringAllocation(fName.GetLength()); info.AddStringAllocation(fName.GetLength());
} }
// ReadLock
bool bool
Volume::ReadLock() Volume::ReadLock()
{ {
@ -743,14 +740,14 @@ Volume::ReadLock()
return ok; return ok;
} }
// ReadUnlock
void void
Volume::ReadUnlock() Volume::ReadUnlock()
{ {
rw_lock_read_unlock(&fLocker); rw_lock_read_unlock(&fLocker);
} }
// WriteLock
bool bool
Volume::WriteLock() Volume::WriteLock()
{ {
@ -760,21 +757,21 @@ Volume::WriteLock()
return ok; return ok;
} }
// WriteUnlock
void void
Volume::WriteUnlock() Volume::WriteUnlock()
{ {
rw_lock_write_unlock(&fLocker); rw_lock_write_unlock(&fLocker);
} }
// IteratorLock
bool bool
Volume::IteratorLock() Volume::IteratorLock()
{ {
return recursive_lock_lock(&fIteratorLocker) == B_OK; return recursive_lock_lock(&fIteratorLocker) == B_OK;
} }
// IteratorUnlock
void void
Volume::IteratorUnlock() Volume::IteratorUnlock()
{ {

View File

@ -53,7 +53,7 @@ class SizeIndex;
const ino_t kRootParentID = 0; const ino_t kRootParentID = 0;
// NodeListenerValue
class NodeListenerValue { class NodeListenerValue {
public: public:
inline NodeListenerValue() {} inline NodeListenerValue() {}
@ -70,7 +70,7 @@ public:
}; };
typedef List<NodeListenerValue> NodeListenerList; typedef List<NodeListenerValue> NodeListenerList;
// EntryListenerValue
class EntryListenerValue { class EntryListenerValue {
public: public:
inline EntryListenerValue() {} inline EntryListenerValue() {}
@ -88,7 +88,7 @@ public:
}; };
typedef List<EntryListenerValue> EntryListenerList; typedef List<EntryListenerValue> EntryListenerList;
// Volume
class Volume { class Volume {
public: public:
Volume(fs_volume* volume); Volume(fs_volume* volume);
@ -173,22 +173,26 @@ protected:
private: private:
typedef DoublyLinkedList<Query> QueryList; typedef DoublyLinkedList<Query> QueryList;
rw_lock fLocker;
String fName;
ino_t fNextNodeID; ino_t fNextNodeID;
NodeTable *fNodeTable; NodeTable *fNodeTable;
DirectoryEntryTable *fDirectoryEntryTable; DirectoryEntryTable *fDirectoryEntryTable;
IndexDirectory *fIndexDirectory; IndexDirectory *fIndexDirectory;
Directory *fRootDirectory; Directory *fRootDirectory;
String fName;
rw_lock fLocker;
recursive_lock fIteratorLocker;
recursive_lock fQueryLocker;
NodeListenerTree *fNodeListeners; NodeListenerTree *fNodeListeners;
NodeListenerList fAnyNodeListeners; NodeListenerList fAnyNodeListeners;
EntryListenerTree *fEntryListeners; EntryListenerTree *fEntryListeners;
EntryListenerList fAnyEntryListeners; EntryListenerList fAnyEntryListeners;
recursive_lock fIteratorLocker;
recursive_lock fQueryLocker;
QueryList fQueries; QueryList fQueries;
bigtime_t fAccessTime; bigtime_t fAccessTime;
bool fMounted; bool fMounted;
}; };
#endif // VOLUME_H #endif // VOLUME_H