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 status_t Write(uint32* size); 91 92 private: 93 void _ParseHeader(); 94 95 status_t _DecodeAttrs(XDR::ReadStream& stream, AttrValue** attrs, 96 uint32* count); 97 status_t _OperationError(Opcode op); 98 99 static status_t _NFS4ErrorToHaiku(uint32 x); 100 101 uint32 fNFS4Error; 102 RPC::Reply* fReply; 103 }; 104 105 106 inline status_t 107 ReplyInterpreter::SetTo(RPC::Reply* _reply) 108 { 109 if (fReply != NULL) 110 return B_DONT_DO_THAT; 111 112 fReply = _reply; 113 114 if (fReply != NULL) 115 _ParseHeader(); 116 117 return B_OK; 118 } 119 120 121 inline void 122 ReplyInterpreter::Reset() 123 { 124 delete fReply; 125 fReply = NULL; 126 } 127 128 129 inline uint32 130 ReplyInterpreter::NFS4Error() 131 { 132 return fNFS4Error; 133 } 134 135 136 inline status_t 137 ReplyInterpreter::LookUp() 138 { 139 return _OperationError(OpLookUp); 140 } 141 142 143 inline status_t 144 ReplyInterpreter::LookUpUp() 145 { 146 return _OperationError(OpLookUpUp); 147 } 148 149 150 inline status_t 151 ReplyInterpreter::PutFH() 152 { 153 return _OperationError(OpPutFH); 154 } 155 156 157 inline status_t 158 ReplyInterpreter::PutRootFH() 159 { 160 return _OperationError(OpPutRootFH); 161 } 162 163 164 inline status_t 165 ReplyInterpreter::Renew() 166 { 167 return _OperationError(OpRenew); 168 } 169 170 171 inline status_t 172 ReplyInterpreter::SaveFH() 173 { 174 return _OperationError(OpSaveFH); 175 } 176 177 178 inline status_t 179 ReplyInterpreter::SetClientIDConfirm() 180 { 181 return _OperationError(OpSetClientIDConfirm); 182 } 183 184 185 inline status_t 186 ReplyInterpreter::Verify() 187 { 188 return _OperationError(OpVerify); 189 } 190 191 192 #endif // REPLYINTERPRETER_H 193 194