[WIN32] added nfsclient-sync to the solution. still manually linked with libnfs becau...
[deb_libnfs.git] / rquota / rquota.c
CommitLineData
05a777d9
RS
1/*
2 Copyright (C) 2010 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as published by
6 the Free Software Foundation; either version 2.1 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program; if not, see <http://www.gnu.org/licenses/>.
16*/
a8a1b858
M
17#ifdef WIN32
18#include "win32_compat.h"
19#endif/*WIN32*/
05a777d9 20
eecdc4f3
RS
21#if defined(WIN32)
22#include <winsock2.h>
23#endif
24
05a777d9
RS
25#include <stdio.h>
26#include <errno.h>
27#include <sys/stat.h>
c353ec24 28#include <rpc/rpc.h>
05a777d9
RS
29#include <rpc/xdr.h>
30#include "libnfs.h"
31#include "libnfs-raw.h"
32#include "libnfs-private.h"
33#include "libnfs-raw-rquota.h"
34
35
36
37char *rquotastat_to_str(int error)
38{
39 switch (error) {
40 case RQUOTA_OK: return "RQUOTA_OK"; break;
41 case RQUOTA_NOQUOTA: return "RQUOTA_NOQUOTA"; break;
42 case RQUOTA_EPERM: return "RQUOTA_EPERM"; break;
43 };
44 return "unknown rquota error";
45}
46
47int rquotastat_to_errno(int error)
48{
49 switch (error) {
50 case RQUOTA_OK: return 0; break;
51 case RQUOTA_NOQUOTA: return -ENOENT; break;
52 case RQUOTA_EPERM: return -EPERM; break;
53 };
54 return -ENOENT;
55}
56
57
58int rpc_rquota1_null_async(struct rpc_context *rpc, rpc_cb cb, void *private_data)
59{
60 struct rpc_pdu *pdu;
61
62 pdu = rpc_allocate_pdu(rpc, RQUOTA_PROGRAM, RQUOTA_V1, RQUOTA1_NULL, cb, private_data, (xdrproc_t)xdr_void, 0);
63 if (pdu == NULL) {
77c23b46 64 rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for rquota1/null call");
05a777d9
RS
65 return -1;
66 }
67
68 if (rpc_queue_pdu(rpc, pdu) != 0) {
77c23b46 69 rpc_set_error(rpc, "Out of memory. Failed to queue pdu for rquota1/null call");
05a777d9
RS
70 rpc_free_pdu(rpc, pdu);
71 return -2;
72 }
73
74 return 0;
75}
76
77int rpc_rquota1_getquota_async(struct rpc_context *rpc, rpc_cb cb, char *export, int uid, void *private_data)
78{
79 struct rpc_pdu *pdu;
80 GETQUOTA1args args;
81
82 pdu = rpc_allocate_pdu(rpc, RQUOTA_PROGRAM, RQUOTA_V1, RQUOTA1_GETQUOTA, cb, private_data, (xdrproc_t)xdr_GETQUOTA1res, sizeof(GETQUOTA1res));
83 if (pdu == NULL) {
77c23b46 84 rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for rquota1/getquota call");
05a777d9
RS
85 return -1;
86 }
87
88 args.export = export;
89 args.uid = uid;
90
91 if (xdr_GETQUOTA1args(&pdu->xdr, &args) == 0) {
92 rpc_set_error(rpc, "XDR error: Failed to encode GETQUOTA1args");
93 rpc_free_pdu(rpc, pdu);
94 return -2;
95 }
96
97 if (rpc_queue_pdu(rpc, pdu) != 0) {
77c23b46 98 rpc_set_error(rpc, "Out of memory. Failed to queue pdu for rquota1/getquota call");
05a777d9
RS
99 rpc_free_pdu(rpc, pdu);
100 return -3;
101 }
102
103 return 0;
104}
19e74f5a
RS
105
106int rpc_rquota1_getactivequota_async(struct rpc_context *rpc, rpc_cb cb, char *export, int uid, void *private_data)
107{
108 struct rpc_pdu *pdu;
109 GETQUOTA1args args;
110
111 pdu = rpc_allocate_pdu(rpc, RQUOTA_PROGRAM, RQUOTA_V1, RQUOTA1_GETACTIVEQUOTA, cb, private_data, (xdrproc_t)xdr_GETQUOTA1res, sizeof(GETQUOTA1res));
112 if (pdu == NULL) {
77c23b46 113 rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for rquota1/getactivequota call");
19e74f5a
RS
114 return -1;
115 }
116
117 args.export = export;
118 args.uid = uid;
119
120 if (xdr_GETQUOTA1args(&pdu->xdr, &args) == 0) {
121 rpc_set_error(rpc, "XDR error: Failed to encode GETQUOTA1args");
122 rpc_free_pdu(rpc, pdu);
123 return -2;
124 }
125
126 if (rpc_queue_pdu(rpc, pdu) != 0) {
77c23b46
RS
127 rpc_set_error(rpc, "Out of memory. Failed to queue pdu for rquota1/getactivequota call");
128 rpc_free_pdu(rpc, pdu);
129 return -3;
130 }
131
132 return 0;
133}
134
135
136int rpc_rquota2_null_async(struct rpc_context *rpc, rpc_cb cb, void *private_data)
137{
138 struct rpc_pdu *pdu;
139
140 pdu = rpc_allocate_pdu(rpc, RQUOTA_PROGRAM, RQUOTA_V2, RQUOTA2_NULL, cb, private_data, (xdrproc_t)xdr_void, 0);
141 if (pdu == NULL) {
142 rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for rquota2/null call");
143 return -1;
144 }
145
146 if (rpc_queue_pdu(rpc, pdu) != 0) {
147 rpc_set_error(rpc, "Out of memory. Failed to queue pdu for rquota2/null call");
148 rpc_free_pdu(rpc, pdu);
149 return -2;
150 }
151
152 return 0;
153}
154
155int rpc_rquota2_getquota_async(struct rpc_context *rpc, rpc_cb cb, char *export, int type, int uid, void *private_data)
156{
157 struct rpc_pdu *pdu;
158 GETQUOTA2args args;
159
160 pdu = rpc_allocate_pdu(rpc, RQUOTA_PROGRAM, RQUOTA_V2, RQUOTA2_GETQUOTA, cb, private_data, (xdrproc_t)xdr_GETQUOTA1res, sizeof(GETQUOTA1res));
161 if (pdu == NULL) {
162 rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for rquota2/getquota call");
163 return -1;
164 }
165
166 args.export = export;
167 args.type = type;
168 args.uid = uid;
169
170 if (xdr_GETQUOTA2args(&pdu->xdr, &args) == 0) {
171 rpc_set_error(rpc, "XDR error: Failed to encode GETQUOTA2args");
172 rpc_free_pdu(rpc, pdu);
173 return -2;
174 }
175
176 if (rpc_queue_pdu(rpc, pdu) != 0) {
177 rpc_set_error(rpc, "Out of memory. Failed to queue pdu for rquota2/getquota call");
178 rpc_free_pdu(rpc, pdu);
179 return -3;
180 }
181
182 return 0;
183}
184
185int rpc_rquota2_getactivequota_async(struct rpc_context *rpc, rpc_cb cb, char *export, int type, int uid, void *private_data)
186{
187 struct rpc_pdu *pdu;
188 GETQUOTA2args args;
189
190 pdu = rpc_allocate_pdu(rpc, RQUOTA_PROGRAM, RQUOTA_V2, RQUOTA2_GETACTIVEQUOTA, cb, private_data, (xdrproc_t)xdr_GETQUOTA1res, sizeof(GETQUOTA1res));
191 if (pdu == NULL) {
192 rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for rquota2/getactivequota call");
193 return -1;
194 }
195
196 args.export = export;
197 args.type = type;
198 args.uid = uid;
199
200 if (xdr_GETQUOTA2args(&pdu->xdr, &args) == 0) {
201 rpc_set_error(rpc, "XDR error: Failed to encode GETQUOTA2args");
202 rpc_free_pdu(rpc, pdu);
203 return -2;
204 }
205
206 if (rpc_queue_pdu(rpc, pdu) != 0) {
207 rpc_set_error(rpc, "Out of memory. Failed to queue pdu for rquota2/getactivequota call");
19e74f5a
RS
208 rpc_free_pdu(rpc, pdu);
209 return -3;
210 }
211
212 return 0;
213}