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 9 10 #include "RequestInterpreter.h" 11 12 #include <string.h> 13 14 #include <util/kernel_cpp.h> 15 16 17 RequestInterpreter::RequestInterpreter(RPC::CallbackRequest* request) 18 : 19 fRequest(request) 20 { 21 fOperationCount = fRequest->Stream().GetUInt(); 22 } 23 24 25 RequestInterpreter::~RequestInterpreter() 26 { 27 delete fRequest; 28 } 29 30 31 status_t 32 RequestInterpreter::GetAttr(FileHandle* handle, int* _mask) 33 { 34 if (fLastOperation != OpCallbackGetAttr) 35 return B_BAD_VALUE; 36 37 uint32 size; 38 const void* ptr = fRequest->Stream().GetOpaque(&size); 39 handle->fSize = size; 40 memcpy(handle->fData, ptr, size); 41 42 uint32 count = fRequest->Stream().GetUInt(); 43 if (count < 1) { 44 *_mask = 0; 45 return fRequest->Stream().IsEOF() ? B_BAD_VALUE : B_OK; 46 } 47 48 uint32 bitmap = fRequest->Stream().GetUInt(); 49 uint32 mask = 0; 50 51 if ((bitmap & (1 << FATTR4_CHANGE)) != 0) 52 mask |= CallbackAttrChange; 53 if ((bitmap & (1 << FATTR4_SIZE)) != 0) 54 mask |= CallbackAttrSize; 55 56 *_mask = mask; 57 58 for (uint32 i = 1; i < count; i++) 59 fRequest->Stream().GetUInt(); 60 61 return fRequest->Stream().IsEOF() ? B_BAD_VALUE : B_OK; 62 } 63 64 65 status_t 66 RequestInterpreter::Recall(FileHandle* handle, bool& truncate, uint32* stateSeq, 67 uint32* stateID) 68 { 69 if (fLastOperation != OpCallbackRecall) 70 return B_BAD_VALUE; 71 72 *stateSeq = fRequest->Stream().GetUInt(); 73 stateID[0] = fRequest->Stream().GetUInt(); 74 stateID[1] = fRequest->Stream().GetUInt(); 75 stateID[2] = fRequest->Stream().GetUInt(); 76 77 truncate = fRequest->Stream().GetBoolean(); 78 79 uint32 size; 80 const void* ptr = fRequest->Stream().GetOpaque(&size); 81 handle->fSize = size; 82 memcpy(handle->fData, ptr, size); 83 84 return fRequest->Stream().IsEOF() ? B_BAD_VALUE : B_OK; 85 } 86 87