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 LockInfo; 58 59 class ReplyInterpreter { 60 public: 61 ReplyInterpreter(RPC::Reply* reply = NULL); 62 ~ReplyInterpreter(); 63 64 inline status_t SetTo(RPC::Reply* reply); 65 inline void Reset(); 66 67 inline uint32 NFS4Error(); 68 69 status_t Access(uint32* supported, uint32* allowed); 70 status_t Close(); 71 status_t Create(); 72 status_t GetAttr(AttrValue** attrs, uint32* count); 73 status_t GetFH(Filehandle* fh); 74 status_t Link(); 75 status_t Lock(LockInfo* linfo); 76 status_t LockT(uint64* pos, uint64* len, LockType* type); 77 status_t LockU(LockInfo* linfo); 78 inline status_t LookUp(); 79 inline status_t LookUpUp(); 80 inline status_t Nverify(); 81 status_t Open(uint32* id, uint32* seq, bool* confirm); 82 status_t OpenConfirm(uint32* stateSeq); 83 inline status_t PutFH(); 84 inline status_t PutRootFH(); 85 status_t Read(void* buffer, uint32* size, bool* eof); 86 status_t ReadDir(uint64* cookie, uint64* cookieVerf, 87 DirEntry** dirents, uint32* count, bool* eof); 88 status_t ReadLink(void* buffer, uint32* size, uint32 maxSize); 89 status_t Remove(); 90 status_t Rename(); 91 inline status_t Renew(); 92 inline status_t SaveFH(); 93 status_t SetAttr(); 94 status_t SetClientID(uint64* clientid, uint64* verifier); 95 inline status_t SetClientIDConfirm(); 96 inline status_t Verify(); 97 status_t Write(uint32* size); 98 inline status_t ReleaseLockOwner(); 99 100 private: 101 void _ParseHeader(); 102 103 status_t _DecodeAttrs(XDR::ReadStream& stream, AttrValue** attrs, 104 uint32* count); 105 status_t _OperationError(Opcode op); 106 107 static status_t _NFS4ErrorToHaiku(uint32 x); 108 109 uint32 fNFS4Error; 110 bool fDecodeError; 111 RPC::Reply* fReply; 112 }; 113 114 115 inline status_t 116 ReplyInterpreter::SetTo(RPC::Reply* _reply) 117 { 118 if (fReply != NULL) 119 return B_DONT_DO_THAT; 120 121 fDecodeError = false; 122 fReply = _reply; 123 124 if (fReply != NULL) 125 _ParseHeader(); 126 127 return B_OK; 128 } 129 130 131 inline void 132 ReplyInterpreter::Reset() 133 { 134 delete fReply; 135 fReply = NULL; 136 fDecodeError = false; 137 } 138 139 140 inline uint32 141 ReplyInterpreter::NFS4Error() 142 { 143 return fNFS4Error; 144 } 145 146 147 inline status_t 148 ReplyInterpreter::LookUp() 149 { 150 return _OperationError(OpLookUp); 151 } 152 153 154 inline status_t 155 ReplyInterpreter::LookUpUp() 156 { 157 return _OperationError(OpLookUpUp); 158 } 159 160 161 inline status_t 162 ReplyInterpreter::Nverify() 163 { 164 return _OperationError(OpNverify); 165 } 166 167 168 inline status_t 169 ReplyInterpreter::PutFH() 170 { 171 return _OperationError(OpPutFH); 172 } 173 174 175 inline status_t 176 ReplyInterpreter::PutRootFH() 177 { 178 return _OperationError(OpPutRootFH); 179 } 180 181 182 inline status_t 183 ReplyInterpreter::Renew() 184 { 185 return _OperationError(OpRenew); 186 } 187 188 189 inline status_t 190 ReplyInterpreter::SaveFH() 191 { 192 return _OperationError(OpSaveFH); 193 } 194 195 196 inline status_t 197 ReplyInterpreter::SetClientIDConfirm() 198 { 199 return _OperationError(OpSetClientIDConfirm); 200 } 201 202 203 inline status_t 204 ReplyInterpreter::Verify() 205 { 206 return _OperationError(OpVerify); 207 } 208 209 210 inline status_t 211 ReplyInterpreter::ReleaseLockOwner() 212 { 213 return _OperationError(OpReleaseLockOwner); 214 } 215 216 217 #endif // REPLYINTERPRETER_H 218 219