btrfs: [] on the end of a struct field is a variable length array.
[haiku.git] / src / add-ons / kernel / file_systems / nfs4 / RequestInterpreter.cpp
blob11ca0a235b7d5b617ff623b921644a5054c08890
1 /*
2 * Copyright 2012 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Paweł Dziepak, pdziepak@quarnos.org
7 */
10 #include "RequestInterpreter.h"
12 #include <string.h>
14 #include <util/kernel_cpp.h>
17 RequestInterpreter::RequestInterpreter(RPC::CallbackRequest* request)
19 fRequest(request)
21 fOperationCount = fRequest->Stream().GetUInt();
25 RequestInterpreter::~RequestInterpreter()
27 delete fRequest;
31 status_t
32 RequestInterpreter::GetAttr(FileHandle* handle, int* _mask)
34 if (fLastOperation != OpCallbackGetAttr)
35 return B_BAD_VALUE;
37 uint32 size;
38 const void* ptr = fRequest->Stream().GetOpaque(&size);
39 handle->fSize = size;
40 memcpy(handle->fData, ptr, size);
42 uint32 count = fRequest->Stream().GetUInt();
43 if (count < 1) {
44 *_mask = 0;
45 return fRequest->Stream().IsEOF() ? B_BAD_VALUE : B_OK;
48 uint32 bitmap = fRequest->Stream().GetUInt();
49 uint32 mask = 0;
51 if ((bitmap & (1 << FATTR4_CHANGE)) != 0)
52 mask |= CallbackAttrChange;
53 if ((bitmap & (1 << FATTR4_SIZE)) != 0)
54 mask |= CallbackAttrSize;
56 *_mask = mask;
58 for (uint32 i = 1; i < count; i++)
59 fRequest->Stream().GetUInt();
61 return fRequest->Stream().IsEOF() ? B_BAD_VALUE : B_OK;
65 status_t
66 RequestInterpreter::Recall(FileHandle* handle, bool& truncate, uint32* stateSeq,
67 uint32* stateID)
69 if (fLastOperation != OpCallbackRecall)
70 return B_BAD_VALUE;
72 *stateSeq = fRequest->Stream().GetUInt();
73 stateID[0] = fRequest->Stream().GetUInt();
74 stateID[1] = fRequest->Stream().GetUInt();
75 stateID[2] = fRequest->Stream().GetUInt();
77 truncate = fRequest->Stream().GetBoolean();
79 uint32 size;
80 const void* ptr = fRequest->Stream().GetOpaque(&size);
81 handle->fSize = size;
82 memcpy(handle->fData, ptr, size);
84 return fRequest->Stream().IsEOF() ? B_BAD_VALUE : B_OK;