xref: /haiku/src/add-ons/kernel/file_systems/nfs4/VnodeToInode.cpp (revision 25a7b01d15612846f332751841da3579db313082)
1 /*
2  * Copyright 2012 Haiku, Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Paweł Dziepak, pdziepak@quarnos.org
7  */
8 
9 
10 #include "VnodeToInode.h"
11 
12 
13 Inode*
Get()14 VnodeToInode::Get()
15 {
16 	if (fInode == NULL) {
17 		status_t result = fFileSystem->GetInode(fID, &fInode);
18 		if (result != B_OK)
19 			fInode = NULL;
20 	}
21 
22 	return fInode;
23 }
24 
25 
26 void
Replace(Inode * newInode)27 VnodeToInode::Replace(Inode* newInode)
28 {
29 	WriteLocker _(fLock);
30 	if (!IsRoot())
31 		delete fInode;
32 
33 	fInode = newInode;
34 }
35 
36 
37 bool
Unlink(InodeNames * parent,const char * name)38 VnodeToInode::Unlink(InodeNames* parent, const char* name)
39 {
40 	WriteLocker _(fLock);
41 	if (fInode != NULL && !IsRoot()) {
42 		bool removed = fInode->GetFileSystem()->InoIdMap()->RemoveName(fID,
43 			parent, name);
44 		if (removed) {
45 			delete fInode;
46 			fInode = NULL;
47 		}
48 		return removed;
49 	}
50 
51 	return false;
52 }
53 
54