btrfs: [] on the end of a struct field is a variable length array.
[haiku.git] / src / add-ons / kernel / file_systems / nfs4 / FileSystem.h
blob5fdca263a1568a383878b363625c534b95a249a0
1 /*
2 * Copyright 2012 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Paweł Dziepak, pdziepak@quarnos.org
7 */
8 #ifndef FILESYSTEM_H
9 #define FILESYSTEM_H
12 #include "Delegation.h"
13 #include "InodeIdMap.h"
14 #include "NFS4Defs.h"
15 #include "NFS4Server.h"
18 class Inode;
19 class RootInode;
21 struct MountConfiguration {
22 bool fHard;
23 int fRetryLimit;
24 bigtime_t fRequestTimeout;
26 bool fEmulateNamedAttrs;
27 bool fCacheMetadata;
29 bigtime_t fDirectoryCacheTime;
32 class FileSystem : public DoublyLinkedListLinkImpl<FileSystem> {
33 public:
34 static status_t Mount(FileSystem** pfs, RPC::Server* serv,
35 const char* path, const char* serverName,
36 dev_t id,
37 const MountConfiguration& configuration);
38 ~FileSystem();
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();
81 private:
82 FileSystem(const MountConfiguration& config);
84 static status_t _ParsePath(RequestBuilder& req, uint32& count,
85 const char* _path);
87 mutex fCreateFileLock;
89 mutex fDelegationLock;
90 DoublyLinkedList<Delegation> fDelegationList;
91 AVLTreeMap<FileHandle, Delegation*> fHandleToDelegation;
93 DoublyLinkedList<OpenState> fOpenFiles;
94 uint32 fOpenCount;
95 mutex fOpenLock;
97 uint64 fOpenOwner;
98 uint32 fOpenOwnerSequence;
99 mutex fOpenOwnerLock;
101 uint32 fExpireType;
102 uint32 fSupAttrs[2];
103 bool fNamedAttrs;
105 FileSystemId fFsId;
106 const char** fPath;
108 RootInode* fRoot;
110 RPC::Server* fServer;
112 int64 fId;
113 dev_t fDevId;
115 InodeIdMap fInoIdMap;
117 MountConfiguration fConfiguration;
121 inline RootInode*
122 FileSystem::Root()
124 return fRoot;
128 inline uint32
129 FileSystem::OpenFilesCount()
131 return fOpenCount;
135 inline bool
136 FileSystem::IsAttrSupported(Attribute attr) const
138 return sIsAttrSet(attr, fSupAttrs, 2);
142 inline uint32
143 FileSystem::ExpireType() const
145 return fExpireType;
149 inline RPC::Server*
150 FileSystem::Server()
152 ASSERT(fServer != NULL);
153 return fServer;
157 inline NFS4Server*
158 FileSystem::NFSServer()
160 ASSERT(fServer->PrivateData() != NULL);
161 return reinterpret_cast<NFS4Server*>(fServer->PrivateData());
165 inline const char**
166 FileSystem::Path() const
168 ASSERT(fPath != NULL);
169 return fPath;
173 inline const FileSystemId&
174 FileSystem::FsId() const
176 return fFsId;
180 inline uint64
181 FileSystem::AllocFileId()
183 return atomic_add64(&fId, 1);
187 inline dev_t
188 FileSystem::DevId() const
190 return fDevId;
194 inline InodeIdMap*
195 FileSystem::InoIdMap()
197 return &fInoIdMap;
201 inline uint64
202 FileSystem::OpenOwner() const
204 return fOpenOwner;
208 inline uint32
209 FileSystem::OpenOwnerSequenceLock()
211 mutex_lock(&fOpenOwnerLock);
212 return fOpenOwnerSequence;
216 inline void
217 FileSystem::OpenOwnerSequenceUnlock(uint32 sequence)
219 fOpenOwnerSequence = sequence;
220 mutex_unlock(&fOpenOwnerLock);
224 inline bool
225 FileSystem::NamedAttrs()
227 return fNamedAttrs;
231 inline void
232 FileSystem::SetNamedAttrs(bool attrs)
234 fNamedAttrs = attrs;
238 inline const MountConfiguration&
239 FileSystem::GetConfiguration()
241 return fConfiguration;
245 inline mutex&
246 FileSystem::CreateFileLock()
248 return fCreateFileLock;
252 #endif // FILESYSTEM_H