2 * Copyright 2013 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
6 * Paweł Dziepak, pdziepak@quarnos.org
10 #include "InodeIdMap.h"
14 InodeIdMap::AddName(FileInfo
& fileInfo
, InodeNames
* parent
,
15 const char* name
, ino_t id
)
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
,
27 fileInfo
.fNames
= new InodeNames
;
28 if (fileInfo
.fNames
== NULL
)
31 fileInfo
.fNames
->fHandle
= fileInfo
.fHandle
;
32 status_t result
= fileInfo
.fNames
->AddName(parent
, name
);
34 delete fileInfo
.fNames
;
38 return fMap
.Insert(id
, fileInfo
);
43 InodeIdMap::RemoveName(ino_t id
, InodeNames
* parent
, const char* name
)
48 AVLTreeMap
<ino_t
, FileInfo
>::Iterator iterator
= fMap
.Find(id
);
49 if (!iterator
.HasCurrent())
52 FileInfo
* fileInfo
= iterator
.CurrentValuePointer();
54 return fileInfo
->fNames
->RemoveName(parent
, name
);
59 InodeIdMap::RemoveEntry(ino_t id
)
62 return fMap
.Remove(id
);
67 InodeIdMap::GetFileInfo(FileInfo
* fileInfo
, ino_t id
)
69 ASSERT(fileInfo
!= NULL
);
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
;