ZDR: New builtin replacement for RPC/XDR called ZDR
[deb_libnfs.git] / mount / mount.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 #ifdef WIN32
19 #include "win32_compat.h"
20 #endif/*WIN32*/
21
22 #include <stdio.h>
23 #include <errno.h>
24 #include "libnfs-zdr.h"
25 #include "libnfs.h"
26 #include "libnfs-raw.h"
27 #include "libnfs-private.h"
28 #include "libnfs-raw-mount.h"
29
30 int rpc_mount_null_async(struct rpc_context *rpc, rpc_cb cb, void *private_data)
31 {
32 struct rpc_pdu *pdu;
33
34 pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V3, MOUNT3_NULL, cb, private_data, (zdrproc_t)zdr_void, 0);
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);
43 return -1;
44 }
45
46 return 0;
47 }
48
49 int rpc_mount_mnt_async(struct rpc_context *rpc, rpc_cb cb, char *export, void *private_data)
50 {
51 struct rpc_pdu *pdu;
52
53 pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V3, MOUNT3_MNT, cb, private_data, (zdrproc_t)zdr_mountres3, sizeof(mountres3));
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
59 if (zdr_dirpath(&pdu->zdr, &export) == 0) {
60 rpc_set_error(rpc, "ZDR error. Failed to encode mount/mnt call");
61 rpc_free_pdu(rpc, pdu);
62 return -1;
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);
68 return -1;
69 }
70
71 return 0;
72 }
73
74 int rpc_mount_dump_async(struct rpc_context *rpc, rpc_cb cb, void *private_data)
75 {
76 struct rpc_pdu *pdu;
77
78 pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V3, MOUNT3_DUMP, cb, private_data, (zdrproc_t)zdr_mountlist, sizeof(mountlist));
79 if (pdu == NULL) {
80 rpc_set_error(rpc, "Failed to allocate pdu for mount/dump");
81 return -1;
82 }
83
84 if (rpc_queue_pdu(rpc, pdu) != 0) {
85 rpc_set_error(rpc, "Failed to queue mount/dump pdu");
86 rpc_free_pdu(rpc, pdu);
87 return -1;
88 }
89
90 return 0;
91 }
92
93 int rpc_mount_umnt_async(struct rpc_context *rpc, rpc_cb cb, char *export, void *private_data)
94 {
95 struct rpc_pdu *pdu;
96
97 pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V3, MOUNT3_UMNT, cb, private_data, (zdrproc_t)zdr_void, 0);
98 if (pdu == NULL) {
99 rpc_set_error(rpc, "Failed to allocate pdu for mount/umnt");
100 return -1;
101 }
102
103 if (zdr_dirpath(&pdu->zdr, &export) == 0) {
104 rpc_set_error(rpc, "failed to encode dirpath for mount/umnt");
105 rpc_free_pdu(rpc, pdu);
106 return -1;
107 }
108
109 if (rpc_queue_pdu(rpc, pdu) != 0) {
110 rpc_set_error(rpc, "Failed to queue mount/umnt pdu");
111 rpc_free_pdu(rpc, pdu);
112 return -1;
113 }
114
115 return 0;
116 }
117
118 int rpc_mount_umntall_async(struct rpc_context *rpc, rpc_cb cb, void *private_data)
119 {
120 struct rpc_pdu *pdu;
121
122 pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V3, MOUNT3_UMNTALL, cb, private_data, (zdrproc_t)zdr_void, 0);
123 if (pdu == NULL) {
124 rpc_set_error(rpc, "Failed to allocate pdu for mount/umntall");
125 return -1;
126 }
127
128 if (rpc_queue_pdu(rpc, pdu) != 0) {
129 rpc_set_error(rpc, "Failed to queue mount/umntall pdu");
130 rpc_free_pdu(rpc, pdu);
131 return -1;
132 }
133
134 return 0;
135 }
136
137 int rpc_mount_export_async(struct rpc_context *rpc, rpc_cb cb, void *private_data)
138 {
139 struct rpc_pdu *pdu;
140
141 pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V3, MOUNT3_EXPORT, cb, private_data, (zdrproc_t)zdr_exports, sizeof(exports));
142 if (pdu == NULL) {
143 rpc_set_error(rpc, "Failed to allocate pdu for mount/export");
144 return -1;
145 }
146
147 if (rpc_queue_pdu(rpc, pdu) != 0) {
148 rpc_set_error(rpc, "Failed to queue mount/export pdu");
149 rpc_free_pdu(rpc, pdu);
150 return -1;
151 }
152
153 return 0;
154 }
155
156 char *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
177 int 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 }
195
196
197