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