xref: /haiku/src/add-ons/kernel/file_systems/nfs4/ReplyInterpreter.h (revision f5baf2ef9f3afe4df5e1565ba2651a0ae3ea38a9)
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 "NFS4Defs.h"
15 #include "RPCReply.h"
16 
17 
18 struct FSLocation {
19 	const char*			fRootPath;
20 	const char**		fLocations;
21 	uint32				fCount;
22 
23 						~FSLocation();
24 };
25 
26 struct FSLocations {
27 	const char*			fRootPath;
28 	FSLocation*			fLocations;
29 	uint32				fCount;
30 
31 						~FSLocations();
32 };
33 
34 struct AttrValue {
35 			AttrValue();
36 			~AttrValue();
37 
38 	uint8	fAttribute;
39 	bool	fFreePointer;
40 	union {
41 			uint32			fValue32;
42 			uint64			fValue64;
43 			void*			fPointer;
44 			FSLocations*	fLocations;
45 	} fData;
46 };
47 
48 struct DirEntry {
49 	const char*			fName;
50 	AttrValue*			fAttrs;
51 	uint32				fAttrCount;
52 
53 						DirEntry();
54 						~DirEntry();
55 };
56 
57 class ReplyInterpreter {
58 public:
59 						ReplyInterpreter(RPC::Reply* reply = NULL);
60 						~ReplyInterpreter();
61 
62 	inline	status_t	SetTo(RPC::Reply* reply);
63 	inline	void		Reset();
64 
65 	inline	uint32		NFS4Error();
66 
67 			status_t	Access(uint32* supported, uint32* allowed);
68 			status_t	Close();
69 			status_t	Create();
70 			status_t	GetAttr(AttrValue** attrs, uint32* count);
71 			status_t	GetFH(Filehandle* fh);
72 			status_t	Link();
73 	inline	status_t	LookUp();
74 	inline	status_t	LookUpUp();
75 			status_t	Open(uint32* id, uint32* seq, bool* confirm);
76 			status_t	OpenConfirm(uint32* stateSeq);
77 	inline	status_t	PutFH();
78 	inline	status_t	PutRootFH();
79 			status_t	Read(void* buffer, uint32* size, bool* eof);
80 			status_t	ReadDir(uint64* cookie, uint64* cookieVerf,
81 							DirEntry** dirents, uint32* count, bool* eof);
82 			status_t	ReadLink(void* buffer, uint32* size, uint32 maxSize);
83 			status_t	Remove();
84 			status_t	Rename();
85 	inline	status_t	Renew();
86 	inline	status_t	SaveFH();
87 			status_t	SetClientID(uint64* clientid, uint64* verifier);
88 	inline	status_t	SetClientIDConfirm();
89 	inline	status_t	Verify();
90 
91 private:
92 			void		_ParseHeader();
93 
94 			status_t	_DecodeAttrs(XDR::ReadStream& stream, AttrValue** attrs,
95 							uint32* count);
96 			status_t	_OperationError(Opcode op);
97 
98 	static	status_t	_NFS4ErrorToHaiku(uint32 x);
99 
100 			uint32		fNFS4Error;
101 			RPC::Reply*	fReply;
102 };
103 
104 
105 inline status_t
106 ReplyInterpreter::SetTo(RPC::Reply* _reply)
107 {
108 	if (fReply != NULL)
109 		return B_DONT_DO_THAT;
110 
111 	fReply = _reply;
112 
113 	if (fReply != NULL)
114 		_ParseHeader();
115 
116 	return B_OK;
117 }
118 
119 
120 inline void
121 ReplyInterpreter::Reset()
122 {
123 	delete fReply;
124 	fReply = NULL;
125 }
126 
127 
128 inline uint32
129 ReplyInterpreter::NFS4Error()
130 {
131 	return fNFS4Error;
132 }
133 
134 
135 inline status_t
136 ReplyInterpreter::LookUp()
137 {
138 	return _OperationError(OpLookUp);
139 }
140 
141 
142 inline status_t
143 ReplyInterpreter::LookUpUp()
144 {
145 	return _OperationError(OpLookUpUp);
146 }
147 
148 
149 inline status_t
150 ReplyInterpreter::PutFH()
151 {
152 	return _OperationError(OpPutFH);
153 }
154 
155 
156 inline status_t
157 ReplyInterpreter::PutRootFH()
158 {
159 	return _OperationError(OpPutRootFH);
160 }
161 
162 
163 inline status_t
164 ReplyInterpreter::Renew()
165 {
166 	return _OperationError(OpRenew);
167 }
168 
169 
170 inline status_t
171 ReplyInterpreter::SaveFH()
172 {
173 	return _OperationError(OpSaveFH);
174 }
175 
176 
177 inline status_t
178 ReplyInterpreter::SetClientIDConfirm()
179 {
180 	return _OperationError(OpSetClientIDConfirm);
181 }
182 
183 
184 inline status_t
185 ReplyInterpreter::Verify()
186 {
187 	return _OperationError(OpVerify);
188 }
189 
190 
191 #endif	// REPLYINTERPRETER_H
192 
193