Update to 4.01.
[profile/ivi/quota.git] / quotaio_rpc.c
1 /*
2  *      quotaio_rpc.c - quota IO operations for RPC (just wrappers for RPC calls)
3  */
4
5 #include "config.h"
6
7 #include <stdio.h>
8 #include <errno.h>
9 #include <stdlib.h>
10 #include <sys/types.h>
11
12 #include "common.h"
13 #include "quotaio.h"
14 #include "dqblk_rpc.h"
15 #include "rquota_client.h"
16 #include "pot.h"
17
18 static int rpc_init_io(struct quota_handle *h);
19 static struct dquot *rpc_read_dquot(struct quota_handle *h, qid_t id);
20 static int rpc_commit_dquot(struct dquot *dquot, int flags);
21
22 struct quotafile_ops quotafile_ops_rpc = {
23 init_io:        rpc_init_io,
24 read_dquot:     rpc_read_dquot,
25 commit_dquot:   rpc_commit_dquot
26 };
27
28 /*
29  * Define maximal values RPC client can transmit to server.
30  */
31 static int rpc_init_io(struct quota_handle *h)
32 {
33 #ifdef RPC
34         h->qh_info.dqi_max_b_limit = ~(uint32_t)0;
35         h->qh_info.dqi_max_i_limit = ~(uint32_t)0;
36         h->qh_info.dqi_max_b_usage = (~(uint32_t)0) << QUOTABLOCK_BITS;
37         h->qh_info.dqi_max_i_usage = ~(uint32_t)0;
38         return 0;
39 #else
40         return -1;
41 #endif
42 }
43
44 /*
45  *      Read a dqblk struct from RPC server - just wrapper function.
46  */
47 static struct dquot *rpc_read_dquot(struct quota_handle *h, qid_t id)
48 {
49 #ifdef RPC
50         struct dquot *dquot = get_empty_dquot();
51         int ret;
52
53         dquot->dq_id = id;
54         dquot->dq_h = h;
55         if ((ret = rpc_rquota_get(dquot)) < 0) {
56                 errno = -ret;
57                 free(dquot);
58                 return NULL;
59         }
60         return dquot;
61 #else
62         errno = ENOTSUP;
63         return NULL;
64 #endif
65 }
66
67 /*
68  *      Write a dqblk struct to RPC server - just wrapper function.
69  */
70 static int rpc_commit_dquot(struct dquot *dquot, int flags)
71 {
72 #ifdef RPC
73         int ret;
74
75         if (QIO_RO(dquot->dq_h)) {
76                 errstr(_("Trying to write quota to readonly quotafile on %s\n"), dquot->dq_h->qh_quotadev);
77                 errno = EPERM;
78                 return -1;
79         }
80         if ((ret = rpc_rquota_set(QCMD(Q_RPC_SETQUOTA, dquot->dq_h->qh_type), dquot)) < 0) {
81                 errno = -ret;
82                 return -1;
83         }
84         return 0;
85 #else
86         errno = ENOTSUP;
87         return -1;
88 #endif
89 }