2 * Copyright 2012 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
6 * Paweł Dziepak, pdziepak@quarnos.org
12 #include "FileSystem.h"
16 InodeName::InodeName(InodeNames
* parent
, const char* name
)
22 fParent
->AcquireReference();
26 InodeName::~InodeName()
29 fParent
->ReleaseReference();
30 free(const_cast<char*>(fName
));
34 InodeNames::InodeNames()
36 mutex_init(&fLock
, NULL
);
40 InodeNames::~InodeNames()
42 while (!fNames
.IsEmpty())
43 delete fNames
.RemoveHead();
44 mutex_destroy(&fLock
);
49 InodeNames::AddName(InodeNames
* parent
, const char* name
)
53 InodeName
* current
= fNames
.Head();
54 while (current
!= NULL
) {
55 if (current
->fParent
== parent
&& !strcmp(current
->fName
, name
))
57 current
= fNames
.GetNext(current
);
60 InodeName
* newName
= new InodeName(parent
, name
);
69 InodeNames::RemoveName(InodeNames
* parent
, const char* name
)
73 InodeName
* previous
= NULL
;
74 InodeName
* current
= fNames
.Head();
75 while (current
!= NULL
) {
76 if (current
->fParent
== parent
&& !strcmp(current
->fName
, name
)) {
77 fNames
.Remove(previous
, current
);
83 current
= fNames
.GetNext(current
);
86 return fNames
.IsEmpty();
101 fNames
->ReleaseReference();
105 FileInfo::FileInfo(const FileInfo
& fi
)
112 fNames
->AcquireReference();
117 FileInfo::operator=(const FileInfo
& fi
)
119 fFileId
= fi
.fFileId
;
120 fHandle
= fi
.fHandle
;
123 fNames
->ReleaseReference();
126 fNames
->AcquireReference();
133 FileInfo::UpdateFileHandles(FileSystem
* fs
)
137 Request
request(fs
->Server(), fs
);
138 RequestBuilder
& req
= request
.Builder();
142 uint32 lookupCount
= 0;
143 const char** path
= fs
->Path();
145 for (; path
[lookupCount
] != NULL
; lookupCount
++)
146 req
.LookUp(path
[lookupCount
]);
150 InodeNames
* names
= fNames
;
151 for (i
= 0; names
!= NULL
; i
++) {
152 if (names
->fNames
.IsEmpty())
153 return B_ENTRY_NOT_FOUND
;
155 names
= names
->fNames
.Head()->fParent
;
160 InodeNames
** pathNames
= new InodeNames
*[i
];
161 if (pathNames
== NULL
)
164 for (i
= 0; names
!= NULL
; i
++) {
165 pathNames
[i
] = names
;
166 names
= names
->fNames
.Head()->fParent
;
170 if (!strcmp(pathNames
[i
- 1]->fNames
.Head()->fName
, ""))
173 req
.LookUp(pathNames
[i
- 1]->fNames
.Head()->fName
);
181 if (fs
->IsAttrSupported(FATTR4_FILEID
)) {
183 attr
.fAttribute
= FATTR4_FILEID
;
184 attr
.fFreePointer
= false;
185 attr
.fData
.fValue64
= fFileId
;
186 req
.Verify(&attr
, 1);
189 status_t result
= request
.Send();
193 ReplyInterpreter
& reply
= request
.Reply();
196 for (uint32 i
= 0; i
< lookupCount
; i
++)
200 result
= reply
.GetFH(&handle
);
204 if (fs
->IsAttrSupported(FATTR4_FILEID
)) {
205 result
= reply
.Verify();
211 fNames
->fHandle
= handle
;