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 "Delegation.h"
13 #include "InodeIdMap.h"
15 #include "NFS4Server.h"
21 struct MountConfiguration
{
24 bigtime_t fRequestTimeout
;
26 bool fEmulateNamedAttrs
;
29 bigtime_t fDirectoryCacheTime
;
32 class FileSystem
: public DoublyLinkedListLinkImpl
<FileSystem
> {
34 static status_t
Mount(FileSystem
** pfs
, RPC::Server
* serv
,
35 const char* path
, const char* serverName
,
37 const MountConfiguration
& configuration
);
40 status_t
GetInode(ino_t id
, Inode
** inode
);
41 inline RootInode
* Root();
43 status_t
Migrate(const RPC::Server
* serv
);
45 DoublyLinkedList
<OpenState
>& OpenFilesLock();
46 void OpenFilesUnlock();
47 inline uint32
OpenFilesCount();
48 void AddOpenFile(OpenState
* state
);
49 void RemoveOpenFile(OpenState
* state
);
51 DoublyLinkedList
<Delegation
>& DelegationsLock();
52 void DelegationsUnlock();
53 void AddDelegation(Delegation
* delegation
);
54 void RemoveDelegation(Delegation
* delegation
);
55 Delegation
* GetDelegation(const FileHandle
& handle
);
57 inline bool IsAttrSupported(Attribute attr
) const;
58 inline uint32
ExpireType() const;
60 inline RPC::Server
* Server();
61 inline NFS4Server
* NFSServer();
63 inline const char** Path() const;
64 inline const FileSystemId
& FsId() const;
66 inline uint64
AllocFileId();
68 inline dev_t
DevId() const;
69 inline InodeIdMap
* InoIdMap();
71 inline uint64
OpenOwner() const;
72 inline uint32
OpenOwnerSequenceLock();
73 inline void OpenOwnerSequenceUnlock(uint32 sequence
);
75 inline bool NamedAttrs();
76 inline void SetNamedAttrs(bool attrs
);
78 inline const MountConfiguration
& GetConfiguration();
80 inline mutex
& CreateFileLock();
82 FileSystem(const MountConfiguration
& config
);
84 static status_t
_ParsePath(RequestBuilder
& req
, uint32
& count
,
87 mutex fCreateFileLock
;
89 mutex fDelegationLock
;
90 DoublyLinkedList
<Delegation
> fDelegationList
;
91 AVLTreeMap
<FileHandle
, Delegation
*> fHandleToDelegation
;
93 DoublyLinkedList
<OpenState
> fOpenFiles
;
98 uint32 fOpenOwnerSequence
;
110 RPC::Server
* fServer
;
115 InodeIdMap fInoIdMap
;
117 MountConfiguration fConfiguration
;
129 FileSystem::OpenFilesCount()
136 FileSystem::IsAttrSupported(Attribute attr
) const
138 return sIsAttrSet(attr
, fSupAttrs
, 2);
143 FileSystem::ExpireType() const
152 ASSERT(fServer
!= NULL
);
158 FileSystem::NFSServer()
160 ASSERT(fServer
->PrivateData() != NULL
);
161 return reinterpret_cast<NFS4Server
*>(fServer
->PrivateData());
166 FileSystem::Path() const
168 ASSERT(fPath
!= NULL
);
173 inline const FileSystemId
&
174 FileSystem::FsId() const
181 FileSystem::AllocFileId()
183 return atomic_add64(&fId
, 1);
188 FileSystem::DevId() const
195 FileSystem::InoIdMap()
202 FileSystem::OpenOwner() const
209 FileSystem::OpenOwnerSequenceLock()
211 mutex_lock(&fOpenOwnerLock
);
212 return fOpenOwnerSequence
;
217 FileSystem::OpenOwnerSequenceUnlock(uint32 sequence
)
219 fOpenOwnerSequence
= sequence
;
220 mutex_unlock(&fOpenOwnerLock
);
225 FileSystem::NamedAttrs()
232 FileSystem::SetNamedAttrs(bool attrs
)
238 inline const MountConfiguration
&
239 FileSystem::GetConfiguration()
241 return fConfiguration
;
246 FileSystem::CreateFileLock()
248 return fCreateFileLock
;
252 #endif // FILESYSTEM_H