BPicture: Fix archive constructor.
[haiku.git] / src / add-ons / kernel / file_systems / nfs4 / InodeIdMap.cpp
blob7f1ca2c5290653fc1390e0fbcdaa3c8b9c95a282
1 /*
2 * Copyright 2013 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Paweł Dziepak, pdziepak@quarnos.org
7 */
10 #include "InodeIdMap.h"
13 status_t
14 InodeIdMap::AddName(FileInfo& fileInfo, InodeNames* parent,
15 const char* name, ino_t id)
17 MutexLocker _(fLock);
18 AVLTreeMap<ino_t, FileInfo>::Iterator iterator = fMap.Find(id);
19 if (iterator.HasCurrent()) {
20 if (fileInfo.fHandle == iterator.Current().fHandle) {
21 return iterator.CurrentValuePointer()->fNames->AddName(parent,
22 name);
26 fMap.Remove(id);
27 fileInfo.fNames = new InodeNames;
28 if (fileInfo.fNames == NULL)
29 return B_NO_MEMORY;
31 fileInfo.fNames->fHandle = fileInfo.fHandle;
32 status_t result = fileInfo.fNames->AddName(parent, name);
33 if (result != B_OK) {
34 delete fileInfo.fNames;
35 return result;
38 return fMap.Insert(id, fileInfo);
42 bool
43 InodeIdMap::RemoveName(ino_t id, InodeNames* parent, const char* name)
45 ASSERT(name != NULL);
47 MutexLocker _(fLock);
48 AVLTreeMap<ino_t, FileInfo>::Iterator iterator = fMap.Find(id);
49 if (!iterator.HasCurrent())
50 return true;
52 FileInfo* fileInfo = iterator.CurrentValuePointer();
54 return fileInfo->fNames->RemoveName(parent, name);
58 status_t
59 InodeIdMap::RemoveEntry(ino_t id)
61 MutexLocker _(fLock);
62 return fMap.Remove(id);
66 status_t
67 InodeIdMap::GetFileInfo(FileInfo* fileInfo, ino_t id)
69 ASSERT(fileInfo != NULL);
71 MutexLocker _(fLock);
72 AVLTreeMap<ino_t, FileInfo>::Iterator iterator = fMap.Find(id);
73 if (!iterator.HasCurrent())
74 return B_ENTRY_NOT_FOUND;
76 *fileInfo = iterator.Current();
77 if (fileInfo->fNames->fNames.IsEmpty())
78 return B_ENTRY_NOT_FOUND;
79 return B_OK;