RPC_CONNECT: Use the rpc_connect_program_async() flow during nfs_mount()
[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
RS
20
21#include <stdio.h>
22#include <errno.h>
23#include <sys/stat.h>
763cd6e3 24#include "libnfs-zdr.h"
05a777d9
RS
25#include "libnfs.h"
26#include "libnfs-raw.h"
27#include "libnfs-private.h"
28#include "libnfs-raw-rquota.h"
29
30
31
32char *rquotastat_to_str(int error)
33{
34 switch (error) {
35 case RQUOTA_OK: return "RQUOTA_OK"; break;
36 case RQUOTA_NOQUOTA: return "RQUOTA_NOQUOTA"; break;
37 case RQUOTA_EPERM: return "RQUOTA_EPERM"; break;
38 };
39 return "unknown rquota error";
40}
41
42int rquotastat_to_errno(int error)
43{
44 switch (error) {
45 case RQUOTA_OK: return 0; break;
46 case RQUOTA_NOQUOTA: return -ENOENT; break;
47 case RQUOTA_EPERM: return -EPERM; break;
48 };
49 return -ENOENT;
50}
51
52
53int rpc_rquota1_null_async(struct rpc_context *rpc, rpc_cb cb, void *private_data)
54{
55 struct rpc_pdu *pdu;
56
763cd6e3 57 pdu = rpc_allocate_pdu(rpc, RQUOTA_PROGRAM, RQUOTA_V1, RQUOTA1_NULL, cb, private_data, (zdrproc_t)zdr_void, 0);
05a777d9 58 if (pdu == NULL) {
77c23b46 59 rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for rquota1/null call");
05a777d9
RS
60 return -1;
61 }
62
63 if (rpc_queue_pdu(rpc, pdu) != 0) {
77c23b46 64 rpc_set_error(rpc, "Out of memory. Failed to queue pdu for rquota1/null call");
05a777d9
RS
65 rpc_free_pdu(rpc, pdu);
66 return -2;
67 }
68
69 return 0;
70}
71
72int rpc_rquota1_getquota_async(struct rpc_context *rpc, rpc_cb cb, char *export, int uid, void *private_data)
73{
74 struct rpc_pdu *pdu;
75 GETQUOTA1args args;
76
763cd6e3 77 pdu = rpc_allocate_pdu(rpc, RQUOTA_PROGRAM, RQUOTA_V1, RQUOTA1_GETQUOTA, cb, private_data, (zdrproc_t)zdr_GETQUOTA1res, sizeof(GETQUOTA1res));
05a777d9 78 if (pdu == NULL) {
77c23b46 79 rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for rquota1/getquota call");
05a777d9
RS
80 return -1;
81 }
82
83 args.export = export;
84 args.uid = uid;
85
763cd6e3
RS
86 if (zdr_GETQUOTA1args(&pdu->zdr, &args) == 0) {
87 rpc_set_error(rpc, "ZDR error: Failed to encode GETQUOTA1args");
05a777d9
RS
88 rpc_free_pdu(rpc, pdu);
89 return -2;
90 }
91
92 if (rpc_queue_pdu(rpc, pdu) != 0) {
77c23b46 93 rpc_set_error(rpc, "Out of memory. Failed to queue pdu for rquota1/getquota call");
05a777d9
RS
94 rpc_free_pdu(rpc, pdu);
95 return -3;
96 }
97
98 return 0;
99}
19e74f5a
RS
100
101int rpc_rquota1_getactivequota_async(struct rpc_context *rpc, rpc_cb cb, char *export, int uid, void *private_data)
102{
103 struct rpc_pdu *pdu;
104 GETQUOTA1args args;
105
763cd6e3 106 pdu = rpc_allocate_pdu(rpc, RQUOTA_PROGRAM, RQUOTA_V1, RQUOTA1_GETACTIVEQUOTA, cb, private_data, (zdrproc_t)zdr_GETQUOTA1res, sizeof(GETQUOTA1res));
19e74f5a 107 if (pdu == NULL) {
77c23b46 108 rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for rquota1/getactivequota call");
19e74f5a
RS
109 return -1;
110 }
111
112 args.export = export;
113 args.uid = uid;
114
763cd6e3
RS
115 if (zdr_GETQUOTA1args(&pdu->zdr, &args) == 0) {
116 rpc_set_error(rpc, "ZDR error: Failed to encode GETQUOTA1args");
19e74f5a
RS
117 rpc_free_pdu(rpc, pdu);
118 return -2;
119 }
120
121 if (rpc_queue_pdu(rpc, pdu) != 0) {
77c23b46
RS
122 rpc_set_error(rpc, "Out of memory. Failed to queue pdu for rquota1/getactivequota call");
123 rpc_free_pdu(rpc, pdu);
124 return -3;
125 }
126
127 return 0;
128}
129
130
131int rpc_rquota2_null_async(struct rpc_context *rpc, rpc_cb cb, void *private_data)
132{
133 struct rpc_pdu *pdu;
134
763cd6e3 135 pdu = rpc_allocate_pdu(rpc, RQUOTA_PROGRAM, RQUOTA_V2, RQUOTA2_NULL, cb, private_data, (zdrproc_t)zdr_void, 0);
77c23b46
RS
136 if (pdu == NULL) {
137 rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for rquota2/null call");
138 return -1;
139 }
140
141 if (rpc_queue_pdu(rpc, pdu) != 0) {
142 rpc_set_error(rpc, "Out of memory. Failed to queue pdu for rquota2/null call");
143 rpc_free_pdu(rpc, pdu);
144 return -2;
145 }
146
147 return 0;
148}
149
150int rpc_rquota2_getquota_async(struct rpc_context *rpc, rpc_cb cb, char *export, int type, int uid, void *private_data)
151{
152 struct rpc_pdu *pdu;
153 GETQUOTA2args args;
154
763cd6e3 155 pdu = rpc_allocate_pdu(rpc, RQUOTA_PROGRAM, RQUOTA_V2, RQUOTA2_GETQUOTA, cb, private_data, (zdrproc_t)zdr_GETQUOTA1res, sizeof(GETQUOTA1res));
77c23b46
RS
156 if (pdu == NULL) {
157 rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for rquota2/getquota call");
158 return -1;
159 }
160
161 args.export = export;
162 args.type = type;
163 args.uid = uid;
164
763cd6e3
RS
165 if (zdr_GETQUOTA2args(&pdu->zdr, &args) == 0) {
166 rpc_set_error(rpc, "ZDR error: Failed to encode GETQUOTA2args");
77c23b46
RS
167 rpc_free_pdu(rpc, pdu);
168 return -2;
169 }
170
171 if (rpc_queue_pdu(rpc, pdu) != 0) {
172 rpc_set_error(rpc, "Out of memory. Failed to queue pdu for rquota2/getquota call");
173 rpc_free_pdu(rpc, pdu);
174 return -3;
175 }
176
177 return 0;
178}
179
180int rpc_rquota2_getactivequota_async(struct rpc_context *rpc, rpc_cb cb, char *export, int type, int uid, void *private_data)
181{
182 struct rpc_pdu *pdu;
183 GETQUOTA2args args;
184
763cd6e3 185 pdu = rpc_allocate_pdu(rpc, RQUOTA_PROGRAM, RQUOTA_V2, RQUOTA2_GETACTIVEQUOTA, cb, private_data, (zdrproc_t)zdr_GETQUOTA1res, sizeof(GETQUOTA1res));
77c23b46
RS
186 if (pdu == NULL) {
187 rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for rquota2/getactivequota call");
188 return -1;
189 }
190
191 args.export = export;
192 args.type = type;
193 args.uid = uid;
194
763cd6e3
RS
195 if (zdr_GETQUOTA2args(&pdu->zdr, &args) == 0) {
196 rpc_set_error(rpc, "ZDR error: Failed to encode GETQUOTA2args");
77c23b46
RS
197 rpc_free_pdu(rpc, pdu);
198 return -2;
199 }
200
201 if (rpc_queue_pdu(rpc, pdu) != 0) {
202 rpc_set_error(rpc, "Out of memory. Failed to queue pdu for rquota2/getactivequota call");
19e74f5a
RS
203 rpc_free_pdu(rpc, pdu);
204 return -3;
205 }
206
207 return 0;
208}