1 /*
2 * Copyright 2012 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 *
5 * Authors:
6 * Paweł Dziepak, pdziepak@quarnos.org
7 */
8 #ifndef REPLYINTERPRETER_H
9 #define REPLYINTERPRETER_H
10
11
12 #include <SupportDefs.h>
13
14 #include "FileInfo.h"
15 #include "NFS4Defs.h"
16 #include "RPCReply.h"
17
18
19 struct FSLocation {
20 const char** fRootPath;
21
22 const char** fLocations;
23 uint32 fCount;
24
25 ~FSLocation();
26 };
27
28 struct FSLocations {
29 const char** fRootPath;
30
31 FSLocation* fLocations;
32 uint32 fCount;
33
34 ~FSLocations();
35 };
36
37 struct AttrValue {
38 AttrValue();
39 ~AttrValue();
40
41 uint8 fAttribute;
42 bool fFreePointer;
43 union {
44 uint32 fValue32;
45 uint64 fValue64;
46 void* fPointer;
47 FSLocations* fLocations;
48 } fData;
49 };
50
51 struct DirEntry {
52 const char* fName;
53 AttrValue* fAttrs;
54 uint32 fAttrCount;
55
56 DirEntry();
57 ~DirEntry();
58 };
59
60 struct LockInfo;
61
62 class ReplyInterpreter {
63 public:
64 ReplyInterpreter(RPC::Reply* reply = NULL);
65 ~ReplyInterpreter();
66
67 inline status_t SetTo(RPC::Reply* reply);
68 inline void Reset();
69
70 inline uint32 NFS4Error();
71
72 status_t Access(uint32* supported, uint32* allowed);
73 status_t Close();
74 status_t Commit();
75 status_t Create(uint64* before, uint64* after, bool& atomic);
76 inline status_t DelegReturn();
77 status_t GetAttr(AttrValue** attrs, uint32* count);
78 status_t GetFH(FileHandle* fh);
79 status_t Link(uint64* before, uint64* after, bool& atomic);
80 status_t Lock(LockInfo* linfo);
81 status_t LockT(uint64* pos, uint64* len, LockType* type);
82 status_t LockU(LockInfo* linfo);
83 inline status_t LookUp();
84 inline status_t LookUpUp();
85 inline status_t Nverify();
86 status_t Open(uint32* id, uint32* seq, bool* confirm,
87 OpenDelegationData* delegData,
88 ChangeInfo* changeInfo = NULL);
89 inline status_t OpenAttrDir();
90 status_t OpenConfirm(uint32* stateSeq);
91 inline status_t PutFH();
92 inline status_t PutRootFH();
93 status_t Read(void* buffer, uint32* size, bool* eof);
94 status_t ReadDir(uint64* cookie, uint64* cookieVerf,
95 DirEntry** dirents, uint32* count, bool* eof);
96 status_t ReadLink(void* buffer, uint32* size, uint32 maxSize);
97 status_t Remove(uint64* before, uint64* after, bool& atomic);
98 status_t Rename(uint64* fromBefore, uint64* fromAfter,
99 bool& fromAtomic, uint64* toBefore, uint64* toAfter,
100 bool& toAtomic);
101 inline status_t Renew();
102 inline status_t SaveFH();
103 status_t SetAttr();
104 status_t SetClientID(uint64* clientid, uint64* verifier);
105 inline status_t SetClientIDConfirm();
106 inline status_t Verify();
107 status_t Write(uint32* size);
108 inline status_t ReleaseLockOwner();
109
110 private:
111 void _ParseHeader();
112
113 static const char** _GetPath(XDR::ReadStream& stream);
114
115 status_t _DecodeAttrs(XDR::ReadStream& stream, AttrValue** attrs,
116 uint32* count);
117 status_t _OperationError(Opcode op);
118
119 static status_t _NFS4ErrorToHaiku(uint32 x);
120
121 uint32 fNFS4Error;
122 bool fDecodeError;
123 RPC::Reply* fReply;
124 };
125
126
127 inline status_t
SetTo(RPC::Reply * _reply)128 ReplyInterpreter::SetTo(RPC::Reply* _reply)
129 {
130 if (fReply != NULL)
131 return B_DONT_DO_THAT;
132
133 fDecodeError = false;
134 fReply = _reply;
135
136 if (fReply != NULL)
137 _ParseHeader();
138
139 return B_OK;
140 }
141
142
143 inline void
Reset()144 ReplyInterpreter::Reset()
145 {
146 delete fReply;
147 fReply = NULL;
148 fDecodeError = false;
149 }
150
151
152 inline uint32
NFS4Error()153 ReplyInterpreter::NFS4Error()
154 {
155 return fNFS4Error;
156 }
157
158
159 inline status_t
DelegReturn()160 ReplyInterpreter::DelegReturn()
161 {
162 return _OperationError(OpDelegReturn);
163 }
164
165
166 inline status_t
LookUp()167 ReplyInterpreter::LookUp()
168 {
169 return _OperationError(OpLookUp);
170 }
171
172
173 inline status_t
LookUpUp()174 ReplyInterpreter::LookUpUp()
175 {
176 return _OperationError(OpLookUpUp);
177 }
178
179
180 inline status_t
OpenAttrDir()181 ReplyInterpreter::OpenAttrDir()
182 {
183 return _OperationError(OpOpenAttrDir);
184 }
185
186
187 inline status_t
Nverify()188 ReplyInterpreter::Nverify()
189 {
190 return _OperationError(OpNverify);
191 }
192
193
194 inline status_t
PutFH()195 ReplyInterpreter::PutFH()
196 {
197 return _OperationError(OpPutFH);
198 }
199
200
201 inline status_t
PutRootFH()202 ReplyInterpreter::PutRootFH()
203 {
204 return _OperationError(OpPutRootFH);
205 }
206
207
208 inline status_t
Renew()209 ReplyInterpreter::Renew()
210 {
211 return _OperationError(OpRenew);
212 }
213
214
215 inline status_t
SaveFH()216 ReplyInterpreter::SaveFH()
217 {
218 return _OperationError(OpSaveFH);
219 }
220
221
222 inline status_t
SetClientIDConfirm()223 ReplyInterpreter::SetClientIDConfirm()
224 {
225 return _OperationError(OpSetClientIDConfirm);
226 }
227
228
229 inline status_t
Verify()230 ReplyInterpreter::Verify()
231 {
232 return _OperationError(OpVerify);
233 }
234
235
236 inline status_t
ReleaseLockOwner()237 ReplyInterpreter::ReleaseLockOwner()
238 {
239 return _OperationError(OpReleaseLockOwner);
240 }
241
242
243 #endif // REPLYINTERPRETER_H
244
245