BPicture: Fix archive constructor.
[haiku.git] / src / add-ons / kernel / file_systems / nfs4 / ReplyBuilder.cpp
blob152d5de25b2c6e6aa63c70ae099d72906f611183
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 "ReplyBuilder.h"
12 #include "NFS4Defs.h"
13 #include "RPCCallbackReply.h"
16 ReplyBuilder::ReplyBuilder(uint32 xid)
18 fStatus(B_OK),
19 fOpCount(0),
20 fReply(RPC::CallbackReply::Create(xid))
22 _InitHeader();
26 ReplyBuilder::~ReplyBuilder()
28 delete fReply;
32 void
33 ReplyBuilder::_InitHeader()
35 fStatusPosition = fReply->Stream().Current();
36 fReply->Stream().AddUInt(0);
38 fReply->Stream().AddOpaque(NULL, 0);
40 fOpCountPosition = fReply->Stream().Current();
41 fReply->Stream().AddUInt(0);
46 RPC::CallbackReply*
47 ReplyBuilder::Reply()
49 fReply->Stream().InsertUInt(fStatusPosition, _HaikuErrorToNFS4(fStatus));
50 fReply->Stream().InsertUInt(fOpCountPosition, fOpCount);
52 if (fReply == NULL || fReply->Stream().Error() == B_OK)
53 return fReply;
54 else
55 return NULL;
59 status_t
60 ReplyBuilder::GetAttr(status_t status, int mask, uint64 size, uint64 change)
62 if (fStatus != B_OK)
63 return B_ERROR;
65 fReply->Stream().AddUInt(OpCallbackGetAttr);
66 fReply->Stream().AddUInt(_HaikuErrorToNFS4(fStatus));
67 fStatus = status;
69 if (status == B_OK) {
70 uint32 bitmap = 0;
71 if ((mask & CallbackAttrChange) != 0)
72 bitmap |= 1 << FATTR4_CHANGE;
73 if ((mask & CallbackAttrSize) != 0)
74 bitmap |= 1 << FATTR4_SIZE;
75 fReply->Stream().AddUInt(1);
76 fReply->Stream().AddUInt(bitmap);
78 XDR::WriteStream str;
79 if ((mask & CallbackAttrChange) != 0)
80 str.AddUHyper(change);
82 if ((mask & CallbackAttrSize) != 0)
83 str.AddUHyper(size);
84 fReply->Stream().AddOpaque(str);
87 fOpCount++;
89 return B_OK;
93 status_t
94 ReplyBuilder::Recall(status_t status)
96 if (fStatus != B_OK)
97 return B_ERROR;
99 fReply->Stream().AddUInt(OpCallbackRecall);
100 fReply->Stream().AddUInt(_HaikuErrorToNFS4(fStatus));
101 fStatus = status;
103 fOpCount++;
105 return B_OK;
109 uint32
110 ReplyBuilder::_HaikuErrorToNFS4(status_t error)
112 switch (error) {
113 case B_OK: return NFS4_OK;
114 case B_FILE_NOT_FOUND: return NFS4ERR_BADHANDLE;
115 case B_NOT_SUPPORTED: return NFS4ERR_OP_ILLEGAL;
116 default: return NFS4ERR_RESOURCE;