BPicture: Fix archive constructor.
[haiku.git] / src / add-ons / kernel / file_systems / nfs4 / Inode.h
blob1e6d47bd319dab4f8362ce06c684aa383301c03c
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 INODE_H
9 #define INODE_H
12 #include "DirectoryCache.h"
13 #include "MetadataCache.h"
14 #include "NFS4Inode.h"
15 #include "OpenState.h"
18 class Delegation;
20 class Inode : public NFS4Inode {
21 public:
22 static status_t CreateInode(FileSystem* fs, const FileInfo& fi,
23 Inode** inode);
24 virtual ~Inode();
26 inline ino_t ID() const;
27 inline mode_t Type() const;
28 virtual const char* Name() const;
29 inline FileSystem* GetFileSystem() const;
31 inline void SetOpenState(OpenState* state);
33 inline void* FileCache();
34 status_t RevalidateFileCache();
36 inline uint64 MaxFileSize();
38 inline uint64 Change();
39 inline bool Dirty();
41 inline OpenState* GetOpenState();
43 void SetDelegation(Delegation* delegation);
44 void RecallDelegation(bool truncate = false);
45 void RecallReadDelegation();
47 status_t LookUp(const char* name, ino_t* id);
49 status_t Access(int mode);
51 status_t Commit();
52 status_t SyncAndCommit(bool force = false);
54 status_t CreateObject(const char* name, const char* path,
55 int mode, FileType type, ino_t* id);
57 status_t CreateLink(const char* name, const char* path,
58 int mode, ino_t* id);
60 status_t Link(Inode* dir, const char* name);
61 status_t Remove(const char* name, FileType type,
62 ino_t* id = NULL);
63 static status_t Rename(Inode* from, Inode* to,
64 const char* fromName, const char* toName,
65 bool attribute = false, ino_t* id = NULL,
66 ino_t* oldID = NULL);
68 status_t Stat(struct stat* st,
69 OpenAttrCookie* attr = NULL);
70 status_t WriteStat(const struct stat* st, uint32 mask,
71 OpenAttrCookie* attr = NULL);
73 status_t Create(const char* name, int mode, int perms,
74 OpenFileCookie* cookie,
75 OpenDelegationData* data, ino_t* id);
76 status_t Open(int mode, OpenFileCookie* cookie);
77 status_t Close(OpenFileCookie* cookie);
79 status_t OpenAttr(const char* name, int mode,
80 OpenAttrCookie* cookie, bool create,
81 int32 type = 0);
82 status_t CloseAttr(OpenAttrCookie* cookie);
84 status_t Read(OpenFileCookie* cookie, off_t pos,
85 void* buffer, size_t* length);
86 status_t Write(OpenFileCookie* cookie, off_t pos,
87 const void* buffer, size_t* _length);
89 status_t ReadDirect(OpenStateCookie* cookie, off_t pos,
90 void* buffer, size_t* length, bool* eof);
91 status_t WriteDirect(OpenStateCookie* cookie, off_t pos,
92 const void* buffer, size_t* _length);
94 status_t CreateDir(const char* name, int mode,
95 ino_t* id);
96 status_t OpenDir(OpenDirCookie* cookie);
97 status_t ReadDir(void* buffer, uint32 size,
98 uint32* count, OpenDirCookie* cookie);
100 status_t OpenAttrDir(OpenDirCookie* cookie);
102 status_t TestLock(OpenFileCookie* cookie,
103 struct flock* lock);
104 status_t AcquireLock(OpenFileCookie* cookie,
105 const struct flock* lock, bool wait);
106 status_t ReleaseLock(OpenFileCookie* cookie,
107 const struct flock* lock);
108 status_t ReleaseAllLocks(OpenFileCookie* cookie);
110 status_t GetDirSnapshot(DirectoryCacheSnapshot**
111 _snapshot, OpenDirCookie* cookie,
112 uint64* _change, bool attribute);
114 status_t LoadAttrDirHandle();
116 static inline ino_t FileIdToInoT(uint64 fileid);
118 void BeginAIOOp();
119 void EndAIOOp();
120 inline void WaitAIOComplete();
121 protected:
122 Inode();
124 void ReleaseOpenState();
126 status_t CreateState(const char* name, int mode,
127 int perms, OpenState* state,
128 OpenDelegationData* data);
130 void ReturnDelegation(bool truncate);
132 status_t ReadDirUp(struct dirent* de, uint32 pos,
133 uint32 size);
134 status_t FillDirEntry(struct dirent* de, ino_t id,
135 const char* name, uint32 pos, uint32 size);
137 status_t ChildAdded(const char* name, uint64 fileID,
138 const FileHandle& fileHandle);
140 status_t GetStat(struct stat* st,
141 OpenAttrCookie* attr = NULL);
143 char* AttrToFileName(const char* path);
145 static inline status_t CheckLockType(short ltype, uint32 mode);
147 private:
148 uint32 fType;
150 MetadataCache fMetaCache;
151 DirectoryCache* fCache;
152 DirectoryCache* fAttrCache;
154 rw_lock fDelegationLock;
155 Delegation* fDelegation;
157 uint64 fChange;
158 void* fFileCache;
159 mutex fFileCacheLock;
160 uint64 fMaxFileSize;
162 OpenState* fOpenState;
163 mutex fStateLock;
165 rw_lock fWriteLock;
166 bool fWriteDirty;
168 sem_id fAIOWait;
169 uint32 fAIOCount;
170 mutex fAIOLock;
174 inline void
175 Inode::WaitAIOComplete()
177 acquire_sem(fAIOWait);
178 release_sem(fAIOWait);
182 inline ino_t
183 Inode::FileIdToInoT(uint64 fileid)
185 if (sizeof(ino_t) >= sizeof(uint64))
186 return fileid;
187 else
188 return (ino_t)fileid ^ (fileid >>
189 (sizeof(uint64) - sizeof(ino_t)) * 8);
193 inline ino_t
194 Inode::ID() const
196 return FileIdToInoT(fInfo.fFileId);
200 inline mode_t
201 Inode::Type() const
203 return sNFSFileTypeToHaiku[fType];
207 inline FileSystem*
208 Inode::GetFileSystem() const
210 ASSERT(fFileSystem != NULL);
211 return fFileSystem;
215 inline void*
216 Inode::FileCache()
218 return fFileCache;
222 inline void
223 Inode::SetOpenState(OpenState* state)
225 ASSERT(state != NULL);
226 fOpenState = state;
230 inline uint64
231 Inode::MaxFileSize()
233 return fMaxFileSize;
237 inline uint64
238 Inode::Change()
240 return fChange;
244 inline bool
245 Inode::Dirty()
247 return fWriteDirty;
251 inline OpenState*
252 Inode::GetOpenState()
254 return fOpenState;
258 #endif // INODE_H