* Changed Vnode to be more flexible to use, and reduced its memory footprint

a bit.
* This also fixes a bug Salvatore pointed me to: Vnode would also call
  put_vnode() on destruction if get_vnode() failed earlier.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26097 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2008-06-23 09:55:04 +00:00
parent 1fd024be6a
commit 45a237d7f4
+45 -18
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2001-2007, Axel Dörfler, [email protected]. * Copyright 2001-2008, Axel Dörfler, [email protected].
* This file may be used under the terms of the MIT License. * This file may be used under the terms of the MIT License.
*/ */
#ifndef INODE_H #ifndef INODE_H
@@ -253,46 +253,73 @@ class NodeGetter : public CachedBlock {
class Vnode { class Vnode {
public: public:
Vnode(Volume *volume, ino_t id) Vnode(Volume* volume, ino_t id)
: :
fVolume(volume), fInode(NULL)
fID(id)
{ {
SetTo(volume, id);
} }
Vnode(Volume *volume, block_run run) Vnode(Volume* volume, block_run run)
: :
fVolume(volume), fInode(NULL)
fID(volume->ToVnode(run)) {
SetTo(volume, run);
}
Vnode()
:
fStatus(B_NO_INIT),
fInode(NULL)
{ {
} }
~Vnode() ~Vnode()
{ {
Put(); Unset();
} }
status_t Get(Inode **_inode) status_t InitCheck()
{ {
// should we check inode against NULL here? it should not be necessary return fStatus;
return get_vnode(fVolume->FSVolume(), fID, (void **)_inode);
} }
void Put() void Unset()
{ {
if (fVolume) if (fInode != NULL) {
put_vnode(fVolume->FSVolume(), fID); put_vnode(fInode->GetVolume()->FSVolume(), fInode->ID());
fVolume = NULL; fInode = NULL;
fStatus = B_NO_INIT;
}
}
status_t SetTo(Volume* volume, ino_t id)
{
Unset();
return fStatus = get_vnode(volume->FSVolume(), id, (void**)&fInode);
}
status_t SetTo(Volume* volume, block_run run)
{
return SetTo(volume, volume->ToVnode(run));
}
status_t Get(Inode** _inode)
{
if (fStatus == B_OK)
*_inode = fInode;
return fStatus;
} }
void Keep() void Keep()
{ {
fVolume = NULL; fInode = NULL;
} }
private: private:
Volume *fVolume; status_t fStatus;
ino_t fID; Inode* fInode;
}; };