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