get rid of all remaining printfs from the library
[deb_libnfs.git] / mount / mount.c
... / ...
CommitLineData
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 <rpc/rpc.h>
21#include <rpc/xdr.h>
22#include "libnfs.h"
23#include "libnfs-raw.h"
24#include "libnfs-private.h"
25#include "libnfs-raw-mount.h"
26
27
28int rpc_mount_null_async(struct rpc_context *rpc, rpc_cb cb, void *private_data)
29{
30 struct rpc_pdu *pdu;
31
32 pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V3, MOUNT3_NULL, cb, private_data, (xdrproc_t)xdr_void, 0);
33 if (pdu == NULL) {
34 rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for mount/null call");
35 return -1;
36 }
37
38 if (rpc_queue_pdu(rpc, pdu) != 0) {
39 rpc_set_error(rpc, "Out of memory. Failed to queue pdu for mount/null call");
40 rpc_free_pdu(rpc, pdu);
41 return -1;
42 }
43
44 return 0;
45}
46
47int rpc_mount_mnt_async(struct rpc_context *rpc, rpc_cb cb, char *export, void *private_data)
48{
49 struct rpc_pdu *pdu;
50
51 pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V3, MOUNT3_MNT, cb, private_data, (xdrproc_t)xdr_mountres3, sizeof(mountres3));
52 if (pdu == NULL) {
53 rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for mount/mnt call");
54 return -1;
55 }
56
57 if (xdr_dirpath(&pdu->xdr, &export) == 0) {
58 rpc_set_error(rpc, "XDR error. Failed to encode mount/mnt call");
59 rpc_free_pdu(rpc, pdu);
60 return -1;
61 }
62
63 if (rpc_queue_pdu(rpc, pdu) != 0) {
64 rpc_set_error(rpc, "Out of memory. Failed to queue pdu for mount/mnt call");
65 rpc_free_pdu(rpc, pdu);
66 return -1;
67 }
68
69 return 0;
70}
71
72int rpc_mount_dump_async(struct rpc_context *rpc, rpc_cb cb, void *private_data)
73{
74 struct rpc_pdu *pdu;
75
76 pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V3, MOUNT3_DUMP, cb, private_data, (xdrproc_t)xdr_mountlist, sizeof(mountlist));
77 if (pdu == NULL) {
78 rpc_set_error(rpc, "Failed to allocate pdu for mount/dump");
79 return -1;
80 }
81
82 if (rpc_queue_pdu(rpc, pdu) != 0) {
83 rpc_set_error(rpc, "Failed to queue mount/dump pdu");
84 rpc_free_pdu(rpc, pdu);
85 return -1;
86 }
87
88 return 0;
89}
90
91int rpc_mount_umnt_async(struct rpc_context *rpc, rpc_cb cb, char *export, void *private_data)
92{
93 struct rpc_pdu *pdu;
94
95 pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V3, MOUNT3_UMNT, cb, private_data, (xdrproc_t)xdr_void, 0);
96 if (pdu == NULL) {
97 rpc_set_error(rpc, "Failed to allocate pdu for mount/umnt");
98 return -1;
99 }
100
101 if (xdr_dirpath(&pdu->xdr, &export) == 0) {
102 rpc_set_error(rpc, "failed to encode dirpath for mount/umnt");
103 rpc_free_pdu(rpc, pdu);
104 return -1;
105 }
106
107 if (rpc_queue_pdu(rpc, pdu) != 0) {
108 rpc_set_error(rpc, "Failed to queue mount/umnt pdu");
109 rpc_free_pdu(rpc, pdu);
110 return -1;
111 }
112
113 return 0;
114}
115
116int rpc_mount_umntall_async(struct rpc_context *rpc, rpc_cb cb, void *private_data)
117{
118 struct rpc_pdu *pdu;
119
120 pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V3, MOUNT3_UMNTALL, cb, private_data, (xdrproc_t)xdr_void, 0);
121 if (pdu == NULL) {
122 rpc_set_error(rpc, "Failed to allocate pdu for mount/umntall");
123 return -1;
124 }
125
126 if (rpc_queue_pdu(rpc, pdu) != 0) {
127 rpc_set_error(rpc, "Failed to queue mount/umntall pdu");
128 rpc_free_pdu(rpc, pdu);
129 return -1;
130 }
131
132 return 0;
133}
134
135int rpc_mount_export_async(struct rpc_context *rpc, rpc_cb cb, void *private_data)
136{
137 struct rpc_pdu *pdu;
138
139 pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V3, MOUNT3_EXPORT, cb, private_data, (xdrproc_t)xdr_exports, sizeof(exports));
140 if (pdu == NULL) {
141 rpc_set_error(rpc, "Failed to allocate pdu for mount/export");
142 return -1;
143 }
144
145 if (rpc_queue_pdu(rpc, pdu) != 0) {
146 rpc_set_error(rpc, "Failed to queue mount/export pdu");
147 rpc_free_pdu(rpc, pdu);
148 return -1;
149 }
150
151 return 0;
152}
153
154char *mountstat3_to_str(int st)
155{
156 enum mountstat3 stat = st;
157
158 char *str = "unknown mount stat";
159 switch (stat) {
160 case MNT3_OK: str="MNT3_OK"; break;
161 case MNT3ERR_PERM: str="MNT3ERR_PERM"; break;
162 case MNT3ERR_NOENT: str="MNT3ERR_NOENT"; break;
163 case MNT3ERR_IO: str="MNT3ERR_IO"; break;
164 case MNT3ERR_ACCES: str="MNT3ERR_ACCES"; break;
165 case MNT3ERR_NOTDIR: str="MNT3ERR_NOTDIR"; break;
166 case MNT3ERR_INVAL: str="MNT3ERR_INVAL"; break;
167 case MNT3ERR_NAMETOOLONG: str="MNT3ERR_NAMETOOLONG"; break;
168 case MNT3ERR_NOTSUPP: str="MNT3ERR_NOTSUPP"; break;
169 case MNT3ERR_SERVERFAULT: str="MNT3ERR_SERVERFAULT"; break;
170 }
171 return str;
172}
173
174
175int mountstat3_to_errno(int st)
176{
177 enum mountstat3 stat = st;
178
179 switch (stat) {
180 case MNT3_OK: return 0; break;
181 case MNT3ERR_PERM: return -EPERM; break;
182 case MNT3ERR_NOENT: return -EPERM; break;
183 case MNT3ERR_IO: return -EIO; break;
184 case MNT3ERR_ACCES: return -EACCES; break;
185 case MNT3ERR_NOTDIR: return -ENOTDIR; break;
186 case MNT3ERR_INVAL: return -EINVAL; break;
187 case MNT3ERR_NAMETOOLONG: return -E2BIG; break;
188 case MNT3ERR_NOTSUPP: return -EINVAL; break;
189 case MNT3ERR_SERVERFAULT: return -EIO; break;
190 }
191 return -ERANGE;
192}