BPicture: Fix archive constructor.
[haiku.git] / src / add-ons / kernel / file_systems / nfs4 / VnodeToInode.h
blobee04a454c3ff62eeca852b606d871d908f976660
1 /*
2 * Copyright 2012 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Paweł Dziepak, pdziepak@quarnos.org
7 */
8 #ifndef VNODETOINODE_H
9 #define VNODETOINODE_H
11 #include <lock.h>
12 #include <SupportDefs.h>
13 #include <util/AutoLock.h>
15 #include "Inode.h"
16 #include "InodeIdMap.h"
17 #include "RootInode.h"
19 class VnodeToInode {
20 public:
21 inline VnodeToInode(ino_t id, FileSystem* fileSystem);
22 inline ~VnodeToInode();
24 inline void Lock();
25 inline void Unlock();
27 inline Inode* GetPointer() const;
28 Inode* Get();
29 void Replace(Inode* newInode);
31 bool Unlink(InodeNames* parent, const char* name);
32 inline void Clear();
34 inline ino_t ID() const;
36 inline bool IsRoot() const;
37 private:
38 ino_t fID;
39 rw_lock fLock;
41 Inode* fInode;
42 FileSystem* fFileSystem;
45 class VnodeToInodeLocking {
46 public:
47 inline bool Lock(VnodeToInode* vti)
49 vti->Lock();
50 return true;
53 inline void Unlock(VnodeToInode* vti)
55 vti->Unlock();
59 typedef AutoLocker<VnodeToInode, VnodeToInodeLocking> VnodeToInodeLocker;
61 inline
62 VnodeToInode::VnodeToInode(ino_t id, FileSystem* fileSystem)
64 fID(id),
65 fInode(NULL),
66 fFileSystem(fileSystem)
68 rw_lock_init(&fLock, NULL);
72 inline
73 VnodeToInode::~VnodeToInode()
75 Clear();
76 if (fFileSystem != NULL && !IsRoot())
77 fFileSystem->InoIdMap()->RemoveEntry(fID);
78 rw_lock_destroy(&fLock);
82 inline void
83 VnodeToInode::Lock()
85 rw_lock_read_lock(&fLock);
89 inline void
90 VnodeToInode::Unlock()
92 rw_lock_read_unlock(&fLock);
96 inline void
97 VnodeToInode::Clear()
99 Replace(NULL);
103 inline bool
104 VnodeToInode::IsRoot() const
106 return fInode && fFileSystem && fInode->ID() == fFileSystem->Root()->ID();
110 inline Inode*
111 VnodeToInode::GetPointer() const
113 return fInode;
117 inline ino_t
118 VnodeToInode::ID() const
120 return fID;
123 #endif // VNODETOINODE_H