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 "DirectoryCache.h"
13 #include "MetadataCache.h"
14 #include "NFS4Inode.h"
15 #include "OpenState.h"
20 class Inode
: public NFS4Inode
{
22 static status_t
CreateInode(FileSystem
* fs
, const FileInfo
& fi
,
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();
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
);
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
,
60 status_t
Link(Inode
* dir
, const char* name
);
61 status_t
Remove(const char* name
, FileType type
,
63 static status_t
Rename(Inode
* from
, Inode
* to
,
64 const char* fromName
, const char* toName
,
65 bool attribute
= false, ino_t
* id
= 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
,
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
,
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
,
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
);
120 inline void WaitAIOComplete();
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
,
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
);
150 MetadataCache fMetaCache
;
151 DirectoryCache
* fCache
;
152 DirectoryCache
* fAttrCache
;
154 rw_lock fDelegationLock
;
155 Delegation
* fDelegation
;
159 mutex fFileCacheLock
;
162 OpenState
* fOpenState
;
175 Inode::WaitAIOComplete()
177 acquire_sem(fAIOWait
);
178 release_sem(fAIOWait
);
183 Inode::FileIdToInoT(uint64 fileid
)
185 if (sizeof(ino_t
) >= sizeof(uint64
))
188 return (ino_t
)fileid
^ (fileid
>>
189 (sizeof(uint64
) - sizeof(ino_t
)) * 8);
196 return FileIdToInoT(fInfo
.fFileId
);
203 return sNFSFileTypeToHaiku
[fType
];
208 Inode::GetFileSystem() const
210 ASSERT(fFileSystem
!= NULL
);
223 Inode::SetOpenState(OpenState
* state
)
225 ASSERT(state
!= NULL
);
252 Inode::GetOpenState()