- linux, osx, and ios need rpc/rpc.h includede before rpc/xdr.h
[deb_libnfs.git] / rquota / rquota.c
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>
21 #include <rpc/xdr.h>
22 #include "libnfs.h"
23 #include "libnfs-raw.h"
24 #include "libnfs-private.h"
25 #include "libnfs-raw-rquota.h"
26
27
28
29 char *rquotastat_to_str(int error)
30 {
31 switch (error) {
32 case RQUOTA_OK: return "RQUOTA_OK"; break;
33 case RQUOTA_NOQUOTA: return "RQUOTA_NOQUOTA"; break;
34 case RQUOTA_EPERM: return "RQUOTA_EPERM"; break;
35 };
36 return "unknown rquota error";
37 }
38
39 int rquotastat_to_errno(int error)
40 {
41 switch (error) {
42 case RQUOTA_OK: return 0; break;
43 case RQUOTA_NOQUOTA: return -ENOENT; break;
44 case RQUOTA_EPERM: return -EPERM; break;
45 };
46 return -ENOENT;
47 }
48
49
50 int rpc_rquota1_null_async(struct rpc_context *rpc, rpc_cb cb, void *private_data)
51 {
52 struct rpc_pdu *pdu;
53
54 pdu = rpc_allocate_pdu(rpc, RQUOTA_PROGRAM, RQUOTA_V1, RQUOTA1_NULL, cb, private_data, (xdrproc_t)xdr_void, 0);
55 if (pdu == NULL) {
56 rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for rquota/null call");
57 return -1;
58 }
59
60 if (rpc_queue_pdu(rpc, pdu) != 0) {
61 rpc_set_error(rpc, "Out of memory. Failed to queue pdu for rquota/null call");
62 rpc_free_pdu(rpc, pdu);
63 return -2;
64 }
65
66 return 0;
67 }
68
69 int rpc_rquota1_getquota_async(struct rpc_context *rpc, rpc_cb cb, char *export, int uid, void *private_data)
70 {
71 struct rpc_pdu *pdu;
72 GETQUOTA1args args;
73
74 pdu = rpc_allocate_pdu(rpc, RQUOTA_PROGRAM, RQUOTA_V1, RQUOTA1_GETQUOTA, cb, private_data, (xdrproc_t)xdr_GETQUOTA1res, sizeof(GETQUOTA1res));
75 if (pdu == NULL) {
76 rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for rquota/getquota call");
77 return -1;
78 }
79
80 args.export = export;
81 args.uid = uid;
82
83 if (xdr_GETQUOTA1args(&pdu->xdr, &args) == 0) {
84 rpc_set_error(rpc, "XDR error: Failed to encode GETQUOTA1args");
85 rpc_free_pdu(rpc, pdu);
86 return -2;
87 }
88
89 if (rpc_queue_pdu(rpc, pdu) != 0) {
90 rpc_set_error(rpc, "Out of memory. Failed to queue pdu for rquota/getquota call");
91 rpc_free_pdu(rpc, pdu);
92 return -3;
93 }
94
95 return 0;
96 }