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